Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: view size is not compatible with input tensor's size in TSAGCN #291

Open
Borzyszkowski opened this issue Feb 17, 2025 · 0 comments

Comments

@Borzyszkowski
Copy link

When using TSAGCN from torch_geometric_temporal, I encountered the following error:

File "lib/python3.8/site-packages/torch_geometric_temporal/nn/attention/tsagcn.py", line 260, in forward
    y = self._adaptive_forward(x, y)
  File "lib/python3.8/site-packages/torch_geometric_temporal/nn/attention/tsagcn.py", line 237, in _adaptive_forward
    A2 = self.conv_b[i](x).view(N, self.inter_c * T, V)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

This error occurs in _adaptive_forward() when calling .view() on a tensor that is not memory-contiguous.

Expected Behavior
The model should process the input without error.

Actual Behavior
The model crashes due to .view() being used on a non-contiguous tensor.

System Information

torch==2.4.1+cu124
torch-geometric==2.6.1
torch-geometric-temporal==0.54.0
torch_cluster==1.6.3+pt24cu124
torch_scatter==2.1.2+pt24cu124
torch_sparse==0.6.18+pt24cu124
torch_spline_conv==1.2.2+pt24cu124
torchaudio==2.4.1+cu124
torchgeometry==0.1.2
torchvision==0.19.1+cu124
Python version: 3.8.10
OS: ubuntu20

Example to reproduce:

import torch
from torch_geometric.data import Data
from torch_geometric_temporal.nn.attention import AAGCN

# Define the graph that produces the error
x = torch.rand(2, 80, 1556, 1)
edge_index = torch.randint(0, 2, (2, 18456), dtype=torch.long)
y = torch.rand(2, 2)  

# Create the graph object
graph = Data(x=x, edge_index=edge_index, y=y)

# Create the AAGCN layer (Attention Aggregated Graph Convolutional Network)
aagcn = AAGCN(in_channels=1,
              out_channels=16,
              edge_index=edge_index,
              num_nodes=2,
              adaptive=True,
              attention=True)

# Forward pass (this is where the original issue happens)
x = x.permute(0, 3, 1, 2).contiguous()  # Batch, Features_In, Temporal_In, Node_Number

 # This will raise the 'view' error in some cases
output = aagcn(x) 

current code in torch_geometric_temporal/nn/attention/tsagcn.py#237
A2 = self.conv_b[i](x).view(N, self.inter_c * T, V)

proposed fix:
A2 = self.conv_b[i](x).reshape(N, self.inter_c * T, V)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant