Repository: pytorch
Issue: dynamo supports Tensor.tolist but not Tensor.item
Labels: triaged,actionable,oncall: pt2,module: dynamic shapes,module: dynamo

### 🐛 Describe the bug

```python
import torch


@torch.compile(backend="eager", fullgraph=True)
def ok(x):
    return tuple(x.to(torch.int64).tolist())

assert ok(torch.tensor([1, 3])) == (1, 3)


@torch.compile(backend="eager", fullgraph=True)
def not_ok(x):
    return int(x[0]), int(x[1])

assert not_ok(torch.tensor([1, 3])) == (1, 3)
```

```
torch._dynamo.exc.Unsupported: Tensor.item
```

<details><summary>Traceback</summary>
<p>

```
Traceback (most recent call last):
  File "/home/philip/git/pytorch/vision/main_dynamo.py", line 15, in <module>
    assert not_ok(torch.tensor([1, 3])) == (1, 3)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/eval_frame.py", line 489, in _fn
    return fn(*args, **kwargs)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/eval_frame.py", line 655, in catch_errors
    return callback(frame, cache_entry, hooks, frame_state)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/convert_frame.py", line 383, in _convert_frame_assert
    compiled_product = _compile(
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/convert_frame.py", line 645, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/utils.py", line 244, in time_wrapper
    r = func(*args, **kwargs)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/convert_frame.py", line 562, in compile_inner
    out_code = transform_code_object(code, transform)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/bytecode_transformation.py", line 1033, in transform_code_object
    transformations(instructions, code_options)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/convert_frame.py", line 151, in _fn
    return fn(*args, **kwargs)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/convert_frame.py", line 527, in transform
    tracer.run()
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/symbolic_convert.py", line 2123, in run
    super().run()
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/symbolic_convert.py", line 818, in run
    and self.step()
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/symbolic_convert.py", line 781, in step
    getattr(self, inst.opname)(inst)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/symbolic_convert.py", line 470, in wrapper
    return inner_fn(self, inst)
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/symbolic_convert.py", line 1213, in CALL_FUNCTION
    self.call_function(fn, args, {})
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/symbolic_convert.py", line 652, in call_function
    self.push(fn.call_function(self, args, kwargs))
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/variables/builtin.py", line 590, in call_function
    item = args[0].call_method(tx, "item", [], {})
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/variables/tensor.py", line 577, in call_method
    unimplemented(f"Tensor.{name}")
  File "/home/philip/.conda/envs/pytorch-vision-dev/lib/python3.8/site-packages/torch/_dynamo/exc.py", line 193, in unimplemented
    raise Unsupported(msg)
torch._dynamo.exc.Unsupported: Tensor.item

from user code:
   File "/home/philip/git/pytorch/vision/main_dynamo.py", line 13, in not_ok
    return int(x[0]), int(x[1])

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
```

</p>
</details> 

I don't know how `Tensor.tolist()` and `Tensor.item()` are implemented internally. From this ignorant perspective, it seems to me that both do a similar thing in that they convert tensor values to their corresponding Python equivalent. Hence, I'm surprised one is fine for dynamo while the other is not.

### Versions

2.2.0.dev20231122+cpu

cc @ezyang @msaroufim @wconstab @bdhirsh @anijain2305 @zou3519 @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng