Skill Tracer
Skills › Scientific Agent Skills › timesfm-forecasting › performance_tuning.md

performance_tuning.md

27 lines · skills/timesfm-forecasting/references/performance_tuning.md at 5f2bc03

Open on GitHub
1# Tune the actual workload
2
3Start with `per_core_batch_size=1`, a context such as 512 and a horizon rounded
4to 128. Record wall time and peak resident/device memory for representative
5lengths before increasing batch size. No table can guarantee a batch size from
6VRAM alone: contexts, horizon, copies, backend, compiler and concurrent work matter.
7
8The 2.5 `torch_compile` loader option defaults True. Use False for first-load
9smokes; separately benchmark whether compilation pays off for repeated calls.
10`model.compile(ForecastConfig(...))` is still needed with either setting.
11The continuous quantile head supports <=1,024 horizon. Symmetric flip averaging
12adds a second decode pass. Reduce context only after evaluating its accuracy cost.
14For CUDA float32 matmul, `torch.set_float32_matmul_precision("high")` can trade
15internal precision for speed on supported hardware; it is not a universal
16accuracy-preserving setting and does not make CPU/MPS use CUDA. Use
17`torch.cuda.get_device_properties(0).total_memory`, not `.total_mem`.
19Process many series in outer chunks if input/output arrays are large; persist
20outputs as you go instead of retaining every array. Passing a copied list avoids
212.5's in-place padding-list growth. `gc.collect()` or `torch.cuda.empty_cache()`
22does not free live model tensors or fix an oversized workload. After OOM,
23reduce the actual context/batch/horizon allocation and rerun the representative
24smoke, then reassess forecast quality.
26Backend details: [TimesFM torch source](https://github.com/google-research/timesfm/blob/e51928e27119cb17bebc005be2696b75e0a9e688/src/timesfm/timesfm_2p5/timesfm_2p5_torch.py),
27[PyTorch precision API](https://docs.pytorch.org/docs/stable/generated/torch.set_float32_matmul_precision.html).

Tune the actual workload

Start with per_core_batch_size=1, a context such as 512 and a horizon rounded to 128. Record wall time and peak resident/device memory for representative lengths before increasing batch size. No table can guarantee a batch size from VRAM alone: contexts, horizon, copies, backend, compiler and concurrent work matter.

The 2.5 torch_compile loader option defaults True. Use False for first-load smokes; separately benchmark whether compilation pays off for repeated calls. model.compile(ForecastConfig(...)) is still needed with either setting. The continuous quantile head supports <=1,024 horizon. Symmetric flip averaging adds a second decode pass. Reduce context only after evaluating its accuracy cost.

For CUDA float32 matmul, torch.set_float32_matmul_precision("high") can trade internal precision for speed on supported hardware; it is not a universal accuracy-preserving setting and does not make CPU/MPS use CUDA. Use torch.cuda.get_device_properties(0).total_memory, not .total_mem.

Process many series in outer chunks if input/output arrays are large; persist outputs as you go instead of retaining every array. Passing a copied list avoids 2.5's in-place padding-list growth. gc.collect() or torch.cuda.empty_cache() does not free live model tensors or fix an oversized workload. After OOM, reduce the actual context/batch/horizon allocation and rerun the representative smoke, then reassess forecast quality.

Backend details: TimesFM torch source, PyTorch precision API.

Raw lines 1 to 27