Skip to content

[BUG] Fix test errors for pytorch-forecasting estimators#10415

Merged
fkiraly merged 26 commits into
sktime:mainfrom
CloseChoice:ptf-bug-fix
Jun 27, 2026
Merged

[BUG] Fix test errors for pytorch-forecasting estimators#10415
fkiraly merged 26 commits into
sktime:mainfrom
CloseChoice:ptf-bug-fix

Conversation

@CloseChoice

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

reconciles the prs ##10412 and #10383

What does this implement/fix? Explain your changes.

Does your contribution introduce a new dependency? If yes, which one?

What should a reviewer concentrate their feedback on?

Did you add any tests for the change?

Any other comments?

PR checklist

For all contributions
  • I've added myself to the list of contributors with any new badges I've earned :-)
    How to: add yourself to the all-contributors file in the sktime root directory (not the CONTRIBUTORS.md). Common badges: code - fixing a bug, or adding code logic. doc - writing or improving documentation or docstrings. bug - reporting or diagnosing a bug (get this plus code if you also fixed the bug in the PR).maintenance - CI, test framework, release.
    See here for full badge reference
  • Optionally, for added estimators: I've added myself and possibly to the maintainers tag - do this if you want to become the owner or maintainer of an estimator you added.
    See here for further details on the algorithm maintainer role.
  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG]. [BUG] - bugfix, [MNT] - CI, test framework, [ENH] - adding or improving code, [DOC] - writing or improving documentation or docstrings.
For new estimators
  • I've added the estimator to the API reference - in docs/source/api_reference/taskname.rst, follow the pattern.
  • I've added one or more illustrative usage examples to the docstring, in a pydocstyle compliant Examples section.
  • If the estimator relies on a soft dependency, I've set the python_dependencies tag and ensured
    dependency isolation, see the estimator dependencies guide.

@CloseChoice CloseChoice left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just some notes for me. Want to see the CI output before doing more changes though.

Comment thread sktime/tests/test_all_estimators.py Outdated
test_fun(**deepcopy(args))
results[key] = "PASSED"
print_if_verbose("PASSED")
results[key] = "PASSED"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

probably not wanted!

random_log_path: bool (default=False)
use random root directory for logging. This parameter is for CI test in
Github action, not designed for end users.
model_params : dict[str, Any] (default=None)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we should reset this!

# -----------------
"tests:core": True, # should tests be triggered by framework changes?
"tests:skip_all": True,
# the fitted pytorch-forecasting model caches a function-local class

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we are going to skip these tests, why not move them to the _PytorchForecastingAdapter? That would save us from copying it to each and every class, and the test-suite would always skip these tests for all pytorch-forecasting models?
Although not sure if this is a "safe" way to add skips as it would lie in one layer above the end point

@phoeenniixx

Copy link
Copy Markdown
Member

I think we should have some substitute for these saving tests where we check for torch ckpts rather than the pkl file

@phoeenniixx

phoeenniixx commented Jun 16, 2026

Copy link
Copy Markdown
Member

Also, I am surprised why NHiTS and NBEATS is still failing test_fit_idempotent and test_non_state_changing_method_contract?
I thought #10412 solved them. Will look into it

@CloseChoice

Copy link
Copy Markdown
Contributor Author

I think we should have some substitute for these saving tests where we check for torch ckpts rather than the pkl file

I agree, though would postpone this to later.

@phoeenniixx phoeenniixx added bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting module:deep-learning&networks neural network module - layers, network templates labels Jun 22, 2026
CloseChoice and others added 5 commits June 23, 2026 14:39
…pter

_origin_time_idx is a transient lookup (internal int time_idx -> original
index, filtered to the prediction window) built in _Xy_to_dataset. It was
stored on self and re-assigned on every fit/predict call, so predict changed
the estimator __dict__ (training window vs prediction window), tripping
test_non_state_changing_method_contract.

Thread it through as a return value of _Xy_to_dataset and an argument to
_predictions_to_dataframe instead of storing it on self. _fit discards it.
This removes the instance mutation entirely rather than backing up/restoring
a value that is never read across calls.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@fkiraly fkiraly changed the title Fix test errors for pytorch-forecasting [BUG] Fix test errors for pytorch-forecasting estimators Jun 27, 2026
@fkiraly
fkiraly marked this pull request as ready for review June 27, 2026 12:09
Copilot AI review requested due to automatic review settings June 27, 2026 12:09
@fkiraly
fkiraly merged commit 2a6b898 into sktime:main Jun 27, 2026
3 of 4 checks passed
@github-project-automation github-project-automation Bot moved this to Fixed/resolved in Bugfixing Jun 27, 2026

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.

Pull request overview

This PR aims to resolve failing tests for the pytorch-forecasting-based forecasters in sktime, primarily by improving test determinism/reproducibility and by skipping persistence-related estimator tests that are incompatible with the underlying model objects.

Changes:

  • Add a deterministic option to pytorch-forecasting forecasters and set it in test params to stabilize test outcomes.
  • Adjust the pytorch-forecasting adapter to handle loss/callbacks separately and to avoid estimator state mutation during prediction by returning transient index lookup data.
  • Skip pickling/persistence tests for these estimators and ignore model checkpoint directories in git.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 6 comments.

File Description
sktime/forecasting/pytorchforecasting.py Adds deterministic parameter, updates doctest directives, and tags persistence-related tests to be skipped for pytorch-forecasting estimators.
sktime/forecasting/base/adapters/_pytorchforecasting.py Refactors adapter internals for loss/callback handling, deterministic seeding, and non-state-mutating prediction indexing.
.gitignore Ignores checkpoints/ directory to prevent accidental commits of model artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +118 to 123
self._model_loss = model_params.pop("loss", None) if model_params else None
self._model_params = deepcopy(model_params) if model_params else {}
self._callbacks = trainer_params.pop("callbacks", None)
self._trainer_params = (
deepcopy(trainer_params) if trainer_params is not None else {}
)
# if fh is not continuous, there will be NaN after extend_y in prediect
data = data.copy()
data["_target_column"] = data["_target_column"].fillna(0)
data["_target_column"] = data["_target_column"].fillna(0) # .astype(float)
Comment on lines +38 to +39
deterministic: bool (default=False)
set seed before predict, so that it will give the same output for the same input
Comment on lines +339 to +340
deterministic: bool (default=False)
set seed before predict, so that it will give the same output for the same input
Comment on lines +932 to +938
deterministic: bool (default=False)
set seed before predict, so that it will give the same output for the same input
random_log_path: bool (default=False)
use random root directory for logging. This parameter is for CI test in
Github action, not designed for end users.
deterministic: bool (default=False)
set seed before predict, so that it will give the same output for the same input
Comment on lines 1043 to 1055
@@ -1008,6 +1051,7 @@ def __init__(
random_log_path,
broadcasting,
)
self.deterministic = deterministic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working module:deep-learning&networks neural network module - layers, network templates module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting

Projects

Status: Fixed/resolved

Development

Successfully merging this pull request may close these issues.

5 participants