Skip to content

test: pin PatchTSTModel time-features shape with num_feat_dynamic_real>0 (#3296 item 6) - #3300

Open
jbbqqf wants to merge 1 commit into
awslabs:devfrom
jbbqqf:feat/3296b-patch-tst-time-feat-test
Open

test: pin PatchTSTModel time-features shape with num_feat_dynamic_real>0 (#3296 item 6)#3300
jbbqqf wants to merge 1 commit into
awslabs:devfrom
jbbqqf:feat/3296b-patch-tst-time-feat-test

Conversation

@jbbqqf

@jbbqqf jbbqqf commented May 9, 2026

Copy link
Copy Markdown
Contributor

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:

#3167 — PatchTST time features: no test asserting shape/ordering of past_time_feat/future_time_feat when num_feat_dynamic_real > 0. Current tests keep it at the default 0.

Concretely, test/torch/model/test_modules.py::test_module_smoke covers 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 setting num_feat_dynamic_real, so the if self.num_feat_dynamic_real > 0 branch in PatchTSTModel.describe_inputs and PatchTSTModel.forward (src/gluonts/torch/model/patch_tst/module.py:173, 228) is never exercised by pytest.

Changes

  • test/torch/model/test_modules.py: add test_PatchTSTModel_time_features_shape, parametrized over num_feat_dynamic_real ∈ {1, 3}, that:
    • Constructs PatchTSTModel with explicit time-feature support (small d_model=8, nhead=2, num_encoder_layers=1 to keep the test fast).
    • Asserts describe_inputs() emits past_time_feat of shape (batch, context_length, num_feat_dynamic_real) and future_time_feat of shape (batch, prediction_length, num_feat_dynamic_real).
    • Runs a forward pass on the spec'd zeros and asserts distr_args / loc / scale shapes are sane (this catches a regression in either the take_last+unfold patching of time features or the cat([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)

git clone https://github.com/awslabs/gluonts.git /tmp/repro && cd /tmp/repro
python3.11 -m venv .venv && source .venv/bin/activate
pip install -e . pytest torch lightning scipy cpflows

# --- BEFORE (origin/dev) ---
git checkout origin/dev
pytest test/torch/model/test_modules.py -q -k PatchTST
# Expected: 0 tests collected — PatchTST is not in test_modules.py.

# --- AFTER (this PR) ---
git fetch https://github.com/jbbqqf/gluonts.git feat/3296b-patch-tst-time-feat-test
git checkout FETCH_HEAD
pytest test/torch/model/test_modules.py -q -k PatchTST
# Expected: 2 passed — both num_feat_dynamic_real values pinned.

What I ran locally

  • pytest test/torch/model/test_modules.py -q6 passed in 14s on the branch (was 4 on dev; +2 from this PR).
  • pytest test/torch/model/test_modules.py -q -k PatchTST2 passed.

Edge cases tested

# Scenario Input Expected Verified by
1 Single dynamic feature num_feat_dynamic_real=1 past_time_feat.shape = (batch, context_length, 1), future_time_feat.shape = (batch, prediction_length, 1), forward returns sane shapes test_PatchTSTModel_time_features_shape[1]
2 Multiple dynamic features num_feat_dynamic_real=3 last dim of both time-feat inputs is 3; forward pass succeeds test_PatchTSTModel_time_features_shape[3]

Risk / blast radius

Test-only addition. No runtime change.

Release note

NONE

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.

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
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.

1 participant