-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Model's state_dict
not loading properly when loading a ckpt
#484
Comments
state_dict
not loading properlystate_dict
not loading properly when loading a ckpt
Thanks for this @inafergra. I guess @dominikandreasseitz or @chMoussa are the best placed to have a look ? |
thanks @inafergra. @Roland-djee , since @inafergra already knows how to solve it he could coordinate with @chMoussa on fixing this. i can ofc also do it. Let me know |
If that is fine with them sure. |
@inafergra @chMoussa Would you be able to coordinate on this ? |
Right now, when loading model checkpoints (
QuantumModel
orQNN
) thestate_dict
of the model is not loaded properly. The issue is in theload_model()
function, which treats theQuantumModel.from_dict()
classmethod as an in-place operationqadence/qadence/ml_tools/saveload.py
Lines 114 to 116 in 70e12d4
when in reality
.from_dict()
is a class method and does not act as an in-place operation, as it returns a new class instance with the parameters taken from the input modelstate_dict
:qadence/qadence/model.py
Lines 276 to 308 in 70e12d4
The most straightforward solution would be to do
model = model.from_dict()
when loading thestate_dict
. However, this doesn't work since then, when using thetrain_grad()
loop, the parameters passed to the optimizer before the training loop do not correspond to the newly created instance of the model, and therefore the parameters won't be updated inoptimizer.step()
.One solution would be to make
.from_dict()
an instance method instead of a class method so that it acts as an in-place operation, by mutating the instance attributes instead of creating a new instance. This might cause some additional issues (@dominikandreasseitz mentioned the uuid assignments might cause problems?)The text was updated successfully, but these errors were encountered: