RuntimeError: pseudo.size(1) == kernel_size.numel() INTERNAL ASSERT FAILED. Input mismatch

amirtmgr: <p>Hi! All,</p>
<p>I recently tried to train a <strong>SplineCNN</strong> using <strong>Pytorch-Geometric</strong> as in example called <a href="https://github.com/pyg-team/pytorch_geometric/blob/master/examples/mnist_nn_conv.py" rel="noopener nofollow ugc">mnist_nn_conv.py</a>. But, I got the following error.</p>
<blockquote>
<p>RuntimeError: The following operation failed in the TorchScript interpreter.<br>
Traceback of TorchScript (most recent call last):<br>
File “….conda\envs\dl23\lib\site-packages\torch_spline_conv\basis.py”, line 10, in spline_basis<br>
is_open_spline: torch.Tensor,<br>
degree: int) → Tuple[torch.Tensor, torch.Tensor]:<br>
return torch.ops.torch_spline_conv.spline_basis(pseudo, kernel_size,<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ &lt;— HERE<br>
is_open_spline, degree)<br>
RuntimeError: pseudo.size(1) == kernel_size.numel() INTERNAL ASSERT FAILED at “D:\a\pytorch_spline_conv\pytorch_spline_conv\csrc\cuda\basis_cuda.cu”:104, please report a bug to PyTorch. Input mismatch.</p>
</blockquote>
<p>The error said it’s a bug and suggested to report to <strong>Pytorch</strong>. Could you please tell, if my implementation is wrong or it is a bug?</p>
<p><strong>My code:</strong></p>
<pre><code class="lang-auto">`
import os.path as osp

import torch
import torch.nn as nn
import torch.nn.functional as F

import torch_geometric.transforms as T
from torch_geometric.datasets import MNISTSuperpixels
from torch_geometric.loader import DataLoader
from torch_geometric.nn import (
    SplineConv,
    global_mean_pool,
    graclus,
    max_pool,
    max_pool_x,
)
from torch_geometric.utils import normalized_cut


//Datasets
path = osp.join(osp.dirname(osp.realpath("/")), '..', 'data', 'MNIST')
transform = T.Cartesian(cat=False)
train_dataset = MNISTSuperpixels(path, True, transform=transform)
test_dataset = MNISTSuperpixels(path, False, transform=transform)
train_loader = DataLoader(train_dataset, batch_size=64, shuffle=True)
test_loader = DataLoader(test_dataset, batch_size=64, shuffle=False)
d = train_dataset`

//Normalized Cut
def normalized_cut_2d(edge_index, pos):
    row, col = edge_index
    edge_attr = torch.norm(pos[row] - pos[col], p=2, dim=1)
    return normalized_cut(edge_index, edge_attr, num_nodes=pos.size(0))

//SplineCNN
class Net(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = SplineConv(in_channels = d.num_features, out_channels= 32,dim=1, kernel_size = 3)
        self.conv2 = SplineConv(in_channels = 32, out_channels= 64, dim=1, kernel_size = 3)
        self.fc1 = torch.nn.Linear(64, 128)
        self.fc2 = torch.nn.Linear(128, d.num_classes)

    def forward(self, data):
        data.x = F.elu(self.conv1(data.x, data.edge_index, data.edge_attr))
        weight = normalized_cut_2d(data.edge_index, data.pos)
        cluster = graclus(data.edge_index, weight, data.x.size(0))
        data.edge_attr = None
        data = max_pool(cluster, data, transform=transform)

        data.x = F.elu(self.conv2(data.x, data.edge_index, data.edge_attr))
        weight = normalized_cut_2d(data.edge_index, data.facepos)
        cluster = graclus(data.edge_index, weight, data.x.size(0))
        x, batch = max_pool_x(cluster, data.x, data.batch)

        x = global_mean_pool(x, batch)
        x = F.elu(self.fc1(x))
        x = F.dropout(x, training=self.training)
        return F.log_softmax(self.fc2(x), dim=1)

//Create Model
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = Net().to(device)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)

//Train Function
def train(epoch):
    model.train()

    if epoch == 16:
        for param_group in optimizer.param_groups:
            param_group['lr'] = 0.001

    if epoch == 26:
        for param_group in optimizer.param_groups:
            param_group['lr'] = 0.0001

    for data in train_loader:
        data = data.to(device)
        optimizer.zero_grad()
        F.nll_loss(model(data), data.y).backward()
        optimizer.step()

//Test Function
def test():
    model.eval()
    correct = 0

    for data in test_loader:
        data = data.to(device)
        pred = model(data).max(1)[1]
        correct += pred.eq(data.y).sum().item()
    return correct / len(test_dataset)

//Run epoch
for epoch in range(1, 31):
    train(epoch)
    test_acc = test()
    print(f'Epoch: {epoch:02d}, Test: {test_acc:.4f}')```


</code></pre>
<p><strong>Environment</strong></p>
<ul>
<li>PyG version: 2.1.0</li>
<li>PyTorch version: 1.13.0</li>
<li>OS: Windows</li>
<li>Python version:3.10.8</li>
<li>CUDA/cuDNN version: 11.7</li>
<li>How you installed PyTorch and PyG (conda, pip, source):pip</li>
<li>Any other relevant information (e.g., version of torch-scatter):pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f <a href="https://data.pyg.org/whl/torch-1.13.0+cu117.html" rel="noopener nofollow ugc">https://data.pyg.org/whl/torch-1.13.0+cu117.html</a></li>
</ul>
<pre><code class="lang-auto"></code></pre>

ptrblck: <p>The error is raised in <a href="https://github.com/rusty1s/pytorch_spline_conv/blob/731f8cd2054185f9ceda6e671b7f91a7e904a370/csrc/cuda/basis_cuda.cu#L104">this line</a> by <code>pytorch_spline_conv</code>. I’m unsure why the error message asks you to report a bug to PyTorch as the check is clearly in this 3rd party repository and I wouldn’t know how PyTorch could be responsible for this shape mismatch.<br>
In any case, check what <code>pseudo</code> is and make sure its <code>size(1)</code> matches the number of elements in <code>kernel_size</code>.</p>

amirtmgr: <p>Thank you for your help. I will look into this.</p>