Function batch_pad_right() doesn't support other mode except for 'constant'

I want to use the function batch_pad_right() as a collate_fn with mode ‘circular’ in my dataloader. However, when I apply this function on a signal data in the dataloader, it shows error: NotImplementedError(“Only 3D, 4D, 5D padding with non-constant padding are supported for now”). And the hparam for dataloader is:

batch_size: 64
collate_fn: !name:speechbrain.dataio.batch.PaddedBatch
padding_func: !name:speechbrain.utils.data_utils.batch_pad_right
mode: circular

Actually, in function batch_pad_right(), the tensors in a batch are processed one-by-one, so the input of torch.pad is a 1-D tensor, leading to this NotImplementedError.

I do not know if I miss some points. I appreciate if there are any other solutions. Although the torch does not support pad on 1-D or 2-D tensor, I think this function should be more robust to deal with this problem. Like just reshaping the tensor to 3-D using torch.unsqueeze()?


Pytorch does not seem to support for some strange reason circular padding for 2-D and 1-D tensors.
Reshaping can work, you can submit a PR if you like probably just adding an if condition in pad_batch_right in utils.data_utils should work.
Also directly wrapping pad could work as this is mainly a Pytorch issue. This last option will be more flexible.