InnovArul:

Why not pass the custom_value while calling the self.conv_1 in custom_model's forward()? This way, either you can set the custom_value at each run before forward() call or directly parameterize the forward() with custom_value.


Yes, I can set it as a parameter directly, but then I would have to do this for each layer right? That’s why i was seeing if there is a way to set something at the model level that I can access within each layer.



 InnovArul:

Then custom_value is not expected to get gradients?
If so, it doesn’t need to be nn.Parameter().


No, like I said in my post, I was just using parameter since I can set it easily using state_dict(). Again, it would be ideal if it is something I can set about the model before I run it. But doesn’t have to be parameter no. As long as I can set it easily.



 InnovArul:

By the time you are trying to set custom_value, self.conv_1 have been already created with its old value. (i.e., 0)


Yes, so the question is is there something else I could use instead of custom_value here to pass to my MyConv2D layer. So one thing you mentioned was:



 InnovArul:

directly parameterize the forward() with custom_value.


Do you mean, just pass an additional parameter to my MyConv2D.forward()? I can do that too but it would not be anything associated with my model then right? If there isn’t a way to do this, that’s probably what I’ll end up doing.