Hello,
I have understood difference between register_buffer() and register_parameter/nn.Parameter.
In my models I initialize my variable either into the buffer or as a parameter similar to this code:
if self.is_param == True:
self.register_buffer("_variable", variable)
elif self.is_param == False:
self.variable= torch.nn.Parameter(variable)
# This is the function call I want to implement (but I have no idea how)
def change_variable_state(flag_param : bool = True):
if flag_param == True:
# make the variable a parameter
elif flag_param == False:
# make the variable a normal buffer in the state_dict
However, now I would like to be able to move this variable from a Parameter to a "normal buffered variable and vice-versa. I.e. I would look to transformed a buffered variable into a parameter.
In other words: I want to dynamically change the “buffer” state of my variable so that I can see it either in the function named_parameters() or not.
Any help is much appreciated.
Thanks