Torch._dynamo.optimize: The tensor has a non-zero number of elements, but its data is not allocated yet
Labels: triaged, oncall: pt2

### 🐛 Describe the bug

I am trying to optimize a code that calls the radius function from pytorch_cluster:
```python
import torch
from torch_cluster import radius
import torch._dynamo as dynamo

def myradius(x: torch.Tensor, y: torch.Tensor, r: float,
             batch_x: Optional[torch.Tensor] = None,
             batch_y: Optional[torch.Tensor] = None,
             max_num_neighbors: int = 32,
             num_workers: int = 1) -> torch.Tensor:
    return radius(x,y,r,batch_x, batch_y, max_num_neighbors, num_workers)
device = torch.device('cuda:0')
x2 = torch.tensor([0.0], device=device)
y2 = torch.tensor([1.0], device=device)
dynamo.explain(myradius, x2, y2, 2)
```
Executing this code results in the following error:
```
Traceback (most recent call last):                                                                                                                                           
  File "/home/raul/mambaforge/envs/torch2-test/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 1194, in run_node                                                
    return node.target(*args, **kwargs)                                                                                                                                      
  File "/home/raul/mambaforge/envs/torch2-test/lib/python3.10/site-packages/torch/_ops.py", line 499, in __call__                                                          
    return self._op(*args, **kwargs or {})                                                                                                                                   
RuntimeError: The tensor has a non-zero number of elements, but its data is not allocated yet. Caffe2 uses a lazy allocation, so you will need to call mutable_data() or raw_
mutable_data() to actually allocate memory.                                                                                                                                  
                                                                                                                                                                             
The above exception was the direct cause of the following exception:                                                                                                         
                                                                                                                                                                             
Traceback (most recent call last):                                                                                                                                           
  File "/home/raul/mambaforge/envs/torch2-test/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 1152, in get_fake_value                                          
    return wrap_fake_exception(                                                                                                                                              
  File "/home/raul/mambaforge/envs/torch2-test/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 808, in wrap_fake_exception                                      
    return fn()                                                                                                                                                              
  File "/home/raul/mambaforge/envs/torch2-test/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 1153, in <lambda>                                                
    lambda: run_node(tx.output, node, args, kwargs, nnmodule)                                                                                                                
  File "/home/raul/mambaforge/envs/torch2-test/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 1206, in run_node                                                
    raise RuntimeError(                                                                                                                                                      
RuntimeError: Failed running call_function torch_cluster.radius(*(FakeTensor(FakeTensor(..., device='meta', size=(1, 1)), cuda:0), FakeTensor(FakeTensor(..., device='meta', 
size=(1, 1)), cuda:0), None, None, 2, 32, 1), **{}):                                                                                                                         
The tensor has a non-zero number of elements, but its data is not allocated yet. Caffe2 uses a lazy allocation, so you will need to call mutable_data() or raw_mutable_data()
 to actually allocate memory.                                                                                                                                                
(scroll up for backtrace)
``` 
**I do not understand this error at all. Some pointers on how to approach this error would be much appreciated.**

On the other hand, the definition of the radius function in pytorch_cluster is not that complicated, being most of the complexity hidden in the C++ side:
```python
def radius(x: torch.Tensor, y: torch.Tensor, r: float,
           batch_x: Optional[torch.Tensor] = None,
           batch_y: Optional[torch.Tensor] = None, max_num_neighbors: int = 32,
           num_workers: int = 1) -> torch.Tensor:

    x = x.view(-1, 1) if x.dim() == 1 else x
    y = y.view(-1, 1) if y.dim() == 1 else y
    x, y = x.contiguous(), y.contiguous()

    batch_size = 1
    if batch_x is not None:
        assert x.size(0) == batch_x.numel()
        batch_size = int(batch_x.max()) + 1
    if batch_y is not None:
        assert y.size(0) == batch_y.numel()
        batch_size = max(batch_size, int(batch_y.max()) + 1)

    ptr_x: Optional[torch.Tensor] = None
    ptr_y: Optional[torch.Tensor] = None
    if batch_size > 1:
        assert batch_x is not None
        assert batch_y is not None
        arange = torch.arange(batch_size + 1, device=x.device)
        ptr_x = torch.bucketize(arange, batch_x)
        ptr_y = torch.bucketize(arange, batch_y)

    return torch.ops.torch_cluster.radius(x, y, ptr_x, ptr_y, r,
                                          max_num_neighbors, num_workers)
```
On the suspicion that the ptr_x/y being None was somehow causing the error, I tried calling the function such that it constructs them.

```python
x = torch.tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]], device=device).float()
batch_x = torch.tensor([0, 0, 0, 0], device=device)
y = torch.tensor([[-1, 0], [1, 0]], device=device).float()
batch_y = torch.tensor([0, 0], device=device)
dynamo.explain(myradius, x, y, 1.5, batch_x, batch_y)
```
This code succeeds. But I am clueless as to why -.-

### Error logs

_No response_

### Minified repro

Running the minifier just prints the above error again.

### Versions

```Python version: 3.10.9 | packaged by conda-forge | (main, Feb  2 2023, 20:20:04) [GCC 11.3.0] (64-bit runtime)                                                               
Is CUDA available: True                                                                                                                                                      
CUDA runtime version: 11.8.89
Versions of relevant libraries:
[pip3] numpy==1.24.2
[pip3] pytorch-triton==2.0.0+b8b470bc59
[pip3] torch==2.0.0.dev20230227+cu118
[pip3] torch-cluster==1.6.0
[pip3] torch-geometric==2.3.0
[pip3] torch-scatter==2.1.0
[pip3] torch-sparse==0.6.16
[pip3] torchaudio==2.0.0.dev20230227
[pip3] torchmetrics==0.11.1
[pip3] torchvision==0.15.0.dev20230227
[conda] blas                      2.116                       mkl    conda-forge
[conda] blas-devel                3.9.0            16_linux64_mkl    conda-forge
[conda] libblas                   3.9.0            16_linux64_mkl    conda-forge
[conda] libcblas                  3.9.0            16_linux64_mkl    conda-forge
[conda] liblapack                 3.9.0            16_linux64_mkl    conda-forge
[conda] liblapacke                3.9.0            16_linux64_mkl    conda-forge
[conda] mkl                       2022.1.0           h84fe81f_915    conda-forge
[conda] mkl-devel                 2022.1.0           ha770c72_916    conda-forge
[conda] mkl-include               2022.1.0           h84fe81f_915    conda-forge
[conda] numpy                     1.24.2          py310h8deb116_0    conda-forge
[conda] pytorch-cuda              11.8                 h7e8668a_3    pytorch-nightly
[conda] pytorch-mutex             1.0                         cpu    pytorch-nightly
[conda] pytorch-triton            2.0.0+b8b470bc59          pypi_0    pypi
[conda] torch                     2.0.0.dev20230227+cu118          pypi_0    pypi
[conda] torch-cluster             1.6.0                     dev_0    <develop>
[conda] torch-geometric           2.3.0                    pypi_0    pypi
[conda] torch-scatter             2.1.0                    pypi_0    pypi
[conda] torch-sparse              0.6.16                   pypi_0    pypi
[conda] torchaudio                2.0.0.dev20230227       py310_cpu    pytorch-nightly
[conda] torchmetrics              0.11.1                   pypi_0    pypi
[conda] torchvision               0.15.0.dev20230227       py310_cpu    pytorch-nightly
```

cc @ezyang @soumith @msaroufim @wconstab @ngimel @bdhirsh