Modifying Convolution Weights

Hello, I would like to implement an error correction mechanism for the weights of a convolution during the inference of a pre-trained model in PyTorch (no training process needed).

I am considering two options: the first is to perform a check on the weights before the convolution (could this be done via a forward pre-hook?), and the second is to modify the operator/convolution code directly also to perform the checking before the convolution.

I would like to know which option would be easier to implement and which would be more optimal regarding temporal overheads.

In the first case, I have experience with hooks. Still, in the case of modifying an operator’s code in CUDA, like convolution, I am unsure how to proceed, so any tutorial or guidance would be greatly appreciated.

Thank you.