Skip to content

fix(examples): migrate global-temperature animation generator to TimesFM 2.5 - #465

Open
ihubanov wants to merge 1 commit into
google-research:masterfrom
ihubanov:fix/global-temperature-animation-2p5
Open

fix(examples): migrate global-temperature animation generator to TimesFM 2.5#465
ihubanov wants to merge 1 commit into
google-research:masterfrom
ihubanov:fix/global-temperature-animation-2p5

Conversation

@ihubanov

Copy link
Copy Markdown

generate_animation_data.py still uses the v1 API that 2.5 removed, so it dies on the first model load:

AttributeError: module 'timesfm' has no attribute 'TimesFmHparams'

6ed1d8a migrated run_forecast.py and visualize_forecast.py for this example but left this script behind. The GIF and HTML still build only because output/animation_data.json is committed; delete it and the animation cannot be rebuilt.

Changes

  • Load via TimesFM_2p5_200M_torch.from_pretrained + model.compile(ForecastConfig(...)), matching run_forecast.py in the same directory.
  • Pass horizon explicitly to forecast() and drop freq=[0], since 2.5 has no frequency indicator.
  • Fix the quantile column mapping. Column 0 is the mean, so q10/q20/q80/q90 are at 1/2/8/9, not 0/1/7/8.

The quantile bug is visible in the committed output. The band labelled q10 was actually the mean, so it sat above q20:

q10 q20
before 1.2482 1.1407
after 1.1231 1.1614

Verification

Ran the example end to end on CPU (Python 3.13, torch 2.13.0+cpu):

  • All 25 animation steps now give monotonic q10 <= q20 <= q80 <= q90, no NaN.
  • The final step (36 context points, horizon 12) matches run_forecast.py's forecast_output.json exactly on the point forecast and every quantile. That cross-check was impossible before, since the two scripts targeted different model versions.
  • Regenerated animation_data.json and the two artifacts derived from it.

forecast_output.csv, forecast_output.json and forecast_visualization.png are left untouched. Re-running only perturbs them around the 7th decimal, so there is no reason to churn them here.

Not covered here

  • examples/anomaly-detection/detect_anomalies.py has the same v1 API problem.
  • examples/covariates-forecasting/demo_covariates.py is already handled by docs(examples): update covariates demo API snippet to TimesFM 2.5 #445.
  • This example's README.md still documents the v1 API and claims the 2.5 PyTorch checkpoint fails to load, which is no longer accurate.

Happy to fold any of those in if you would prefer a single PR.

Refs #423

…sFM 2.5

generate_animation_data.py was missed by 6ed1d8a, which migrated the rest of
the example. It still calls the removed v1 API and fails on the first model
load:

    AttributeError: module 'timesfm' has no attribute 'TimesFmHparams'

Port it to from_pretrained + ForecastConfig + forecast(horizon=...) and drop
the frequency indicator, which 2.5 removed.

Also correct the quantile column mapping. Index 0 is the mean, so q10/q20/q80
/q90 are at 1/2/8/9, not 0/1/7/8. The old mapping stored the mean in the q10
slot, which left the lower band crossing above q20 in the committed data
(q10=1.2482 > q20=1.1407); it is correctly ordered now (1.1231 < 1.1614).

Regenerate animation_data.json and the two artifacts derived from it.

Refs google-research#423
@google-cla

google-cla Bot commented Aug 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ihubanov

Copy link
Copy Markdown
Author

@googlebot I signed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant