I’m no Lua torch expert, but it seems that n.Replicate(1, 3)(u) adds a dimension in axis 3.
a 
>> [torch.DoubleTensor of size 1x2x3x4]
nn.Replicate(1,3)(a)
>> [torch.DoubleTensor of size 1x2x1x3x4]

You could achieve this in Pytorch using a.unsqueeze(2).
Could you confirm the lua Torch behavior, since I’m really not experienced in this framework.