timestral-tune
Fine-tuning, selective LoRA, and conformal calibration for Mistral's Timestral time-series foundation models in PyTorch.
Status: alpha (v0.1). Loading, the data pipeline, all five adaptation modes (
conformal,head_only,lora_variate,lora_temporal,full_ft), anti-forgetting replay mixing and frozen-base distillation (ReplayConfig,SyntheticReplaySource),bf16+torch.compileon CUDA, full Apple GPU coverage (5M–209M, contexts up to32,768), upstream-loadable checkpoint export, raw-space evaluation & forgetting metrics, optional Lacuna integration, and real-dataset benchmarks (5M–209M) are built and verified (14/14 acceptance tests passing). See docs/BENCHMARKS.md and docs/STATUS.md.
What it is
Timestral is Mistral AI's family of time-series foundation models
(5M, 28M, 123M and 209M parameters). The official repository
provides inference only. timestral-tune is an open adaptation toolkit for the released weights,
with a ladder of increasingly invasive options:
| Mode | What changes |
|---|---|
conformal |
Nothing in the model; forecast quantiles are recalibrated after the fact |
head_only |
The quantile head |
lora_variate |
Low-rank adapters on cross-series (variate) attention |
lora_temporal |
Low-rank adapters on temporal attention |
full_ft |
All weights; lower learning rate, or pair with distillation / real-data replay to limit forgetting |
Design goals: reproduce the paper's objective, masks and normalisation exactly and prove it with tests against the official code; export checkpoints that load in the official package; make runs auditable.
The full design is in docs/SPEC.md, which is the project's overview guide and source of truth.
What exists today
| Piece | State |
|---|---|
| Specification | Written and verified against the paper, the official code and the released checkpoints |
| Loading on any device | Done: CUDA, CPU, Apple GPU (5M–209M and contexts up to 32,768, PyTorch 2.8+) |
| Data pipeline | Done: polars / pandas / pyarrow frames, point-in-time windows, time splits, collation |
| Training forward and loss | Done; trimmed covariate layout (L + 2h tokens), equal to official inference (<= 1e-12 fp64) |
| Adaptation modes | Done: head_only (with frozen-feature caching), lora_variate (with single-row guard), lora_temporal, full_ft |
| Anti-forgetting replay & distillation | Done: ReplayConfig, SyntheticReplaySource, distillation_loss (low-VRAM teacher caching & disable_lora) |
| CUDA acceleration | Done: bf16 autocast, fused AdamW, optional torch.compile (verified on NVIDIA L4) |
| Conformal calibration | Done: ConformalCalibrator (CQR) and OnlineConformalCalibrator (ACI) |
| Checkpoint export | Done: upstream-loadable config.json + merged model.safetensors, LoRA adapters, conformal.json, sidecar, LICENSE, NOTICE |
| Benchmarks, metrics, Lacuna integration | Done: utils/metrics.py, integrations/lacuna.py, sweep-backed defaults, 5M–209M tables in docs/BENCHMARKS.md |
| Acceptance tests T1–T14 | All 14 of 14 implemented and passing on tiny, 5M and 28M (CPU, Apple GPU, CUDA) |
| CI | Passing on main (Python 3.10–3.13 on Linux) |
Install
pip install timestral-tune # or: uv add timestral-tune
Requires Python 3.10+ and PyTorch 2.4+ (2.8+ for the Apple GPU). The data layer reads polars, pandas and pyarrow frames, so install whichever you use; none is a dependency. Model weights are downloaded from the Hugging Face Hub on first use, under Mistral AI's licence (see below).
The API may change between 0.x releases; changes are listed in the changelog.
Quick start
from timestral_tune import LoraConfig, TimestralTrainer, TrainingConfig
from timestral_tune.data import TimeSeriesDataset
# A long-format frame: one row per (series, timestamp). polars, pandas and pyarrow all work.
dataset = TimeSeriesDataset.from_polars(
df,
id_col="symbol",
time_col="timestamp",
target_cols=["load"],
past_covariates=["temperature"], # known up to the forecast origin only
known_covariates=["is_holiday"], # known in advance over the horizon
context_length=512,
forecast_horizon=96,
stride=96,
)
train, validation = dataset.split_by_time("2024-02-15") # training sees nothing from this date on
config = TrainingConfig(
model_name_or_path="mistralai/Timestral-5M",
mode="lora_variate",
batch_size=8,
epochs=3,
output_dir="./runs/load-lora",
)
lora = LoraConfig(r=8, lora_alpha=16, axes=("variate",), targets=("q", "v"))
trainer = TimestralTrainer(config, train, validation, lora_config=lora)
print(trainer.evaluate().loss) # zero-shot validation loss
result = trainer.fit() # trains only the variate LoRA adapters
print(result.best_eval_loss)
trainer.export() # writes upstream-loadable merged checkpoint + adapters + NOTICE/LICENSE
Default settings (sign_flip=True, learning rates head_only=3e-3, lora_variate=3e-3,
lora_temporal=1e-3, full_ft=1e-4, and LoRA r=8, targets=("q","k","v","o")) are backed by
Phase 3 validation and forgetting sweeps across 5M–209M in docs/BENCHMARKS.md.
For full_ft on the two smaller checkpoints (5M and 28M), we recommend setting
learning_rate=3e-4: it achieved lower error in our benchmarks (three seeds on 5M, one seed on
28M, where the gain is mainly on volatility), at the cost of roughly two to three percentage
points more forgetting. Keep the 1e-4 default on 123M and 209M, where the two rates tie or
favour 1e-4 on validation and 1e-4 forgets less.
To limit forgetting of the pretrained behaviour, pass a ReplayConfig. Its default adds a light
distillation term that pulls forecasts on built-in synthetic series towards the frozen base model; it
needs no extra data and no labels:
from timestral_tune import ReplayConfig
trainer = TimestralTrainer(config, train, validation, lora_config=lora, replay_config=ReplayConfig())
Measured effects and their limits are in
docs/BENCHMARKS.md §5: it
helped most for head_only, and for full_ft a lower learning rate did as well.
To check your own data for leakage and parity with the official inference path:
from timestral_tune.utils import run_checks
batch = dataset.collator(trainer.model.config)([dataset[i] for i in range(8)]).to(trainer.device)
for check in run_checks(trainer.model, batch):
print(check)
Repository layout
docs/SPEC.md Specification and overview guide (start here)
AGENTS.md How to work in this repo: rules, commands, commit conventions
docs/ Also: status, development log, verification record, upstream and phase notes
src/timestral_tune/ The package (Phases 0-4 built) and the vendored upstream code in _vendor/
tests/ Unit tests and the acceptance tests of spec §9
scripts/ Vendoring, drift check, and verification probes
papers/ Reference papers (only the CC BY Timestral paper is tracked)
assets/ README banner (drawn by scripts/make_banner.py)
archive/ The original draft of the specification
Development
Requires Python 3.10+ and uv.
uv sync # create the environment
uv run pytest # downloads the 5M and 28M checkpoints on first run
uv run pytest -m "not network" # no downloads; what CI runs
uv run ruff check . && uv run ruff format --check .
The verification probes download released checkpoints from the Hugging Face Hub on first use:
uv run python scripts/probes/model_facts.py
uv run python scripts/probes/device_parity.py --device mps # or cuda
More in docs/DEVELOPMENT.md. Contributors and coding agents should read AGENTS.md first.
Licence and important restrictions
- This software is licensed under Apache 2.0. It includes a vendored copy of Mistral AI's
Apache-2.0
timestralpackage; see NOTICE. - Timestral model weights are not covered by Apache 2.0. They are downloaded from the Hugging Face Hub under Mistral AI's Modified MIT License. That licence grants no rights to anyone whose company (or employer) had global consolidated revenue above $20 million in the preceding month, and it applies to derivatives and modifications. Weights fine-tuned with this toolkit are derivatives and carry the same restriction. Read the licence in the model repositories before using the weights. This is a summary, not legal advice.
- Independence. This is an independent community project, not affiliated with or endorsed by Mistral AI. "Timestral", the base architecture and the weights are Mistral AI's.
Metadata
Release files for timestral-tune 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| timestral_tune-0.1.0.tar.gz | 581.0 kB | With provenance | Details for timestral_tune-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| timestral_tune-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for timestral_tune-0.1.0-py3-none-any.whl |
Total release size: 729.9 kB
Release files / timestral_tune-0.1.0.tar.gz
| Download URL | timestral_tune-0.1.0.tar.gz |
|---|---|
| Size | 581.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
45527d393a3e5ab6a547d647f6a3a4a0758dc1876042424f048b311dfaf49863
|
|
BLAKE2b-256 checksum How to use checksums |
405b094413e89dc0b2c6c7ab0a55c03d12f1fc60ba18967e9335bcbcaa46712f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / timestral_tune-0.1.0-py3-none-any.whl
| Download URL | timestral_tune-0.1.0-py3-none-any.whl |
|---|---|
| Size | 148.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
532fe016939b6f4ff8ee91c219e247fd7250d00ab9f184cfca355a786879f555
|
|
BLAKE2b-256 checksum How to use checksums |
0937e629672575528b40fc4f4c95ce5a16a3a10db0875f685e99142b341d6c69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logSecurity for timestral-tune 0.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for timestral_tune-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logA 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.