-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Trainer.from_argparse_args with additional kwargs causes model to not be saved #1714
Comments
Hi! thanks for your contribution!, great first issue! |
I had the same issue. I fixed it using the following "import copy; self.hparams=copy.deepcopy(hparams)". This is a quick fix, but maybe it can help you. |
I usually have some lines like mparams = Namespace(**vars(params))
del mparams.logger for this after I've created the trainer object with |
I try your solution, but it makes trainer can't save model. Here is my code:
Also I have tried
Is there any solutions to this problem? |
This solved an issue I had that occurred only when returning val_loss from Show traceback
|
Changing just this small part of the source code worked for me Another workaround would be to use for eg. Trainer(gpus = hparams.gpus ...), which is not suggested but will definitely work |
Just confirmed that #2029 fixes the issue for me. |
🐛 Bug
When using Trainer.from_argparse_args() to initialize the trainer, there will be some specific arguments that we would like to keep constant and not send as part of hparams. If the extra arguments turn out to be an object, such as a TensorBoardLogger or a ModelCheckpoint object, the model will not be saved because these objects get added to hparams
To Reproduce
Code sample
Error
TypeError: cannot pickle '_thread.lock' object
Expected behavior
The model to be saved without considering the extra arguments sent as hparams
Environment
Additional context
Possible Fix
I believe that a possible fix is to change the from_argparse_args method
from
to
This ensures that the **kwargs are not added to the hparams of the model and the model gets saved successfully, but I'm not sure of the impact of this change
The text was updated successfully, but these errors were encountered: