TimesFM-3 MLX
A pure-MLX port of Google Research's TimesFM-3, a 330M-parameter foundation model for time-series forecasting. Runs natively on Apple Silicon with no PyTorch dependency, and matches the official reference implementation to ~1e-6.
Features
- Complete — multivariate targets, past-only and past-future covariates, arbitrary context length.
- Standalone — depends only on
mlxand the.safetensorsweights. No PyTorch install. - Faithful — ~1e-6 relative error vs the official PyTorch reference on every tested configuration.
Installation
pip install hskyto-timesfm-mlx
(mlx and huggingface-hub are pulled in automatically. The model weights are
downloaded and cached on first use.)
Or from source:
git clone https://github.com/Hemeskyo/TimesFM-3-MLX && cd TimesFM-3-MLX && pip install -e .
Usage
from timesfm_mlx import load_weights, forecast
weights = load_weights() # downloads from Hugging Face (cached) on first call
out = forecast(series, horizon=64, weights=weights) # (horizon, 9): 9 quantiles per step
median = out[:, 4] # column 4 = median forecast
For multivariate targets or covariates, use decode directly:
from timesfm_mlx import decode
# target: (b, num_target, context) ; optional past_only_/past_future_covariates
out = decode(target, horizon, weights,
past_only_covariates=po, past_future_covariates=pf) # (b, v, horizon, 9)
Weights are fetched from google/timesfm-3.0-pytorch automatically. To use a local file instead: load_weights("path/to/model.safetensors").
Architecture
Time series are split into patches (32 steps = one token). TimesFM-3 is multivariate: tokens form a 2-D grid (series × time) and each layer attends on both axes.
raw series
→ preprocessing: running-stats RevIN + linear detrending + patching + stitching
→ pre_transformer_resblock (patch 192 → token 1280)
→ 20 × MixingTransformer (seq attention over TIME + var attention over SERIES + FFN)
→ output_head (1280 → 64 horizon steps × 9 quantiles)
→ reverse RevIN / re-trend
→ forecast + quantiles
Each MixingTransformer layer runs seq_attn across time (causal, RoPE) and var_attn across series (no RoPE, non-causal), each wrapped as post_norm(sublayer(pre_norm(h))) + h.
Validation
Every block is checked against the PyTorch reference (relative error):
| Block | rel. error |
|---|---|
| rms_norm · linear · per_dim_scale · rope | ~1e-6 |
| attention (seq) · var_attn · feed_forward | ~1e-6 |
| MixingTransformer layer · transformer_stack (20) | ~1e-6 |
| resblock · output_head | ~1e-6 |
| end-to-end decode (any context · past-only · past-future · both) | ~1e-6 |
Run the parity suite: PYTHONPATH=. python parities/parity.py.
Project structure
timesfm_mlx/
tfm_mlx.py — transformer blocks: rms_norm, linear, per_dim_scale, rope,
attention (seq/var), feed_forward, mixing_layer, transformer_stack,
resblock, output_head
tfm_decode.py — preprocessing + decode + load_weights + forecast
__init__.py — public API
parities/ — parity tests against the PyTorch reference
experiments/ — usage demos
License
Code: MIT. The TimesFM-3 weights are distributed by Google under the timesfm-non-commercial-license-v1.0 (research / non-commercial only) and are not included here — download them from Hugging Face.
Reference: google/timesfm-3.0-pytorch · arXiv:2310.10688.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hskyto_timesfm_mlx-0.1.2.tar.gz.
File metadata
- Download URL: hskyto_timesfm_mlx-0.1.2.tar.gz
- Upload date:
- Size: 342.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9d041f63264490513ec4f6f825b11449b85d10e16426fe2fd9e0fe93815bba3
|
|
| MD5 |
0a01cb5e88593d3e2f2f90978d1d9c2c
|
|
| BLAKE2b-256 |
f566770c2d12677246f0fae8bb54cb27dc7d87e1e8be722a8dc00276cac872bf
|
File details
Details for the file hskyto_timesfm_mlx-0.1.2-py3-none-any.whl.
File metadata
- Download URL: hskyto_timesfm_mlx-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19146fa275d9d813b685c71d17a864d045393ddd5c1b646d76e2513660dffb47
|
|
| MD5 |
759596235042ff5ea9ad44d00fc433de
|
|
| BLAKE2b-256 |
7fb2a77ac904a59b821fa1455d11317ed1f2d0aefecf3460d7da40f9e7e8a380
|