Seems to be a bug with padding in a replicate mode (3D tensors expect 2 values for padding)

>>> import torch as to
>>> import torch.nn.functional as fu
>>> a=to.randn(3,2,5)
>>> _=fu.pad(a[:, 1:], (0,0,1,0,), mode='constant')  # works!
>>> _=fu.pad(a[:, 1:], (0,0,1,0,), mode='replicate')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/torch/nn/", line 2852, in pad
    assert len(pad) == 2, '3D tensors expect 2 values for padding'
AssertionError: 3D tensors expect 2 values for padding

Am I doing something wrong?


In replicate mode. pad expects batched image-like Tensors as input I think. If you want to do 2D padding, you should give it a 4D input.


I see, okay thank you.