In the above code, ‘x’ is the input and the convolutional weights are modified using the ‘.data’ attribute. ‘values’ is a tensor of the size of kernel_size x kernel_size which in the above example is 3 x 3. I’ve read from multiple sources how using the ‘.data’ attribute is deprecated and shouldn’t be used since it leads to incorrect gradient calculations. I would like to know the right way to modify the convolutional weights.
Wrap the weight manipulation into a with torch.no_grad() context to explicitly disable Autograd for this operation instead of manipulating the .data attribute.
Thank you for your reply @ptrblck. What if ‘values’ are being generated by another sub-network and thus gradient flow is necessary through ‘values’ as well? In that case, will torch.no_grad() work?