View size is not compatible with input tensor's size and stride

The posted error is raised, if the tensor it not contiguous in memory and thus view will fail.
You could either use .reshape instead as suggested in the error message or .contiguous().view(...) alternatively.