Commit dbfd38b
authored
[BUG] Align TimeXer v2 endogenous/exogenous usage with tslib metadata (#2009)
## Summary
This PR makes the TimeXer v2 implementation consistent with the v2 /
`tslib` design by removing the duplicated configuration of endogenous
and exogenous variables inside `TimeXer._forecast`.
Instead of re-selecting series using `self.endogenous_vars` /
`self.exogenous_vars` on top of the `tslib` metadata, the model now
relies solely on the tensors provided by the data pipeline
(`history_target` and `history_cont`).
This implements **option 1** discussed in #2003 ("not overriding or
passing twice").
Fixes #2003
## Motivation / Context
In v2, feature configuration is intended to be described by the
`metadata` produced by `TslibDataModule` and consumed by
`TslibBaseModel`. TimeXer v2 currently has:
- feature names and indices described in `metadata`
- *and* additional `endogenous_vars` / `exogenous_vars` kwargs that are
used in `_forecast` to re-select columns from `history_cont`
This leads to two different places where the endogenous / exogenous
split can be defined, which is exactly the concern raised in #2003.
The maintainers confirmed that option 1 is preferred: relying on the
metadata / data pipeline only, i.e. not overriding or passing the
configuration twice.
## What this PR changes
In `pytorch_forecasting/models/timexer/_timexer_v2.py`:
- `TimeXer._forecast` no longer uses `self.endogenous_vars` or
`self.exogenous_vars` to re-select columns from `history_cont`.
- Instead, the method now follows the v2 convention:
- endogenous information is taken from `history_target`
- exogenous information is taken from all continuous covariates in
`history_cont`
Concretely, the previous block:
```python
# explicitly set endogenous and exogenous variables
endogenous_cont = history_target
if self.endogenous_vars:
endogenous_indices = [
self.feature_names["continuous"].index(var)
for var in self.endogenous_vars
]
endogenous_cont = history_cont[..., endogenous_indices]
exogenous_cont = history_cont
if self.exogenous_vars:
exogenous_indices = [
self.feature_names["continuous"].index(var)
for var in self.exogenous_vars
]
exogenous_cont = history_cont[..., exogenous_indices]
```
is replaced by:
```python
# v2 convention:
# - endogenous information comes from the target history
# - exogenous information comes from all continuous covariates
endogenous_cont = history_target
exogenous_cont = history_cont
```
The rest of `_forecast` (embedding, encoder, head) remains unchanged.
### API / behaviour notes
- The `endogenous_vars` and `exogenous_vars` arguments are still present
in `TimeXer.__init__` and are stored on `self`, but they are no longer
used in `_forecast`.
- This keeps the public signature unchanged for now (no immediate
breaking change), while removing the duplicated configuration path that
conflicted with the v2 metadata design.
- In practice, this means TimeXer v2 now always behaves as if the
endogenous information is given by the target history and the exogenous
information by the continuous covariates provided by `TslibDataModule`.
- If desired, a follow-up PR can deprecate or remove these args entirely
from the public API.
## Tests
On Windows with Python 3.13, I ran:
```bash
python -m pytest -k "TimeXer" -q --basetemp="C:\Projects\pytorch-forecasting\.pytest_tmp"
```
- 75 tests passed
- 1 test skipped
- 0 failures
The failures reported earlier were due to a local Windows permission
issue with the default pytest temp directory; pointing `--basetemp` at a
project-local directory resolved that, and the TimeXer tests now run
cleanly with the change in place.
## Notes
- This PR is intentionally scoped to the functional change in
`_forecast` only.
- I am happy to follow up with a separate PR (or extend this one if
preferred) to:
- deprecate/remove the `endogenous_vars` / `exogenous_vars` kwargs from
`TimeXer.__init__`, and
- update the class docstring and docs accordingly.1 parent 725e0c3 commit dbfd38b
File tree
2 files changed
+5
-30
lines changed- pytorch_forecasting/models/timexer
- tests/test_models
2 files changed
+5
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 67 | | |
74 | 68 | | |
75 | 69 | | |
| |||
83 | 77 | | |
84 | 78 | | |
85 | 79 | | |
86 | | - | |
| 80 | + | |
| 81 | + | |
87 | 82 | | |
88 | 83 | | |
89 | 84 | | |
| |||
118 | 113 | | |
119 | 114 | | |
120 | 115 | | |
121 | | - | |
122 | | - | |
123 | 116 | | |
124 | 117 | | |
125 | 118 | | |
| |||
156 | 149 | | |
157 | 150 | | |
158 | 151 | | |
159 | | - | |
160 | | - | |
161 | 152 | | |
162 | 153 | | |
163 | 154 | | |
| |||
292 | 283 | | |
293 | 284 | | |
294 | 285 | | |
295 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
296 | 289 | | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | 290 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | 291 | | |
312 | 292 | | |
313 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | 338 | | |
342 | 339 | | |
343 | 340 | | |
344 | 341 | | |
345 | | - | |
346 | | - | |
347 | 342 | | |
348 | 343 | | |
349 | 344 | | |
| |||
0 commit comments