Repository: pytorch
Issue: `native_batch_norm`: `aot_eager` backend incorrectly raising an error.
Labels: triaged,module: functionalization,oncall: pt2,module: aotdispatch,module: pt2-dispatcher

### 🐛 Describe the bug

`out=` variant of `native_batch_norm` operation does not work with `aot_eager` backend.

```python
args = (
    torch.rand(5, 5, 5),
    torch.rand(5),
    torch.rand(5),
    torch.rand(5),
    torch.rand(5),
    True,
    0.5,
    0.6,
)

out = (
    torch.empty(5, 5, 5),
    torch.empty(5),
    torch.empty(5),
)

>>> torch.compile(torch.native_batch_norm, backend="aot_eager")(*args, out=out)
Traceback (most recent call last):
  File "examples/bn.py", line 20, in <module>
    torch.compile(torch.native_batch_norm, backend="aot_eager")(*args, out=out)
  File "torch/_dynamo/eval_frame.py", line 487, in _fn
    return fn(*args, **kwargs)
  File "torch/_dynamo/convert_frame.py", line 1350, in __call__
    return self._torchdynamo_orig_callable(
  File "torch/_dynamo/convert_frame.py", line 1141, in __call__
    result = self._inner_convert(
  File "torch/_dynamo/convert_frame.py", line 543, in __call__
    return _compile(
  File "torch/_dynamo/convert_frame.py", line 963, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "torch/_dynamo/convert_frame.py", line 694, in compile_inner
    return _compile_inner(code, one_graph, hooks, transform)
  File "torch/_utils_internal.py", line 87, in wrapper_function
    return function(*args, **kwargs)
  File "torch/_dynamo/convert_frame.py", line 727, in _compile_inner
    out_code = transform_code_object(code, transform)
  File "torch/_dynamo/bytecode_transformation.py", line 1337, in transform_code_object
    transformations(instructions, code_options)
  File "torch/_dynamo/convert_frame.py", line 228, in _fn
    return fn(*args, **kwargs)
  File "torch/_dynamo/convert_frame.py", line 656, in transform
    tracer.run()
  File "torch/_dynamo/symbolic_convert.py", line 2794, in run
    super().run()
  File "torch/_dynamo/symbolic_convert.py", line 996, in run
    while self.step():
  File "torch/_dynamo/symbolic_convert.py", line 908, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "torch/_dynamo/symbolic_convert.py", line 2985, in RETURN_VALUE
    self._return(inst)
  File "torch/_dynamo/symbolic_convert.py", line 2970, in _return
    self.output.compile_subgraph(
  File "torch/_dynamo/output_graph.py", line 1143, in compile_subgraph
    self.compile_and_call_fx_graph(tx, pass2.graph_output_vars(), root)
  File "torch/_dynamo/output_graph.py", line 1371, in compile_and_call_fx_graph
    compiled_fn = self.call_user_compiler(gm)
  File "torch/_dynamo/output_graph.py", line 1418, in call_user_compiler
    return self._call_user_compiler(gm)
  File "torch/_dynamo/output_graph.py", line 1467, in _call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e).with_traceback(
  File "torch/_dynamo/output_graph.py", line 1448, in _call_user_compiler
    compiled_fn = compiler_fn(gm, self.example_inputs())
  File "torch/_dynamo/repro/after_dynamo.py", line 130, in __call__
    compiled_gm = compiler_fn(gm, example_inputs)
  File "torch/__init__.py", line 2309, in __call__
    return self.compiler_fn(model_, inputs_, **self.kwargs)
  File "torch/_dynamo/backends/common.py", line 72, in __call__
    cg = aot_module_simplified(gm, example_inputs, **self.kwargs)
  File "torch/_functorch/aot_autograd.py", line 1087, in aot_module_simplified
    compiled_fn = dispatch_and_compile()
  File "torch/_functorch/aot_autograd.py", line 1063, in dispatch_and_compile
    compiled_fn, _ = create_aot_dispatcher_function(
  File "torch/_functorch/aot_autograd.py", line 524, in create_aot_dispatcher_function
    return _create_aot_dispatcher_function(
  File "torch/_functorch/aot_autograd.py", line 762, in _create_aot_dispatcher_function
    compiled_fn, fw_metadata = compiler_fn(
  File "torch/_functorch/_aot_autograd/jit_compile_runtime_wrappers.py", line 145, in aot_dispatch_base
    fw_module, updated_flat_args, maybe_subclass_meta = aot_dispatch_base_graph(  # type: ignore[misc]
  File "torch/_functorch/_aot_autograd/dispatch_and_compile_graph.py", line 166, in aot_dispatch_base_graph
    copy_count = assert_functional_graph(fw_module.graph)
  File "torch/_functorch/_aot_autograd/functional_utils.py", line 465, in assert_functional_graph
    assert (
torch._dynamo.exc.BackendCompilerFailed: backend='aot_eager' raised:
AssertionError: aot_autograd expected to have an entirely functional graph, but found %_native_batch_norm_legit : [num_users=3] = call_function[target=torch.ops.aten._native_batch_norm_legit.default](args = (%arg4_1, %arg3_1, %arg2_1, %arg1_1, %arg0_1, True, 0.5, 0.6), kwargs = {})

Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information


You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True
```

### Versions

PyTorch version: 2.5.0a0+git7128504
Is debug build: True
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

cc @ezyang @chauhang @penguinwu @zou3519 @bdhirsh @yf225