test: pin PatchTSTModel time-features shape with num_feat_dynamic_real>0 (#3296 item 6) - #3300
Open
jbbqqf wants to merge 1 commit into
Open
test: pin PatchTSTModel time-features shape with num_feat_dynamic_real>0 (#3296 item 6)#3300jbbqqf wants to merge 1 commit into
jbbqqf wants to merge 1 commit into
Conversation
awslabs#3167 added num_feat_dynamic_real support to PatchTST, threading extra real-valued time features through past_time_feat / future_time_feat. The existing test_module_smoke parametrize only exercises modules at num_feat_dynamic_real=0, so the time-feature branch is not pinned — flagged as item 6 of the umbrella regression-test gap issue awslabs#3296. Add a parametrized test (num_feat_dynamic_real in {1, 3}) that: - Asserts describe_inputs() emits past_time_feat / future_time_feat keys with shapes (batch, length, num_feat_dynamic_real). Pins the layout so a refactor of the InputSpec doesn't silently change the contract. - Runs a forward pass on the spec'd zeros and checks distr_args/loc/scale shapes are sane. Catches concatenation / patching mistakes in the time-feature branch of forward(). Refs awslabs#3296
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.
Issue #, if available: refs #3296 (item 6)
Description of changes:
Summary
Add a regression test pinning
PatchTSTModel's time-features branch (num_feat_dynamic_real > 0), introduced by #3167 but not exercised by the existing module-level test suite.Context
#3296 enumerates regression-test gaps left by recent merged PRs. Item 6:
Concretely,
test/torch/model/test_modules.py::test_module_smokecovers DeepAR, MQF2, SimpleFeedForward, and TFT, but PatchTST is absent and the only PatchTST tests in the suite (test/torch/model/test_estimators.py) construct estimators without settingnum_feat_dynamic_real, so theif self.num_feat_dynamic_real > 0branch inPatchTSTModel.describe_inputsandPatchTSTModel.forward(src/gluonts/torch/model/patch_tst/module.py:173, 228) is never exercised by pytest.Changes
test/torch/model/test_modules.py: addtest_PatchTSTModel_time_features_shape, parametrized overnum_feat_dynamic_real ∈ {1, 3}, that:PatchTSTModelwith explicit time-feature support (smalld_model=8,nhead=2,num_encoder_layers=1to keep the test fast).describe_inputs()emitspast_time_featof shape(batch, context_length, num_feat_dynamic_real)andfuture_time_featof shape(batch, prediction_length, num_feat_dynamic_real).distr_args/loc/scaleshapes are sane (this catches a regression in either thetake_last+unfoldpatching of time features or thecat([inputs, time_feat_patches], dim=-1)projection alignment).A short docstring on the test cites #3167 and #3296 so a reviewer reading the test cold sees what regression it guards.
Reproduce BEFORE/AFTER yourself (copy-paste)
What I ran locally
pytest test/torch/model/test_modules.py -q→ 6 passed in 14s on the branch (was 4 on dev; +2 from this PR).pytest test/torch/model/test_modules.py -q -k PatchTST→ 2 passed.Edge cases tested
num_feat_dynamic_real=1past_time_feat.shape = (batch, context_length, 1),future_time_feat.shape = (batch, prediction_length, 1), forward returns sane shapestest_PatchTSTModel_time_features_shape[1]num_feat_dynamic_real=3test_PatchTSTModel_time_features_shape[3]Risk / blast radius
Test-only addition. No runtime change.
Release note
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Please tag this pr with at least one of these labels to make our release process faster: BREAKING, new feature, bug fix, other change, dev setup
PR drafted with assistance from Claude Code. The reproducer block above was used during development and is the same one a reviewer can paste verbatim.