Repository navigation
[BUG] keep a validation series when the v2 split rounds it to zero - #2479
Open
Chetansahney wants to merge 1 commit into
Open
Chetansahney wants to merge 1 commit into
Chetansahney wants to merge 1 commit into
Conversation
`_ensure_split` sizes train and validation with `int()`, so with the default (0.7, 0.15, 0.15) split any dataset with 3 to 6 series got no validation series. No validation ran, and the default `val_loss` checkpoint in `Base_pkg.fit` was never written. When validation rounds to zero, take one series from the test remainder, which holds the rounding surplus, or from train when test cannot spare one. Splits that already give validation a series are unchanged.
Chetansahney
requested review from
benHeid,
fkiraly,
jdb78 and
phoeenniixx
as code owners
October 25, 2026 07:37
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v2-dev #2479 +/- ##
=========================================
Coverage ? 88.06%
=========================================
Files ? 203
Lines ? 11394
Branches ? 0
=========================================
Hits ? 10034
Misses ? 1360
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:
|
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
No existing issue. The shared split came to
BaseTimeSeriesDataModulein #2423.Related: #2087 (open, against
main) moves splitting intocompute_split_boundaries, which rounds instead of truncating. With the default split that still gives 3 series no validation series, and gives 4 or 5 series no test series, so the same guard applies there. Happy to carry it over when #2087 andv2-devmeet.What does this implement/fix? Explain your changes.
BaseTimeSeriesDataModule._ensure_splitsizes the train and validation sets withint(). With the default(0.7, 0.15, 0.15),int(0.15 * n)is 0 for any dataset with 3 to 6 series, so validation gets no series, while 1 and 2 series are special-cased and do get one:With an empty validation set Lightning skips validation without a warning, so the default
ModelCheckpoint(monitor="val_loss")inBase_pkg.fit()never saves anything. FittingDecoderMLP_pkg_v2on 4 series, the size of the v2 test data, logs onlytrain_loss, andfit()returnsPath(".")as the best checkpoint. The(0.8, 0.2)split the v2 test suite uses behaves the same way.When validation rounds to zero, this takes one series from the test remainder, which holds the rounding surplus, or from train when test cannot spare one; test keeps at least one series whenever its fraction is positive. Splits that already give validation a series are unchanged, so with the default split, datasets with 7 or more series are split exactly as before.
What should a reviewer concentrate their feedback on?
2 / 1 / 1is closer to0.7 / 0.15 / 0.15than taking it from train, which would give1 / 1 / 2.(0.8, 0.2)has no test fraction, so test can give up its last series: 4 series split3 / 1 / 0.Did you add any tests for the change?
test_few_series_split_keeps_validationintests/test_data/test_data_module.pychecks the exact split sizes for 3 to 7 series and for(0.8, 0.2), for bothEncoderDecoderTimeSeriesDataModuleandTslibDataModule, that every series lands in exactly one split, and that the validation dataset is not empty. 10 of the 12 cases fail before the change; the two 7-series cases, which already had a validation series, pass both ways.tests/test_dataand the full v2 estimator suite inpytorch_forecasting/tests/test_all_v2(240 tests) pass. The v2 test data has 4 series, so those integration tests now run validation, which they did not before.Any other comments?
Three related things I noticed and left out of this PR:
Base_pkg.fit()returnsPath(checkpoint_cb.best_model_path), which isPath("."), and_save_artifactthen writesdatamodule_cfg.pkl,model_cfg.pklandmetadata.pklinto the current working directory. [ENH] Addforecastersupport and remove_pkgclass for new API #2434 and [ENH] Add minimal vignette tests for v2 design and fix default datamodule compatibility #2475 both rework_base_pkg.py, so I did not touch it here.test_integrationwrites it to./checkpoints(gitignored), because_integrationcallspkg.fit()with the default relativeckpt_dir. Passingckpt_dir=tmp_pathwould keep it in the test's temp directory;_test_integration.pyis also being changed in [ENH] Add minimal vignette tests for v2 design and fix default datamodule compatibility #2475.pytorch_forecasting/data/tests/test_tslib_data_module.pyfails 14 of 14 onv2-dev: it still passestime_series_dataset=, which &Faakhir30 [ENH] Update Datamodules according to new API design #2423 renamed totime_series=. CI does not collectpytorch_forecasting/data/tests(see [MNT] run in-package test folders in CI, fixtest_multivariate_target#2478), which is why this went unnoticed. Happy to update it in a follow-up.PR checklist