Ignore zeros or some elements in the input


I am wondering is there a way with which I can give a layer in Pytorch a mask using which it can ignore certain values of the input?

I saw a post regarding creating a custom layer to ignore zeros, however, I am wondering if this functionality is prebuilt in the layers of Pytorch (say Conv2d or linear).