-
Notifications
You must be signed in to change notification settings - Fork 818
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] PicklingError: "Can't pickle : attribute lookup on __main__ failed" happend when fit model #1843
Comments
in class TorchForecastingModel:
error happened in this line |
Python documentation says that lambda functions cannot be pickled. Should we conside using dill dump the model? |
jupp, had the same issue.
|
the workaround is change the lambda to be function, the fix suggestion is to use dill dump the model. |
Thank you for reporting the bug with a code snippet and finding a workaround @joshua-xia, thank you @philippGraf for sharing another solution. I don't think that we will want to add a dependency just to pickle the lambda functions in the These kwargs should also be added to the Would you be interested in opening a PR to fix this? |
I think we can just update the docs (and maybe enforce) to use a function instead of lambdas for the encoders. |
Describe the bug
when I test the model (maybe any forecast model, I test TFTModel, NlinearModel etc.)
I set the following parameters of model:
force_reset=True,
save_checkpoints=True,
optimizer_kwargs={"lr": results.suggestion()},
pl_trainer_kwargs={"callbacks": [early_stopper]},
add_encoders={
'cyclic': {'future': ['month']},
'datetime_attribute': {'future': ['hour', 'dayofweek']},
'position': {'past': ['relative'], 'future': ['relative']},
'custom': {'past': [lambda idx: (idx.year - 1950) / 50]},
'transformer': Scaler(StandardScaler())
}
model.fit(
series=[train_1, train_2, train_3],
val_series=[val_1, val_2, val_3],
past_covariates=[train_1_covariates, train_2_covariates, train_3_covariates],
val_past_covariates=[val_1_covariates, val_2_covariates, val_3_covariates],
)
and train the model with validation data, it should trigger the model save the best model checkpoint.
but the following error happened:
--> 636 pickler.dump(obj)
637 data_value = data_buf.getvalue()
638 zip_file.write_record('data.pkl', data_value, len(data_value))
PicklingError: Can't pickle at 0x2bc431280>: attribute lookup on main failed
when I remove add_encoders then the train work well.
I think the add_encoders lead to something can NOT dump correctly.
Anybody take a look this issue? it block me the model performance testing.
Thanks!
To Reproduce
see the description.
Expected behavior
model should be train and save the best checkpoint
System (please complete the following information):
The text was updated successfully, but these errors were encountered: