print(torch.__version__) # 1.0.1.post2
#stacking example
a = torch.randn(2,3,4)
b = torch.randn(2,3)
print(a.size()) # 2, 3, 4
print(b.size()) # 2, 3
b = torch.unsqueeze(b, dim=2)  
print(b.size()) # 2, 3, 1
r = torch.stack([a, b], dim=2 )
print(r)

Outputs the error like this:
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 2. Got 4 and 1 in dimension 3 at /pytorch/aten/src/TH/generic/THTensorMoreMath.cpp:1307
I was trying to achieve r.size() = 2, 3, 5
according to this 1.