Repository: pytorch
Issue: `nanmean`: `out=` function does not work with dynamo.
Labels: triaged,enhancement,oncall: pt2,module: inductor

### 🐛 Describe the bug

`out=` variant of `nanmean` operation does not work with dynamo (eager backend).

```python
>>> inp = torch.rand(10)
>>> out = torch.tensor(.0)

>>> torch.nanmean(inp, out=out)
tensor(...)

>>> torch.compile(torch.nanmean, backend="eager")(inp, out=out)
Traceback (most recent call last):
  File "examples/nanmean.py", line 7, in <module>
    torch.compile(torch.nanmean, backend="eager")(inp, 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 614, in wrapper
    return inner_fn(self, inst)
  File "torch/_dynamo/symbolic_convert.py", line 1693, in CALL_FUNCTION_EX
    self.call_function(fn, argsvars.items, kwargsvars)
  File "torch/_dynamo/symbolic_convert.py", line 843, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
  File "torch/_dynamo/variables/lazy.py", line 169, in realize_and_forward
    return getattr(self.realize(), name)(*args, **kwargs)
  File "torch/_dynamo/variables/torch.py", line 953, in call_function
    tensor_variable = wrap_fx_proxy(
  File "torch/_dynamo/variables/builder.py", line 2057, in wrap_fx_proxy
    return wrap_fx_proxy_cls(target_cls=TensorVariable, **kwargs)
  File "torch/_dynamo/variables/builder.py", line 2144, in wrap_fx_proxy_cls
    example_value = get_fake_value(proxy.node, tx, allow_non_graph_fake=True)
  File "torch/_dynamo/utils.py", line 2134, in get_fake_value
    raise TorchRuntimeError(str(e)).with_traceback(e.__traceback__) from None
  File "torch/_dynamo/utils.py", line 2069, in get_fake_value
    ret_val = wrap_fake_exception(
  File "torch/_dynamo/utils.py", line 1626, in wrap_fake_exception
    return fn()
  File "torch/_dynamo/utils.py", line 2070, in <lambda>
    lambda: run_node(tx.output, node, args, kwargs, nnmodule)
  File "torch/_dynamo/utils.py", line 2202, in run_node
    raise RuntimeError(make_error_message(e)).with_traceback(
  File "torch/_dynamo/utils.py", line 2184, in run_node
    return node.target(*args, **kwargs)
torch._dynamo.exc.TorchRuntimeError: Failed running call_function <built-in method nanmean of type object at 0x7f4e342e90a0>(*(FakeTensor(..., size=(10,)),), **{'out': FakeTensor(..., size=())}):
Cannot access data pointer of Tensor (e.g. FakeTensor, FunctionalTensor). If you're using torch.compile/export/fx, it is likely that we are erroneously tracing into a custom kernel. To fix this, please wrap the custom kernel into an opaque custom op. Please see the following for details: https://pytorch.org/tutorials/advanced/custom_ops_landing_page.html

from user code:
   File "torch/_dynamo/external_utils.py", line 31, in inner
    return fn(*args, **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 @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire