Torchscript with spconv


I’m trying to convert my model via jit.trace(). I’m currently using the spconv library for my Network. Training the network works fine and with no errors, but using jit.trace() throws a size mismatch error.

Here are the layers of my model: = spconv.SparseSequential(
            spconv.SparseConv2d(1, 64, 1),
            spconv.SparseConv2d(64, 256, 2, padding=(1, 0)),
            spconv.SparseConv2d(256, 512, 2, padding=(1, 0)),
            spconv.SparseConv2d(512, 256, 2, padding=(0, 1)),
            spconv.SparseConv2d(256, 64, 2, padding=(0, 1)),
            spconv.SparseConv2d(64, 1, 1),
            # nn.Tanh(),

Here is the error message:

RuntimeError: size mismatch, m1: [375 x 375], m2: [1 x 64] at /pytorch/aten/src/THC/generic/

The input consists of 375x375 matrices. The network operates on CUDA.

Maybe someone has an idea why this error comes up.

Thank you

That error looks like it’s coming from the actual operation, not anything to do with tracing. Are you tracing it with the same inputs you’re using to run it successfully in normal PyTorch?

If your model has any control flow that depends on the inputs tracing may not work correctly. Can you also post the full code you’re using to run/trace your model?


I already solved the problem, you were right. I accidentally passed a float as batch size, which caused this error.

1 Like