Changing the convolution behaviour

Hello there.

I would like to ask if it is possible to change the convolution behaviour in pytorch with the following goal:

In convolutional operations, for specific numbers occured in multiplication in conv, replace their result with specific number, for example: if 5 * 3 is found, replace its result with 12 instead of 15. Basically I want to check each operation in convolution and change their result according to their value.

I first tried to use nn.functional.unfold and define a custom dot product function to replace conv2d but it is extremely slow (2000X slow-down for my platform).

I think I need to define a custom Function or Module by imitating the soure code of conv2d, but no luck on figuring out how conv2d works in the bottom layer (operation level). Is it possible to do this in python, or I have to dive into the C++ codes?

Thanks,