Skip to content
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

fix: replacing lambda with named function to make model pickable #1594

Merged
merged 6 commits into from
Feb 28, 2023

Conversation

madtoinou
Copy link
Collaborator

Fixes #1587.

Summary

save() was not working on FTT model if the trend argument was neither "poly" or "exp" because the function lambda x : 0 is not pickable. Just created a class method to have a named function that can be pickled and updated the docstring.

Other Information

I'll make sure all the other models save() method are working before converting this draft PR into a real one.

@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2023

Codecov Report

Base: 94.08% // Head: 94.04% // Decreases project coverage by -0.04% ⚠️

Coverage data is based on head (dc1a2db) compared to base (c80049b).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1594      +/-   ##
==========================================
- Coverage   94.08%   94.04%   -0.04%     
==========================================
  Files         125      125              
  Lines       11171    11164       -7     
==========================================
- Hits        10510    10499      -11     
- Misses        661      665       +4     
Impacted Files Coverage Δ
darts/models/forecasting/fft.py 96.42% <100.00%> (+0.23%) ⬆️
darts/utils/data/tabularization.py 99.27% <0.00%> (-0.73%) ⬇️
darts/timeseries.py 92.28% <0.00%> (-0.22%) ⬇️
darts/ad/anomaly_model/filtering_am.py 91.93% <0.00%> (-0.13%) ⬇️
...arts/models/forecasting/torch_forecasting_model.py 89.88% <0.00%> (-0.04%) ⬇️
darts/models/forecasting/block_rnn_model.py 98.24% <0.00%> (-0.04%) ⬇️
darts/models/forecasting/nhits.py 99.27% <0.00%> (-0.01%) ⬇️
darts/datasets/__init__.py 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@madtoinou madtoinou marked this pull request as ready for review February 24, 2023 12:50
@madtoinou
Copy link
Collaborator Author

madtoinou commented Feb 24, 2023

The pickle issue was also occurring for trend=exp since it was also relying on a lambda function. Created helper function for all 3 cases. I had to store the trend_coefficients in the model itself in order to have a clean exponential detrending function. Let me know if there is a better way to implement such functionality.

Noticed that the save/load cycle was not tested on all models, I don't know if we want to change this? I manually checked all the local models, it seems like FFT was the only one causing pickling issues anyway.

Copy link
Collaborator

@dennisbader dennisbader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks a lot!
Just added the Callable for better interpretability

darts/models/forecasting/fft.py Outdated Show resolved Hide resolved
@madtoinou madtoinou merged commit 803d851 into master Feb 28, 2023
@madtoinou madtoinou deleted the fix/pickle_lambda branch February 28, 2023 15:25
alexcolpitts96 pushed a commit to alexcolpitts96/darts that referenced this pull request May 31, 2023
…t8co#1594)

* fix: replacing lambda with named function to make model pickable

* fix: issue was also occurring with the exponential de-trending function

* fix: adding typing

* fix: linting

---------

Co-authored-by: Dennis Bader <dennis.bader@gmx.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Calling save() after fit() throw pickle error for FFT models
3 participants