[DOC] Update tslib v2 tutorial to use the package (pkg) classes - #2366
Open
echo-xiao wants to merge 4 commits into
Open
[DOC] Update tslib v2 tutorial to use the package (pkg) classes#2366echo-xiao wants to merge 4 commits into
echo-xiao wants to merge 4 commits into
Conversation
Rewrite the tslib v2 example to use the high-level pkg API (TimeXer_pkg_v2 / DLinear_pkg_v2) instead of manually wiring up the datamodule, model and Trainer. - Configure via model_cfg / datamodule_cfg / trainer_cfg + .fit() / .predict() - Add a DLinear example to show the same pipeline with another tslib model - Fix future_known_feature typo in the TimeSeries definition - Fix nhead -> n_heads (the old name was silently swallowed by **kwargs, so the model was running with the default number of heads) - Make context_length divisible by patch_length to drop the 'some time steps will not be used' warning - Remove categorical_encoders, which TslibDataModule does not accept - Note that TimeXer v2 does not yet consume categorical features and that the datamodule does not encode them - Leave logging_metrics off the QuantileLoss variant: point metrics cannot be computed on quantile output and raise an assertion during fit - Use accelerator='cpu' so the small demo is reproducible on any machine
echo-xiao
requested review from
benHeid,
fkiraly,
jdb78 and
phoeenniixx
as code owners
August 1, 2026 23:31
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2366 +/- ##
=======================================
Coverage ? 87.46%
=======================================
Files ? 175
Lines ? 10165
Branches ? 0
=======================================
Hits ? 8891
Misses ? 1274
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
phoeenniixx
requested changes
Aug 3, 2026
phoeenniixx
left a comment
Member
There was a problem hiding this comment.
Nice!
Few suggestions:
- In v2, you can perform the training in two ways - High level API (using
pkgclass) or skipping thepkgclass and creating the data modules, models etc yourself. So, it would be great if we dont remove the 2nd way (which was I think already present?) And instead add this new High level API with it. Although, the cells for usingpkgclass should be BEFORE the cells where we dont use thepkgclass. See the other tutorial to see what I mean! - For the toydataset, you can use the inbuilt method present in
data/examplesfile. See here. - For the note about API being unstable, It would be great if that can be highlighted so that, noone misses that!
- Please in the begining of the tutorial, also add a md cell explaining
tslibmodels are taken fromthumland they are different from the enc-dec models usingEncoderDecoderDataModule.
…thuml/enc-dec note and highlight unstable-API warning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #2353.
What does this implement/fix? Explain your changes.
Updates the v2
tslibtutorial notebook(
docs/source/tutorials/tslib_v2_example.ipynb) to use the high-levelpackage (
pkg) API for v2 models, as requested in #2353. The previousversion wired up the
TslibDataModule, model and LightningTrainerbyhand; the tutorial now drives the whole pipeline through the pkg classes.
Main change:
TimeXer_pkg_v2/DLinear_pkg_v2: configurewith three dicts (
model_cfg/datamodule_cfg/trainer_cfg) and runwith
.fit()/.predict(), instead of manually constructing thedatamodule, model and
Trainer.(
pytorch_forecasting.models.timexer/pytorch_forecasting.models.dlinear).tslib model.
Correctness fixes made while updating the notebook:
future_known_featuretypo in theTimeSeriesdefinition.nhead->n_heads(the old name was silently swallowed by**kwargs, so the model was running with the default number of heads).context_lengthdivisible bypatch_lengthto drop the"some time steps will not be used" warning.
categorical_encoders, whichTslibDataModuledoes not accept.logging_metricsoff theQuantileLossvariant: point metrics(MAE/SMAPE) cannot be computed on quantile output and raise an assertion
during
fit.accelerator="cpu"so the small demo is reproducible on any machine.Clarifying note added to the notebook:
does not encode them (every feature is cast to float and sliced by index).
The
catcolumns are kept in the data definition to show the full API.What should a reviewer concentrate their feedback on?
models (still an experimental / unstable API, see [ENH] Implementing D2 data module, tests and
TimeXermodel fromtslibfor v2 #1836).TimeXer v2 /
TslibDataModulebehavior.models currently built on
TslibBaseModelV2.Did you add any tests for the change?
No — this is a documentation-only change (a tutorial notebook); no library
code is touched. The notebook was executed end-to-end locally and all cells
run without errors. The docs build uses
nbsphinx_execute = "never", so thecommitted outputs are what render.
Any other comments?
While updating the notebook I noticed a stray
print(self.model_cfg)debugstatement in
pytorch_forecasting/base/_base_pkg.pythat fires on every pkgconstruction and leaks into the output (the
{'loss': ...}lines visible inthe notebook). I kept it out of this PR to keep the change documentation-only;
it could be removed in a separate [MNT] PR.
PR checklist