Torch-equivalent code for pytorch with nn.Replicate

I am recently trying to port Facebook babi simulator written in torch into pytorch
According to their MeMnet code, it has a line "nn.Replicate(1,3)(u)"
Now I understand what nn.Replicate(3)(x) means, since it is clearly noted in tutorial.
But what does nn.Replicate(1,3) means? Can someone show its meaning with an example?
Pytorch equivalent code (without legacy code) will be great.

Thanks first.

1 Like

I don’t think nn.Replicate exists in pytorch:

In [3]: torch.nn.Replicate
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-c0b9108e265b> in <module>()
----> 1 torch.nn.Replicate

AttributeError: module 'torch.nn' has no attribute 'Replicate'

Could you post a link to the the lua torch nn.Replicate (I’m not familiar with what it does).

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.

2 Likes