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

[BUG] Calling save() after fit() throw pickle error for FFT models #1587

Closed
fabioprocaci opened this issue Feb 22, 2023 · 1 comment · Fixed by #1594
Closed

[BUG] Calling save() after fit() throw pickle error for FFT models #1587

fabioprocaci opened this issue Feb 22, 2023 · 1 comment · Fixed by #1594
Labels
bug Something isn't working

Comments

@fabioprocaci
Copy link

fabioprocaci commented Feb 22, 2023

Describe the bug
save() method does not work after fit() method in some cases.
AttributeError: Can't pickle local object 'FFT.fit.<locals>.<lambda>'

To Reproduce

from darts.datasets import EnergyDataset
from darts.dataprocessing.transformers import Scaler, MissingValuesFiller



df = EnergyDataset().load().pd_dataframe()
df_day_avg = df.groupby(df.index.astype(str).str.split(" ").str[0]).mean().reset_index()
filler = MissingValuesFiller()
scaler = Scaler()
series = scaler.fit_transform(
    filler.transform(
        TimeSeries.from_dataframe(
            df_day_avg, "time", ["generation hydro run-of-river and poundage"]
        )
    )
).astype(np.float32)



train, val = series.split_after(pd.Timestamp("20170901"))


model = FFT(nr_freqs_to_keep=2, trend='linear', trend_poly_degree=2)
model.fit(train)


model.save('test.pht')

Expected behavior

The model should be saved properly as test.pht

System (please complete the following information):

  • Python version: 3.7.13
  • darts version 0.23.1

Additional context

In another code a co-worker got a similar error :
AttributeError: Can't pickle local object 'EvaluationLoop.advance.<locals>.batch_to_device'

It was trying model.save() method after fitting a TFTModel. I couldn't reproduce the error on my machine though ...

@fabioprocaci fabioprocaci added bug Something isn't working triage Issue waiting for triaging labels Feb 22, 2023
@madtoinou madtoinou changed the title [BUG] [BUG] Calling save() after fit() throw pickle error for FFT models Feb 22, 2023
@madtoinou
Copy link
Collaborator

madtoinou commented Feb 22, 2023

Hi,

After a quick investigation, it appears that "linear" is not a supported value for the trend argument of FTT.fit(). If you replace it by "poly" or "exp", the save() method works just fine. For your example more specifically, trend="poly" trend_poly_degree=1 should result in a linear trend function.

The error seems to be linked to the trend_function being lambda x : 0 when trend is anything but "poly" or "exp", not sure of how to solve it atm...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants