Skip to main content

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 mlx and the .safetensors weights. 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

hskyto_timesfm_mlx-0.1.1.tar.gz (174.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hskyto_timesfm_mlx-0.1.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file hskyto_timesfm_mlx-0.1.1.tar.gz.

File metadata

  • Download URL: hskyto_timesfm_mlx-0.1.1.tar.gz
  • Upload date:
  • Size: 174.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for hskyto_timesfm_mlx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fd03c7e0c9d226cbaf037152845482b8ccc4a2f979fd90a13c133da3695bb58f
MD5 d0c18be649acf4db2121849cfc64e30a
BLAKE2b-256 0e9e72368b160504a647dcb66e1e315ba171bd908fb2ca526a37f3eb3387ffa1

See more details on using hashes here.

File details

Details for the file hskyto_timesfm_mlx-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hskyto_timesfm_mlx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5fed33693a7c82a2335ea6b80ab5af8b1fce27857475f4edb65e3ad966a94218
MD5 b08c6261f84e0d75947d332a4f0729bf
BLAKE2b-256 96b680a34022f855f61a6c419633c30bb5861f36c8d244d8bcb9316387bbbba8

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page