As you can see from the official documentation 17 torch.stack requires tensors of the same size.
The output will be a tensor with a new extra dimension in position 0 with value equal to the number of tensors stacked.
In your case dimension 0 of your original tensors (which is dimension 1 of the resulting tensor) does not match.
Maybe you wanted to concatenate the tensors, in this case you can try with:
torch.cat([a,b]) # output size is (5,2,1,2)