If I’m not mistaken, torch.jit.trace would use static shapes for dim1+ but would still allow to use a flexible batch size (toch.jit.script would allow more flexible inputs as well as data-dependent control flow).
The current issue is raised in a view or reshape operation, which apparently tries to reshape the tensor to a shape of [2, -1, 8, 32] (512 elements) while the input only contains 256 elements.