Skip to content

Fix predict() silently falling back to the training series after fit(val_series) - #3279

Closed
XXXXXQ-0206 wants to merge 2 commits into
unit8co:masterfrom
XXXXXQ-0206:fix-predict-val-series-warning
Closed

XXXXXQ-0206 wants to merge 2 commits into
unit8co:masterfrom
XXXXXQ-0206:fix-predict-val-series-warning

Conversation

@XXXXXQ-0206

@XXXXXQ-0206 XXXXXQ-0206 commented Oct 16, 2026 •

Copy link
Copy Markdown

predict() without series falls back to training_series (documented in the docstring). After fit(train, val_series=val) where val continues train, that fallback excludes the validation part, so the forecast restarts inside the validation period - silently.

Reproduction (0.48.1, master dcdde24, CPU):

train, val = series[:70], series[70:]
model.fit(train, val_series=val)
model.predict(n=3).start_time()                 # index 70  == train.end + freq (re-forecasts the val range)
model.predict(n=3, series=series).start_time()  # index 100 == val.end + freq

This PR keeps the fallback and the returned start point unchanged (documented behaviour others rely on) and only makes it visible: fit() records whether a val_series reached beyond training_series, and predict() warns when it falls back, naming the training series, the resulting start and how to avoid it. The flag is recorded before the model is saved during fit(), so it also survives save()/load() and load_from_checkpoint(). A val_series inside the training series, a fit() without val_series, explicit series=..., historical_forecasts() and backtest() are unaffected.

Test: test_predict_without_series_warns_when_fitted_with_val_series (no val_series / extending it / equal to it).

Verification (local, CPU torch 2.14.1): new test: 3 cases pass; with torch_forecasting_model.py restored to base they fail (1 failed, 2 passed); the full test file 363 passed; pre-commit passes.

AI disclosure: prepared with AI assistance under the account owner's direction; reproduction, tests and verification commands were run locally, outputs quoted verbatim.

Fixes #3278

Copilot AI balanced review requested due to automatic review settings October 16, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@XXXXXQ-0206
XXXXXQ-0206 force-pushed the fix-predict-val-series-warning branch from 66f65d2 to 2d176ce Compare October 24, 2026 04:30
@dennisbader

Copy link
Copy Markdown
Collaborator

Thanks for the PR @XXXXXQ-0206. I'll close this PR with the answer I gave here.

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.

[IMPROVEMENT] Warn when TorchForecastingModel.predict(series=None) is called after fit(series, val_series=...) where val_series follows series

3 participants