Andrii_Pylypenko:

When I changed the input to random values using torch.randn(25, 5, requires_grad=True) it worked good.


Could you add a print statement into the training loop and check the shape of input?
Your shapes and value ranges look correct, which also explains why the code using random tensors works.
Based on the error message, I assume the input tensor might become a 4-dimensional tensor for some reason (e.g. used in a segmentation use case) and thus the error is raised.