Are you trying to use the padding_mode option of grid_sample()? If so, you can find it documented with an explanation here 144, and if there is something in the explanation you don’t understand, feel free to ask.
Or are you trying to implement a new type of padding for grid_sample()? That is, other than the existing zeros, border, and reflection. If so, then that’s a completely different matter.
It’s not clear from your question which one you need help with.