Repository: pytorch
Issue: RuntimeError: Trying to create tensor with negative dimension -1741885395: [-1741885395]
Labels: module: sparse,triaged

## Issue description  RuntimeError: Trying to create tensor with negative dimension -1741885395: [-1741885395]

I am running a graph convolution network model using Pytorch and get the problem:
```
   _File "Reddit_3.py", line 83, in get_A_r
    adj_label = torch.sparse.mm(adj_label,torch.t(adj_label))
  File "/home2/graphmodel/venv/lib/python3.8/site-packages/torch/sparse/__init__.py", line 90, in mm
    return torch._sparse_sparse_matmul(mat1, mat2)
RuntimeError: Trying to create tensor with negative dimension -1741885395: [-1741885395]_
```


This adj_label is (232965, 232965) size with type as tensor.cuda.sparse.FloatTensor and I do not know why it becomes negative dimension when doing sparse multiplication. 


This get_A_r function is working properly with other small datasets before, but with this reddit dataset, is that because overflow? 


The data is reddit take from paper: GraphSage and I use the Pytorch-Geometric library to load:
```
_from torch_geometric.datasets import Reddit
from torch_geometric.data import NeighborSampler

_train_loader = NeighborSampler(data.edge_index, node_idx=data.train_mask,
                               sizes=[25, 10], batch_size=32, shuffle=True,     
                               num_workers=12)
subgraph_loader = NeighborSampler(data.edge_index, node_idx=None, sizes=[-1],
                                  batch_size=32, shuffle=False,
                                  num_workers=12)__
```


As the dataset is large and I change batch_size to 1 and num_workers to 0 to run on my local machine.

## Code example
```
def get_A_r(adj, r):
    adj_label = adj.float()
    if r == 1:
        adj_label = adj_label
    elif r == 2:
        adj_label = torch.sparse.mm(adj_label,torch.t(adj_label))
        #adj_label = torch.sparse.mm(adj_label.to_dense(),torch.t(adj_label.to_dense())) 202GB in dense
    elif r == 3:
        adj_label = torch.sparse.mm(torch.sparse.mm(adj_label, adj_label),adj_label)
    return adj_label
```

This code is to get the adjcaency matrix of graph which will be used in train function to calculate loss, other related code:

```
 def get_feature_dis(x):
    """
    x :           batch_size x nhid
    x_dis(i,j):   item means the similarity between x(i) and x(j).
    """
    x_dis = torch.mm(x, x.T)
    mask = torch.eye(x_dis.shape[0]).cuda()
    x_sum = torch.sum(x**2, 1).reshape(-1, 1)
    x_sum = torch.sqrt(x_sum).reshape(-1, 1)
    x_sum = torch.mm(x_sum,x_sum.T)
    x_dis = x_dis*(x_sum**(-1))
    x_dis = (1-mask) * x_dis
    return x_dis

def Ncontrast(x_dis, adj_label, tau = args.tau):
    """compute the Ncontrast loss"""
    x_dis = torch.exp(tau*x_dis)
    x_dis_sum = torch.sum(x_dis, 1)
    x_dis_sum_pos = torch.sum(x_dis*adj_label,1)
    loss = -torch.log(x_dis_sum_pos*(x_dis_sum**(-1))+1e-8).mean()
    return loss_
```
Then add this loss to the training loss

## System Info
- PyTorch or Caffe2:  Pytorch 
- How you installed PyTorch (conda, pip, source): pip
- Build command you used (if compiling from source):
- OS: Ubuntu 20.04
- PyTorch version: 1.9.0
- Python version: 3.8.10
- CUDA/cuDNN version: 10.2
- GPU models and configuration:  Nvidia 2080Ti, NVIDIA-SMI 460.91.03 
- GCC version (if compiling from source):
- CMake version:
- Versions of any other relevant libraries: PyG torch-geometric    2.0.0


cc @nikitaved @pearu @cpuhrsch @IvanYashchuk