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.

Results

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.

Metadata

Release files for hskyto-timesfm-mlx 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hskyto-timesfm-mlx 0.1.2
File Size Uploaded Provenance
hskyto_timesfm_mlx-0.1.2.tar.gz 342.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hskyto-timesfm-mlx 0.1.2
File Interpreter ABI Platform
hskyto_timesfm_mlx-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 358.6 kB

Release files / hskyto_timesfm_mlx-0.1.2.tar.gz

Download URL hskyto_timesfm_mlx-0.1.2.tar.gz
Size 342.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b9d041f63264490513ec4f6f825b11449b85d10e16426fe2fd9e0fe93815bba3
BLAKE2b-256 checksum
How to use checksums
f566770c2d12677246f0fae8bb54cb27dc7d87e1e8be722a8dc00276cac872bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / hskyto_timesfm_mlx-0.1.2-py3-none-any.whl

Download URL hskyto_timesfm_mlx-0.1.2-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19146fa275d9d813b685c71d17a864d045393ddd5c1b646d76e2513660dffb47
BLAKE2b-256 checksum
How to use checksums
7fb2a77ac904a59b821fa1455d11317ed1f2d0aefecf3460d7da40f9e7e8a380
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for hskyto-timesfm-mlx 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

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