Repository: pytorch
Issue: add scalar inputs with out causes error in torch.compile
Labels: triaged,oncall: pt2,module: decompositions,module: aotdispatch,module: pt2-dispatcher

### 🐛 Describe the bug

```
import torch
def add_fn(params):
    res = torch.add(**params)
    return res
if __name__ == "__main__":
    add_fn = torch.compile(add_fn)
    params = {'other': 1.1, 'alpha': 0.4, 'input': 2, 'out': torch.tensor(1.)}
    res = add_fn(params)
    print(res)
```

It cases below error:
```
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0] failed while attempting to run meta for aten.add.out
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0] Traceback (most recent call last):
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]   File "/tmp/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 2016, in _dispatch_impl
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]     r = func(*args, **kwargs)
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]   File "/tmp/lib/python3.10/site-packages/torch/_ops.py", line 716, in __call__
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]     return self._op(*args, **kwargs)
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]   File "/tmp/lib/python3.10/site-packages/torch/_prims_common/wrappers.py", line 273, in _fn
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]     result = fn(*args, **kwargs)
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]   File "/tmp/lib/python3.10/site-packages/torch/_prims_common/wrappers.py", line 141, in _fn
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]     result = fn(**bound.arguments)
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]   File "/tmp/lib/python3.10/site-packages/torch/_refs/__init__.py", line 1087, in add
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0]     dtype = a.dtype if isinstance(a, TensorLike) else b.dtype  # type: ignore[union-attr]
E0124 11:04:10.160000 286274 torch/_subclasses/fake_tensor.py:2020] [0/0] AttributeError: 'float' object has no attribute 'dtype'
Traceback (most recent call last):
  File "/tmp/val.py", line 12, in <module>
    res = add_fn(params)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 465, in _fn
    return fn(*args, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1269, in __call__
    return self._torchdynamo_orig_callable(
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1064, in __call__
    result = self._inner_convert(
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 526, in __call__
    return _compile(
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 924, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 666, in compile_inner
    return _compile_inner(code, one_graph, hooks, transform)
  File "/tmp/lib/python3.10/site-packages/torch/_utils_internal.py", line 87, in wrapper_function
    return function(*args, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 699, in _compile_inner
    out_code = transform_code_object(code, transform)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/bytecode_transformation.py", line 1322, in transform_code_object
    transformations(instructions, code_options)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 219, in _fn
    return fn(*args, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 634, in transform
    tracer.run()
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 2796, in run
    super().run()
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 983, in run
    while self.step():
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 895, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 582, in wrapper
    return inner_fn(self, inst)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1680, in CALL_FUNCTION_EX
    self.call_function(fn, argsvars.items, kwargsvars)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 830, in call_function
    self.push(fn.call_function(self, args, kwargs))  # type: ignore[arg-type]
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/variables/torch.py", line 897, in call_function
    tensor_variable = wrap_fx_proxy(
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/variables/builder.py", line 2037, in wrap_fx_proxy
    return wrap_fx_proxy_cls(target_cls=TensorVariable, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/variables/builder.py", line 2124, in wrap_fx_proxy_cls
    example_value = get_fake_value(proxy.node, tx, allow_non_graph_fake=True)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 2082, in get_fake_value
    raise TorchRuntimeError(str(e)).with_traceback(e.__traceback__) from None
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 2017, in get_fake_value
    ret_val = wrap_fake_exception(
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 1574, in wrap_fake_exception
    return fn()
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 2018, in <lambda>
    lambda: run_node(tx.output, node, args, kwargs, nnmodule)
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 2150, in run_node
    raise RuntimeError(make_error_message(e)).with_traceback(
  File "/tmp/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 2132, in run_node
    return node.target(*args, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/utils/_stats.py", line 21, in wrapper
    return fn(*args, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 1241, in __torch_dispatch__
    return self.dispatch(func, types, args, kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 1695, in dispatch
    return self._cached_dispatch_impl(func, types, args, kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 1342, in _cached_dispatch_impl
    output = self._dispatch_impl(func, types, args, kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_subclasses/fake_tensor.py", line 2016, in _dispatch_impl
    r = func(*args, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_ops.py", line 716, in __call__
    return self._op(*args, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_prims_common/wrappers.py", line 273, in _fn
    result = fn(*args, **kwargs)
  File "/tmp/lib/python3.10/site-packages/torch/_prims_common/wrappers.py", line 141, in _fn
    result = fn(**bound.arguments)
  File "/tmp/lib/python3.10/site-packages/torch/_refs/__init__.py", line 1087, in add
    dtype = a.dtype if isinstance(a, TensorLike) else b.dtype  # type: ignore[union-attr]
torch._dynamo.exc.TorchRuntimeError: Failed running call_function <built-in method add of type object at 0x7f10670a3a20>(*(), **{'other': 1.1, 'alpha': 0.4, 'input': 2, 'out': FakeTensor(..., size=())}):
'float' object has no attribute 'dtype'

from user code:
   File "/tmp/val.py", line 5, in add_fn
    res = torch.add(**params)

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.1

cc @chauhang @penguinwu @SherlockNoMad @zou3519 @bdhirsh @yf225