feat: add support for T0 (theforecastingcompany/t0-alpha)#350
Closed
GeoffNN wants to merge 2 commits into
Closed
Conversation
Adds The Forecasting Company's open-weights T0 foundation model as a foundation forecaster, via the tfc-t0 package (Python 3.11–3.13). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Regenerated after tfc-t0 0.1.2 (metadata-only floor relaxation) was published to PyPI. Resolves to tfc-t0 0.1.2 + einops 0.7.0 + jaxtyping 0.2.38 — the combo the T0 adapter is verified against. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Closing — keeping the original #348 from the personal fork, where a contributor already has a PR open. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for The Forecasting Company’s T0 foundation model to TimeCopilot, including dependency wiring, documentation, and import/version gating.
Changes:
- Introduces
T0forecaster implementation with quantile/interval output support. - Adds
tfc-t0dependency and Python-version-based import/test gating. - Updates model hub and API docs to list T0.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| timecopilot/models/foundation/t0.py | New T0 forecaster implementation and Python version guard |
| tests/models/test_models.py | Adds test ensuring import fails on unsupported Python versions |
| tests/models/conftest.py | Registers T0 in the model test matrix for supported Python versions |
| pyproject.toml | Adds tfc-t0 dependency with Python version markers |
| docs/model-hub.md | Lists T0 in the model hub |
| docs/api/models/foundation/models.md | Exposes T0 in generated API docs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+93
to
+95
| finally: | ||
| del model | ||
| torch.cuda.empty_cache() |
Comment on lines
+89
to
+90
| def _get_model(self) -> T0Forecaster: | ||
| model = T0Forecaster.from_pretrained(self.repo_id).to(self.device).eval() |
Comment on lines
+103
to
+111
| context = torch.full( | ||
| (len(batch), max_len), | ||
| float("nan"), | ||
| dtype=torch.float32, | ||
| ) | ||
| for idx, ts in enumerate(batch): | ||
| ts = ts[-max_len:] | ||
| context[idx, -len(ts) :] = ts.to(dtype=torch.float32) | ||
| return context |
Comment on lines
+179
to
+183
| out = model.predict( | ||
| self._to_context(batch), | ||
| horizon=h, | ||
| quantiles=pred_quantiles, | ||
| ) |
Comment on lines
+187
to
+192
| fcst_df[self.alias] = fcsts_np[..., median_idx].reshape(-1, 1) | ||
| if qc.quantiles is not None: | ||
| for q in qc.quantiles: | ||
| fcst_df[f"{self.alias}-q-{int(q * 100)}"] = fcsts_np[ | ||
| ..., pred_quantiles.index(q) | ||
| ].reshape(-1, 1) |
Comment on lines
+88
to
+95
| @contextmanager | ||
| def _get_model(self) -> T0Forecaster: | ||
| model = T0Forecaster.from_pretrained(self.repo_id).to(self.device).eval() | ||
| try: | ||
| yield model | ||
| finally: | ||
| del model | ||
| torch.cuda.empty_cache() |
Comment on lines
+113
to
+120
| def forecast( | ||
| self, | ||
| df: pd.DataFrame, | ||
| h: int, | ||
| freq: str | None = None, | ||
| level: list[int | float] | None = None, | ||
| quantiles: list[float] | None = None, | ||
| ) -> pd.DataFrame: |
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.
Summary
Adds T0, The Forecasting Company's open-weights time series foundation model, as a new foundation forecaster. T0 (
t0-alpha, ~102M params, Apache-2.0) is a decoder-style patch transformer producing probabilistic multi-horizon quantile forecasts — currently #1 on the fev-bench leaderboard (skill score 42.2) and CRPS 0.4941 on GIFT-Eval.(Disclosure: I work at The Forecasting Company.)
Changes
timecopilot/models/foundation/t0.py—T0forecaster wrapping thetfc-t0package, following the existing foundation-model pattern (_get_modelcontext manager,TimeSeriesDatasetbatching,QuantileConverterfor levels/quantiles). The model predicts 5 quantile knots and interpolates arbitrary requested levels in a single forward pass; the median is the point forecast. Ragged batches are left-padded with NaN, which T0 treats as missing.pyproject.toml—tfc-t0>=0.1.2for Python 3.11–3.13 (the package's supported range), mirroring the TiRex/uni2ts marker pattern.tests/models/conftest.py—T0(context_length=256, batch_size=2)added to the model matrix under a version guard, plus atest_t0_import_failsguard test mirroring TiRex/Sundial.Validation
Run locally on macOS / Python 3.12. The lock resolves to
tfc-t0 0.1.2 + einops 0.7.0 + jaxtyping 0.2.38:forecastwith defaults,quantiles=[0.1, 0.5, 0.9], andlevel=[80]on multi-series daily data: correct columns, finite values, monotone quantiles, median == point forecast.cross_validation(df, h=6): correct shape and columns.uv run pytest tests/models/test_models.py::test_t0_import_fails(skips on 3.11–3.13, asserts ImportError outside).ruff check+ruff format --checkpass on the new/changed files.Note
tfc-t00.1.2 (the version this depends on) is published to PyPI;uv.lockis regenerated and committed. Ready for review.🤖 Generated with Claude Code