Repository: pytorch
Issue: [TensorDict - compile] dynamo generator compatibility
Labels: low priority,triaged,oncall: pt2,module: dynamo

### 🐛 Describe the bug

dynamo doesn't like generators _td.py L2871

removing the [following block](https://github.com/pytorch/tensordict/blob/b5cb40aaeb824ac632c0a2f178430105513525d1/tensordict/tensorclass.py#L2870-L2917) results in this error:

```
__________________________________________________________________________ TestTD.test_items __________________________________________________________________________
Traceback (most recent call last):
  File "/Users/vmoens/Repos/rl/tensordict/test/test_compile.py", line 109, in test_items
    keys_c, vals_c = items_c(data)
                     ^^^^^^^^^^^^^
  File "/Users/vmoens/venv/rl/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 434, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/vmoens/Repos/rl/tensordict/test/test_compile.py", line 103, in items
    keys, vals = zip(*td.items(True, True))
                      ^^^^^^^^^^^^^^^^^^^^
  File "/Users/vmoens/Repos/rl/tensordict/tensordict/_td.py", line 2918, in items
    return fast_iter()
           ^^^^^^^^^^^
  File "/Users/vmoens/venv/rl/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 1121, in __call__
    return self._torchdynamo_orig_callable(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vmoens/venv/rl/lib/python3.11/site-packages/torch/_dynamo/convert_frame.py", line 441, in __call__
    unimplemented("generator")
  File "/Users/vmoens/venv/rl/lib/python3.11/site-packages/torch/_dynamo/exc.py", line 221, in unimplemented
    raise Unsupported(msg)
torch._dynamo.exc.Unsupported: generator
======================================================================= short test summary info =======================================================================
```


### Versions

Collecting environment information...
PyTorch version: 2.5.0.dev20240627
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 14.5 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.3.9.4)
CMake version: version 3.29.3
Libc version: N/A

Python version: 3.11.7 (v3.11.7:fa7a6f2303, Dec  4 2023, 15:22:56) [Clang 13.0.0 (clang-1300.0.29.30)] (64-bit runtime)
Python platform: macOS-14.5-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Apple M3 Max

Versions of relevant libraries:
[pip3] mujoco-torch==0.1.0
[pip3] numpy==1.26.4
[pip3] optree==0.11.0
[pip3] torch==2.5.0.dev20240627
[pip3] torchao==0.1
[pip3] torchaudio==2.4.0.dev20240627
[pip3] torchrl==0.4.0+7c0a7c8
[pip3] torchtext==0.18.0
[pip3] torchvision==0.20.0.dev20240627
[conda] Could not collect


cc @ezyang @anijain2305 @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @amjames