Skip to main content

mrail — maps of exact language-model runs

.mrail is an append-only file format for what a language model has already computed. For models whose state after any prefix has a constant size (state-space models, linear attention, gated delta networks, fixed-state attention such as Ward recall), the state is a pure function of the token prefix. A map of earlier runs therefore lets a runtime

  • answer known contexts without running the model — the stored continuation is the model's own greedy output;
  • restart exactly from anchored states at shared prefixes (system prompts, conversation histories), or rebuild any state from the stored tokens;
  • draft continuations for new contexts, verified by the model in one pass, so the map changes speed, never output;
  • grow with use — every served answer is appended; maps split by topic, load and merge like any file.

Measured with a compiled Qwen2.5-1.5B-Instruct (constant state of 14.4 MiB) on the Apple Neural Engine (see the papers below): known questions in 3.0–4.3 ms instead of 9.7–10.3 s; 2.54 instead of 1.25 accepted tokens per pass on unseen coding tasks with a 1.2 MB coding map of 1 641 runs (2.27× greedy decoding); 8.4 MB instead of 893 MB for the anchors of the same runs through delta coding and stations, 9.6 kB for their tokens alone.

Tracks (format kind 5, new in 0.4) record a run without its context: the context by its chain hash and a source name (an eval item, a document id), the model's answer copy-coded against it. On 652 runs of benchmark prompts of 131k to 1M tokens the maps shrink from 881.4 MB to 89.5 KB, 143 bytes per run of a million tokens, and every track replays its answer identically. Long runs are indexed at every 256th prefix, at the end of the prompt and at every answer position (4k hash entries instead of a million for a 1M-token run).

This repository contains the format specification and a dependency-light reference reader and writer (Python, numpy). It does not contain a model runtime.

pip install mrail
import mrail
m = mrail.MapFile("coding.mrail")                  # opens or creates
answer = mrail.exact_answer(m, context_tokens, max_new=256, stop={151645})
m.add_session(prompt_tokens + model_answer_tokens + [next_token], gen_start=len(prompt_tokens))
tree = m.rail.tree(context_tokens, budget=31)       # draft tree [(token, parent)] for verification
python -m mrail info coding.mrail
python -m mrail merge team.mrail alice.mrail bob.mrail

Share your map

A map is a file of verified output of one exact model. Maps merge by loading their runs (python -m mrail merge), so a map of a repository, a documentation set, a tool protocol or a team's daily questions can be shared with everyone who runs the same model. Runs from a foreign map are loaded as drafts only: they propose continuations, the model verifies every token, and only runs produced by the local model answer a context directly. A shared map therefore makes inference faster on its topic and cannot change a single output token. The map is written by the model itself (the Möbius loop: every verified answer becomes a run, every disagreement becomes a new run), so it grows finer with use and never turns into a store of canned answers.

Name shared maps by model and topic, e.g. Qwen2.5-1.5B-Instruct-HCGM.coding.mrail, and renew them when the model version changes.

Papers

Models and maps: huggingface.co/tfwnotops.

License: Apache-2.0.

Metadata

Release files for mrail 0.4.0

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

Source distribution (sdist)

Source distribution for mrail 0.4.0
File Size Uploaded
mrail-0.4.0.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mrail 0.4.0
File Interpreter ABI Platform
mrail-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.4 kB

Release files / mrail-0.4.0.tar.gz

Download URL mrail-0.4.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
78d09c1a3d99f962ca11ee3833fc99374d77c3f107d95247d835bca7d178cb12
BLAKE2b-256 checksum
How to use checksums
7f646e0ee02bb6dcc96b8f7ac5eb04d612a14e2b70a73697fae823af7066390d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / mrail-0.4.0-py3-none-any.whl

Download URL mrail-0.4.0-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
396ca83e9a6396c7b28d0f34beea2f2e3f2e6ec327aa9944eb2b30cb68f92efb
BLAKE2b-256 checksum
How to use checksums
0a11ba368da04d9d9519d3a6108430024fc32547cfb60f57c5b6500e21edc49b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release history Release notifications | RSS feed

0.4.1

2 release files

This release

0.4.0 This release

2 release 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