How to create a mask tensor

I have a list that contains different sizes of tensors so I used torch.nn.utils.rnn.pad_sequence to the list. For example, the original data is
grp_pt_data_list = [
[[1,2,1],[1,1,5],[2,1,3],[1,2,1],[1,1,1],],
[[1,2,1],[2,3,2],[1,3,2]],
[[1,3,1],[2,4,2],[1,1,2]]]
after padding the tensor is
tensor([[[[1., 1., 2., 1., 1.],
[1., 2., 1., 0., 0.],
[1., 2., 1., 0., 0.]],
[[2., 1., 1., 2., 1.],
[2., 3., 3., 0., 0.],
[3., 4., 1., 0., 0.]],
[[1., 5., 3., 1., 1.],
[1., 2., 2., 0., 0.],
[1., 2., 2., 0., 0.]]]], device=‘cuda:0’)
The length becomes maximum value 5. I wanted to apply a mask to the result of a nn.Conv2d(fea_dim, 4, kernel_size=(1,1)), so that the padded zeros could be reset to 0, and the other values will remain. Expected mask will be tensor([[ True, True, True, True, True],
[ True, True, True, False, False],
[ True, True, True, False, False]])
How should I create the mask tensor and apply the mask to conv2d results without a for loop? Or is there any other better way to not calculating the padded values?

it’s hard to understand what your padding does, but as for mask, you can just do mask with 1 and 0, then element-wise multiplication. Yet, why can’t you skip padding and mask if you have kernel size 1?

it’s because the input list have irregular sizes so I need to pad them to form a tensor