Skip to content

Add MiniMax M3 and M3.1-Flash - #2536

Merged
AlexCheema merged 1 commit into
mainfrom
models/minimax-m3
Nov 1, 2026
Merged

AlexCheema merged 1 commit into
mainfrom
models/minimax-m3

Conversation

@AlexCheema

Copy link
Copy Markdown
Contributor

Stacked on #2509 (upstream mlx-lm), which is stacked on #2508 (MLX 0.32.4) and #2507 (per-family model folders). It carries #2512's ReasoningEffortHook commit unchanged; drop that commit if #2512 lands first.

Summary

MiniMax M3 (June) and M3.1-Flash (October 23) are the successors of the MiniMax M2.x models exo already serves. Both are open weights under MiniMax's community licence.

  • Size: about 428B parameters, 23B active per token, for both. Despite its name, M3.1-Flash is not smaller: it has the same dimensions as M3.
  • Layers: 60. The first 3 are dense, the other 57 MoE: 128 routed experts, 4 per token (sigmoid routing with a bias), plus a shared expert, all with GPT-OSS-style clamped SwiGLU.
  • Attention: 64 query / 4 KV heads with per-head QK norms and partial RoPE (64 of 128 dims).
  • MiniMax Sparse Attention: a lightning indexer (4 heads, one per KV group) scores 128-key blocks; each query attends to the 16 best blocks, its own block always included. It runs on layers 3-59 in M3 and on all 60 layers in M3.1-Flash. Below 2048 keys every block is kept, so it only changes anything past 2k tokens.
  • Weights: M3 is bf16 (854 GB); MiniMax also ships M3 in MXFP8 (444 GB). M3.1-Flash ships only its quantization-aware-trained weights: NVFP4 routed experts and MXFP8 everywhere else (252 GB).
  • mlx-lm: upstream has the text model (minimax_m3_vl, Add MiniMax M3 model support (text-only) ml-explore/mlx-lm#1398, Ignore HF remote repo changes (temporary fix) #1958, feat(app): open Share Bug Report in a dedicated window #2003), including loading M3.1-Flash's official checkpoint, so it is in deps: move mlx-lm to upstream ml-explore/mlx-lm #2509's pin. The vision tower is not loaded; these cards are text only.

What exo adds, in the minimax family:

  • Tensor parallelism (MiniMaxM3ShardingStrategy, as mlx-lm's own Model.shard):
    • query, key and value heads; the QK norms are per head, so they need no communication;
    • the indexer: it has one index head per KV group, so each rank keeps the index heads of its own KV heads. Its key projection is one head shared by every group and stays whole;
    • the dense MLPs, and the routed experts and the shared expert along their intermediate dimension, summed once by the MoE block. The router stays whole on every rank.
    • Head counts (64 / 4 / 4) allow 2x and 4x tensor parallelism; placement already checks the 4 KV heads.
  • NVFP4 under tensor parallelism (separate commit, auto_parallel.py). An nvfp4 switch layer holds one tensor scale per expert (global_scale, shape [experts]). exo's in-place sharding split every parameter of a projection along the same axis, so each rank kept the scales of only half the experts, and the first forward pass failed ([gather_qmm] Global scale must have one entry per expert with shape (128) but got (64)). The scale doesn't depend on which rows or columns a rank keeps: every rank now keeps them all. The new unit test fails that way without it. This affects any nvfp4 checkpoint with per-expert scales under tensor parallelism, not only MiniMax.
  • Pipeline parallelism needs no fixup: every layer keeps its own KV cache (plus an index-key cache on sparse layers), and the attention mask is built from the shard's first cache.
  • Output parsing (minimax/parser.py):
    • Reasoning is <mm:think>…</mm:think>. A turn without reasoning starts with a bare </mm:think>: the template renders such turns that way, and the model writes them so. Both tags are dropped from the content.
    • Tool calls are XML in a namespace of their own: every tag starts with the ]<]minimax[>[ token, so code or markup inside a value can't be taken for a tag. Objects nest as child elements, arrays as <item> children, and scalars are untyped text (booleans as true/false).
    • mlx-lm alone would get both wrong: it finds <think> in MiniMax's vocabulary (a token the model doesn't use) and picks its JSON tool-call parser because the template contains <tool_call> and tool_call.name.
  • Typed tool arguments (separate commit). Output parsers turned tool calls into ToolCallResponses without the request's tools. An OutputParser can now ask exo to coerce the arguments to the tool schemas, with the coercion the generic tool parser already uses ("3" → 3 for an integer, "true" → true, nested objects and arrays). The coercion also reads an empty value as [] or {} when the schema says array or object: XML writes both as nothing.
  • Reasoning effort and thinking off (the ReasoningEffortHook of Add GLM-5.3, and fix GLM-5.2/5.3 output past 2048 tokens #2512, plus a small TemplateKwargsHook in its own commit):
    • M3.1's template renders reasoning_effort as <effort>…</effort> and documents low, medium, high, xhigh and max. exo's minimal becomes low; none and unset give no effort tag (the template's default). M3's template has no effort.
    • Both think adaptively by default: the model decides whether to reason.
    • M3's template has a thinking_mode switch. For enable_thinking: false exo now sets thinking_mode=disabled: the system prompt says so and the generation prompt ends with </mm:think>, token for token as the official template renders it.
    • M3.1's template has no switch. For enable_thinking: false exo ends the generation prompt with </mm:think>, the prefix its system prompt names for thinking disabled.
    • enable_thinking: true stays adaptive on both. M3's thinking_mode=enabled would open the reasoning block in the prompt itself, which the output parser can't see.
  • Cards (sampling 1.0 / 0.95 from the model card; 1M-token context; text, thinking, thinking toggle):
card weights size checked
MiniMaxAI/MiniMax-M3.1-Flash official: NVFP4 routed experts + MXFP8 252.4 GB full model on hardware (below)
mlx-community/MiniMax-M3.1-Flash-Text-4bit the same weights repacked for MLX, text only 248.4 GB strict load; sampled tensors byte-identical to the official ones
mlx-community/MiniMax-M3.1-Flash-Text-3bit 3-bit affine (fits one 256 GB machine) 186.5 GB strict load; first 6 layers scored against the reference (informational)
MiniMaxAI/MiniMax-M3-MXFP8 official MXFP8 of M3 443.8 GB strict load; its layout tested on a small synthetic checkpoint (see the report)
mlx-community/MiniMax-M3-4bit 4-bit affine of M3 241.5 GB strict load; first 4 layers against the reference: tiers b, c, e, f
  • Every carded checkpoint loads strictly into mlx-lm's model: mlx-lm's load_model(strict=True) on lazy placeholders built from the safetensors headers sets every parameter with the right shape. Under exo's non-strict loading, a conversion with the wrong tensor names would otherwise run on random weights.
  • No cards for M3 in bf16 (854 GB) or for mlx-community's MiniMax-M3.1-Flash-oQ*-mtp mixed conversions (they load, but weren't measured).

Test plan

  • uv run basedpyright (0 errors), uv run ruff check, nix fmt (no changes), and pytest as CI runs it (pytest src -m "not slow" --import-mode=importlib): 1964 passed, 3 skipped, on a Mac Studio with MLX.
  • New tests (models/minimax/tests/):
    • 2-rank pipeline and tensor sharding of a tiny M3 (a dense full-attention layer, then MoE layers with sparse attention whose 4-key blocks the 13-token prompt and decode steps exceed) against a single device. Pipeline must be bit-identical; tensor within 1e-4 in float32.
    • The same tensor split with nvfp4 routed experts (a tensor scale per expert) and mxfp8 elsewhere, as M3.1's checkpoint stores them. It fails without the nvfp4 commit.
    • Output parsing through exo's real parser chain: reasoning, a turn starting with a bare </mm:think>, a tag next to a held-back space, the official template's rendering of two tool calls (code with < and quotes, a nested object, a list, an empty list, a float) parsed back with typed arguments, values without a schema, a JSON-looking string argument, and malformed blocks returned as text.
    • Reasoning effort and thinking off through apply_chat_template, with the effort and generation-prompt lines of the M3.1 template and the thinking-mode lines of the M3 template.
  • Correctness: the report below, against Hugging Face transformers (PyTorch): the full M3.1-Flash model (layer-streamed), its first 6 layers in one piece, the first 4 layers of the M3 4-bit card, and a small checkpoint in M3's official MXFP8 layout.
  • On hardware: the official M3.1-Flash card through exo's API and the perf runner:
    • one Mac Studio (M3 Ultra, 512 GB): 8/8 end-to-end checks, needle recall up to 64k tokens;
    • two Mac Studios over Thunderbolt, as 2x tensor parallel over RDMA and as 2x pipeline parallel over the ring: 8/8 end-to-end checks and 6/6 needle recall (4.5k and 16k tokens) on each, and the full model's tier e (single device vs 2x TP and vs 2x PP) in the harness.

Correctness report

Verdict: PASS. exo's bf16 is closer to the float32 reference than the reference's own bf16 run, and 2x tensor and 2x pipeline parallelism across two Mac Studios pass at full depth.

  • Full model, bf16 vs the reference: exo (official NVFP4/MXFP8 weights, bf16 activations) is closer to the float32 Hugging Face transformers reference than transformers' own bf16 run is, on every one of the 25 prompts: mean KL 0.186 vs 0.264 (paired excess −0.078), top-1 0.960 vs 0.948 where the reference is at least 1 nat confident.
  • M3.1 is unusually precision-sensitive at full depth. transformers' own bf16 run is at mean KL 0.264 from its float32 run (Flint's was 0.045, Qwen3.8-27B's 0.012). Chat, math, multilingual and short code prompts are at 0.005-0.06 for both; raw-text continuations, tool calls and long contexts carry the mean, for both.
  • Float32 against float32 at full depth (8 prompts): exo matches transformers to a median KL of 2e-10 (code, math, tool and raw-text prompts: ≤ 2.4e-6). Long contexts are the exception, and the sparse attention's block selection explains it: it is ill-conditioned at depth. exo against itself, with only the prefill split into 1024- instead of 4096-token chunks, differs as much as exo does from the reference (mean KL 0.49 on the 3.3k-token haystack).
  • First 6 layers, real weights, in one piece: per-layer hidden states match transformers to a relative L2 of 5e-7 in float32, with the sparse attention active (3000 tokens), in a prefill and in step-by-step decoding. In bf16: mean KL 2.7e-5 vs transformers' own 1.1e-4; greedy decoding identical on 25/25 prompts; 2x pipeline bit-identical and 2x tensor within bf16 noise, also on a 15k-token haystack.
  • M3 (not M3.1): the 4-bit card's first 4 layers (3 full-attention + 1 sparse) pass the same tiers; M3's official MXFP8 layout matches transformers exactly on a small checkpoint built in that format.
  • Templates: exo's rendering matches the official templates' token ids on 19/24 (M3.1) and 21/24 (M3) fixtures; the rest are documented deviations.
  • Full model on two Mac Studios: 2x tensor parallel (RDMA) is at mean KL 0.171 from the single device (median 4.2e-4), inside the reference's own bf16 noise (0.264). 2x pipeline parallel is bit-identical to a single device prefilling in the same chunks.
  • API: 8/8 end-to-end checks on one Mac Studio, on 2x TP and on 2x PP, including typed tool-call arguments, parallel streamed calls, thinking off and reasoning separation. Needle recall 7/7 at 4.5k, 16k and 64k tokens on one machine, 6/6 at 4.5k and 16k on each of TP and PP.

Setup

Reference weights MiniMaxAI/MiniMax-M3.1-Flash at 2f33a8b9ae49ce7b51c994df97166a7fd059bc2e, every file checked (LFS sha256, git blob ids). mlx-community/MiniMax-M3-4bit at 29909f4575501289881466f3b3bd910fdc95bc7c, mlx-community/MiniMax-M3.1-Flash-Text-3bit at 71463b23769721057082e06fc14c1a54be981012 (their first layers, fetched by tensor)
exo weights the same checkpoints: mlx-lm loads the official NVFP4/MXFP8 tensors directly, so both sides hold the same values
Weight decoding (reference) exact, in float32: NVFP4 = e2m1 value × e4m3 scale per 16 inputs ÷ the tensor's global scale; MXFP8 = e4m3 value × 2^(e8m0 − 127) per 32 inputs; MLX affine = q × scale + bias. Then cast to the run's dtype, as from_pretrained(dtype=...) would
exo this branch; MLX 0.32.4 (the PyPI wheel; exo's uv.lock builds the same tag from source), mlx-lm ml-explore/mlx-lm at 6b572ab as locked
Reference implementation Hugging Face transformers 5.22.1, PyTorch 2.15.0, MiniMaxM3VLForCausalLM (SDPA attention, grouped_mm experts). Float32 for teacher forcing (gold); bfloat16 as the noise baseline and, on truncated checkpoints, for greedy decoding
Full-depth reference layer-streamed: transformers' own decoder layers, filled from the checkpoint one at a time and run over every prompt (exo_harness.reference_streamed). On the 6-layer checkpoint it reproduces the one-piece runner exactly (KL 0 at all 5,823 positions)
Hardware Mac Studio (M3 Ultra, 512 GB): exo and the CPU reference. The truncated runs: a second Mac Studio (M3 Ultra, 512 GB). Full-depth tier e and the 2-node API checks: two Mac Studios (M3 Ultra, 512 GB) connected by Thunderbolt 5
Prompts 25 prompts: code, math, six languages plus byte-fallback text, reasoning, multi-turn chat, JSON, tool calls and results, raw continuations, long context (3.3k, 7.5k and 3.0k tokens). A 15k-token haystack on the truncated model only. Thinking is left unset (the templates' adaptive default; M3.1's template has no switch)
Continuations truncated models: the reference's bf16 greedy decode. Full model: exo's bf16 greedy decode (greedy decoding through a layer-streamed reference would stream the checkpoint once per token)

KL is KL(reference ‖ candidate) per scored position, over the reference's top 64 tokens plus a tail bucket (a lower bound of the full-vocabulary KL).

Summary

tier check comparison result key numbers
a per-layer hidden states 6 layers, MLX fp32 vs transformers fp32, 3000 tokens PASS relative L2 ≤ 5.1e-7 at every layer; logits KL 1.6e-12; step-by-step decode the same
b teacher-forced distributions, full model exo bf16 vs transformers fp32 (transformers bf16 as baseline) PASS mean KL 0.186 (baseline 0.264, paired excess −0.078); median 4.8e-4; top-1 0.907 (baseline 0.866), 0.960 where the reference margin ≥ 1 nat (baseline 0.948)
b′ the same in float32, full model exo fp32 vs transformers fp32, 8 prompts info median KL 2e-10; ≤ 2.4e-6 on code, math, tools, raw text; 0.36 on two long-context prompts (see below)
b teacher-forced, first 6 layers exo bf16 vs transformers fp32 PASS mean KL 2.7e-5 (baseline 1.1e-4); top-1 0.997
b the same, 15k-token haystack PASS mean KL 2.0e-5 (baseline 1.2e-4)
c greedy decoding, first 6 layers exo bf16 vs transformers bf16 PASS 25/25 identical, and the 15k haystack
e single vs 2x TP / 2x PP, first 6 layers two ranks on one Mac Studio PASS TP: mean KL 2.0e-5, greedy 25/25 identical; PP: bit-identical (also at 15k tokens)
e single vs 2x TP, full model two Mac Studios, RDMA PASS mean KL 0.171, inside the reference's bf16 noise (0.264); median 4.2e-4; top-1 0.967 where the margin ≥ 1 nat (noise 0.948)
e single vs 2x PP, full model two Mac Studios, ring; both prefilling in 512-token chunks PASS bit-identical at all 5,502 positions
b, c, e M3 4-bit card, first 4 layers exo vs transformers on its exactly decoded weights PASS b: mean KL 1.5e-5 (baseline 2.5e-5); c: 25/25 identical; TP KL 6.3e-6; PP bit-identical
a M3's MXFP8 layout small synthetic checkpoint, MLX fp32 vs transformers fp32 PASS relative L2 ≤ 2.9e-7; logits KL 7e-16
f chat template token ids exo's rendering vs the official template PASS M3.1: 19/24 identical, 5 expected deviations. M3: 21/24 identical, 3 expected
e API end to end official card through /v1/chat/completions: one Mac Studio; two, as 2x TP (RDMA) and 2x PP (ring) PASS 8/8 checks on each
- needle recall API, thinking off PASS one Mac Studio: 3/3 at 4.5k, 3/3 at 16k, 1/1 at 64k tokens. 2x TP and 2x PP: 3/3 at 4.5k and 3/3 at 16k on each
d task evals not run the CPU reference streams 252 GB per forward pass

Tier b at full depth: where the KL is

Mean KL per prompt against the float32 reference:

prompt exo bf16 transformers bf16
chat, reasoning, knowledge (5 prompts) 0.008-0.023 0.025-0.038
math (3) 0.005-0.022 0.016-0.062
multilingual (6) 0.006-0.020 0.018-0.063
code, chat-templated (3) 0.006-0.016 0.022-0.047
tools-call-01 / tools-result-01 0.174 / 0.234 0.278 / 0.405
raw-prose-01 / raw-json-01 / code-raw-01 0.240 / 1.450 / 1.194 0.383 / 1.623 / 1.509
long-haystack-2k / -6k / long-prose-raw-3k 0.896 / 1.166 / 1.661 1.319 / 1.316 / 2.463
  • exo is closer than transformers' bf16 on every prompt.
  • The high rows are the same for both. Raw-text prompts (no chat template) are continued by exo's own greedy decode, which drifts into degenerate text ([truncated] … [tr] [tr]invoke_ur) where every next token is uncertain. Tool-call turns and long contexts are the others.
  • What isn't the cause: probes that compute the Gemma-style norms' 1 + w in float32 (as transformers does) or combine the routed experts' outputs in float32 leave these prompts where they are (e.g. raw-json-01 1.45 → 1.33 / 1.47; tools-result-01 0.23 → 0.27 / 0.18). exo in float32 matches the reference on the tool and raw-text prompts (mean KL ≈ 1e-8). So it is bf16 rounding, which the model amplifies at depth, not a difference in the computation. By the precision policy, nothing is changed.

Long contexts in float32: the sparse attention's selection is ill-conditioned

  • exo in float32 matches the reference everywhere except long contexts: mean KL 0.44 on the 3.3k-token haystack and 0.31 on 3k tokens of prose.
  • The same happens inside exo. Splitting the prefill into 1024- instead of 4096-token chunks is mathematically the same computation; it only changes rounding. exo float32 at 1024 vs at 4096: mean KL 0.49 on the haystack. And exo at 1024 tokens is 0.024 from the reference on that prompt (0.26 on the prose).
  • Why (consistent with the chunking test): each query attends to the 16 key blocks whose best key scores highest in the indexer, and only half of the index head is rotated by position. A haystack repeats the same tokens in every block, so many blocks score almost alike. A rounding difference, accumulated over 60 layers, can then pick different blocks, and attending different blocks of a retrieval context changes the next token.
  • Not a model error: on 6 layers in float32 (3000 tokens, 16 of 24 blocks kept) exo reproduces transformers to 1e-12; needle recall through exo's API is 7/7 up to 64k tokens.

Full model across two Mac Studios (tier e)

exo's harness ran the full model in bf16 on the same 25 prompts on a single device, as 2x tensor parallel over RDMA and as 2x pipeline parallel over the ring, and compared the teacher-forced distributions.

  • Tensor parallel: mean KL 0.171 from the single device, median 4.2e-4, top-1 0.967 where the single device's margin is at least 1 nat. That is inside the reference's own fp32 → bf16 noise (mean KL 0.264, top-1 0.948), the distributed threshold. Chat, knowledge, math, multilingual and reasoning prompts are at 0.006-0.012. Long contexts (1.07), raw text (0.69), code (0.19) and tools (0.17) carry the mean: the prompts where bf16 rounding already moves the model most (tier b above). Tensor parallelism changes the order of the all-reduced sums, and on long contexts that reaches the sparse attention's block selection, as the prefill chunk size does.
  • Pipeline parallel: bit-identical to a single device prefilling in the same 512-token chunks: KL 0 and identical top-1 at all 5,502 positions. Against a single device in exo's default 4096-token chunks, the 21 sequences shorter than 512 tokens are still bit-identical; the 4 longer ones, whose prefill is split differently (a tool-result turn and the 3 long contexts), differ (mean KL 0.09 over the two tool prompts, 1.02 over the long contexts), as the chunk-size test above predicts. The harness used 512-token chunks because, with 4096-token chunks, its in-process pipeline run of the full model hit the GPU command-buffer timeout; exo itself served 16k-token prompts over 2x pipeline parallel (the perf and needle runs).

First 6 layers, in one piece (real weights)

  • Checkpoint: layers 0-5 of the official checkpoint (3 dense + 3 MoE, all with sparse attention), with the embeddings, final norm and LM head, cut from the downloaded shards byte for byte (18.7 GB).
  • Tier a, float32: embedding identical; layers 0-5 at relative L2 3.4e-7, 2.6e-7, 2.9e-7, 3.8e-7, 4.2e-7, 5.1e-7 (hidden-state scales up to 7,000); logits KL 1.6e-12, top-1 100 %. A 2500-token prefill followed by 500 single-token decode steps gives the same logits (KL 1.7e-12). So the NVFP4 global scales, the MXFP8 scales, the indexer's partial RoPE, its block pooling and selection, and the index-key cache all match.
  • Tier b, bf16: mean KL 2.7e-5, median 1.3e-5, top-1 0.997 (1.000 at margin ≥ 1 nat) over 5,823 positions; transformers' own bf16 is at 1.1e-4.
  • Tier c: greedy decoding identical on all 25 prompts.
  • Tier e: 2x tensor parallel mean KL 2.0e-5 (median 3.8e-6), greedy 25/25 identical; 2x pipeline bit-identical. Two ranks on one Mac Studio over the ring backend.
  • 15k-token haystack (116 key blocks, 16 kept): tier b mean KL 2.0e-5 (transformers bf16 1.2e-4), greedy identical, TP 1.5e-5, PP bit-identical. It crosses exo's 4096-token prefill chunks.
  • More, on the same checkpoint:
    • batched generation (mlx-lm's BatchGenerator, which exo drives; prompts of 3000, 2600 and 700 tokens, so the batch is left-padded) gives the same greedy tokens as each prompt alone;
    • exo's KV prefix cache: a request extending an earlier one (5,018 of 5,047 tokens cached, including the index-key caches) gives the same tokens as without the cache, with log-probs within bf16 rounding of a different prefill split.

M3 (not M3.1)

  • mlx-community/MiniMax-M3-4bit, first 4 layers (3 dense full-attention layers, then an MoE layer with sparse attention; RoPE base 5M): against transformers on the checkpoint's exactly decoded 4-bit weights, tier b mean KL 1.5e-5 (transformers bf16 2.5e-5), greedy 25/25 identical, TP mean KL 6.3e-6, PP bit-identical. This conversion folds the shared expert into the routed experts as a 129th; mlx-lm's loader splits it off.
  • MiniMaxAI/MiniMax-M3-MXFP8: its first layers couldn't be fetched in time (the range requests slowed to ~1 MB/s). Instead, the tiny-random M3 was written in exactly its layout: per-expert w1/w2/w3 and every other linear as F8_E4M3 values with an E8M0 weight_scale_inv per 32 inputs, dense MLPs under mlp., and the official quantization_config. mlx-lm loads it as mxfp8 QuantizedSwitchLinear experts and mxfp8 linears; in float32 it matches transformers at relative L2 ≤ 2.9e-7, logits KL 7e-16, also step by step. The full checkpoint's tensor names and shapes load strictly.

Tier f: chat templates

exo's real rendering path (OpenAI request → adapter → apply_chat_template → encode_prompt) against the official templates rendered by transformers:

fixture M3.1 M3
plain, system, multi-turn, unicode, developer role, tools, nested schema, tool call and result, reasoning history, effort high identical identical
typed and nested tool-call arguments, a null argument, parallel calls with grouped results identical identical
reasoning in every past turn; a past turn without reasoning (bare </mm:think>) identical identical
effort minimal (→ low), xhigh, thinking on (exo's medium) identical identical (M3 has no effort)
thinking off expected deviation: exo ends the prompt with </mm:think>; M3.1's template has no switch identical to thinking_mode=disabled
assistant prefill expected deviation: exo appends the prefill after the generation prompt; the template renders a finished turn starting with </mm:think> (exo's generic handling) same
two system messages; a mid-conversation system message expected deviation: exo's generic system-message consolidation same

Quantized weights (informational)

  • mlx-community/MiniMax-M3.1-Flash-Text-4bit holds the official weights repacked for MLX: the sampled tensors (expert values and scales, attention values and scales, a dense MLP) are byte-identical to the official ones.
  • mlx-community/MiniMax-M3.1-Flash-Text-3bit re-quantizes them to 3-bit affine (186.5 GB, the only conversion that fits one 256 GB machine). On the first 6 layers, against the float32 reference of the official weights: mean KL 1.1e-3 (paired excess 9.4e-4), top-1 0.975, top-5 overlap 0.893, greedy 25/25 identical. Six layers understate what the full depth costs.

Deviations and caveats

  • No tier c at full depth: the reference is layer-streamed, so greedy decoding isn't practical; tier c is on the truncated checkpoints, and the full model's greedy outputs are checked through the API.
  • The 15k-token haystack is left out of the full-depth reference (its bf16 attention on CPU is too slow); it is covered on 6 layers.
  • CPU bf16 reference: PyTorch on macOS has no fast bf16 batched GEMM; as in earlier reports, the reference computes those products in float32 and rounds once (0.015 % of outputs differ from torch's own kernel, by less than one bf16 step).
  • KL bound: from each side's top 64 tokens plus a tail bucket.

Thresholds

  • same-precision (tier b): mean KL ≤ 2e-3, or no more than transformers bf16 on the same positions (paired); top-1 limits scaled the same way; greedy departures only at near-ties.
  • distributed (TP): within the reference's own fp32→bf16 noise. distributed-exact (PP): bit-identical.
  • exact (templates): identical token ids, except documented deviations.

Reproduce

# reference (transformers, CPU), full model, layer-streamed, on exo's greedy continuations
python ref_m3_streamed.py run --checkpoint <MiniMax-M3.1-Flash> --format hf --dtype float32 \
  --prompts data/prompts_minimax_m3.jsonl --skip long-haystack-12k --tasks tf \
  --continuations-from runs/exo_greedy.json --label hf-fp32 --out runs/hf_fp32_full.json
python ref_m3_streamed.py run ... --dtype bfloat16 --label hf-bf16 --out runs/hf_bf16_full.json
# truncated checkpoints: the one-piece runner with the same exact decoding
python ref_m3.py --checkpoint <first-6-layers> --dtype bfloat16 --tasks greedy,tf ... --out runs/hf_bf16.json
# exo side (single / TP / PP, templates, comparisons, report)
python -m exo_harness.suite --config suite.json

Performance (official M3.1-Flash weights)

Setup

  • Hardware: Mac Studio (M3 Ultra, 512 GB), macOS 27.0.1. Two nodes: two such machines connected by Thunderbolt 5; tensor parallel over RDMA (MLX's jaccl backend), pipeline parallel over the TCP ring.
  • Weights: MiniMaxAI/MiniMax-M3.1-Flash (NVFP4 routed experts, MXFP8 elsewhere), 248 GB in memory.
  • Software: this branch, with MLX 0.32.4 and mlx-lm 6b572ab as pinned in uv.lock.

Method: the exo correctness harness perf runner (exo_harness.perf), batch 1.

  • Prompts: chat-templated multilingual prose, sized to the stated token count with the model's tokenizer.
  • Generation: 128 tokens, with EOS banned by /bench/chat/completions. The prefix cache is off.
  • Repetitions: 1 warm-up request, then 3 measured requests per row with 3 s between them; the table reports the median. Max/min across the repetitions was at most 1.03.
  • TTFT is client-side, to the first streamed token. Prefill and decode tok/s are exo's server-side generation_stats. Peak memory: MLX's peak on the reporting rank / the largest RAM in use on either node during the row (from /state; the whole machine).
config comm nodes prompt tok gen tok TTFT s (median [min-max]) prefill tok/s decode tok/s (median / best) peak mem GB (MLX / max node RAM)
single - 1 512 128 3.60 [3.57-3.61] 152.6 23.2 / 23.2 267.6 / 267.6
single - 1 4096 128 13.18 [13.17-13.20] 317.7 18.4 / 18.4 269.8 / 270.9
single - 1 16384 128 57.85 [57.84-57.96] 284.9 16.6 / 16.6 276.1 / 278.2
tp2 RDMA 2 512 128 2.14 [2.13-2.20] 493.1 29.4 / 29.4 137.1 / 149.6
tp2 RDMA 2 4096 128 8.19 [8.10-8.23] 582.1 22.6 / 22.6 139.3 / 153.2
tp2 RDMA 2 16384 128 34.42 [34.41-34.45] 492.9 19.3 / 19.4 141.5 / 157.0
pp2 ring 2 512 128 2.74 [2.73-2.75] 206.4 21.4 / 21.4 130.4 / 155.2
pp2 ring 2 4096 128 14.61 [14.58-14.63] 286.3 17.6 / 17.7 132.5 / 159.7
pp2 ring 2 16384 128 36.37 [36.33-36.38] 458.9 15.9 / 16.0 135.6 / 176.4

Observations

  • Tensor parallel over RDMA is the faster way to use two machines. Decode is 1.27x one machine at 512 tokens (29.4 vs 23.2 tok/s), 1.23x at 4k and 1.16x at 16k; prefill is 3.2x, 1.8x and 1.7x (TTFT 34 s instead of 58 s at 16k). Each machine's MLX peak is 137 GB, about half of one machine's 268 GB.
  • Pipeline parallel over the ring decodes a single request slower than one machine (0.92-0.96x): the stages run one after the other, plus a network hop per token. Its prefill is 1.35x at 512 tokens, 0.90x at 4k and 1.6x at 16k.
  • Decode slows with context: 23.2 tok/s at 512 tokens, 16.6 at 16k. Past 2048 keys every layer's indexer scores every cached key, and mlx-lm builds the kept blocks into a dense per-head mask.
  • Long prompts: a 64k-token needle request took 532 s through the API (about 120 tok/s of prefill), measured while the CPU reference was also running on that machine.
  • Memory for long prompts: mlx-lm's sparse attention materializes a boolean mask over all heads, queries of the prefill chunk and keys. On the 6-layer checkpoint, the transient memory above the weights grew about linearly with context: 2.8 GB at 4k, 6.4 at 16k, 12.4 at 32k and 24.3 GB at 64k (it is needed for one layer at a time). Extrapolated, one 512 GB machine handles a few hundred thousand tokens, not the cards' 1M; tensor parallelism halves the heads per rank. This is upstream mlx-lm's implementation; a fused block-sparse kernel would remove it (performance phase).

Screenshots

MiniMax-M3.1-Flash (the official NVFP4/MXFP8 card) placed by exo as 2x tensor parallel over RDMA on two Mac Studios, answering a chat from the dashboard with thinking on (the reasoning is collapsed): first token after 3.5 s, 26.1 tok/s. Device names are generic.

Dashboard home with MiniMax-M3.1-Flash running tensor parallel on two Mac Studios:

cluster-home.png

Dashboard chat with MiniMax-M3.1-Flash (2x tensor parallel, RDMA over Thunderbolt):

cluster-chat.png

🤖 Generated with Claude Code

@AlexCheema

Copy link
Copy Markdown
Contributor Author

The runner crash in the 8-concurrent GSM8K runs ([metal::malloc] Resource limit (499000) exceeded after about 15 minutes) is a leak in batched decoding, and it happens without the perf follow-up too.

Each sparse-attention layer keeps its index keys in a second cache beside the attention cache. Nothing reads that index cache's offsets. In a batch, those offsets are an array that moves on lazily at every step, so each step's update chained onto the last and kept a small Metal buffer alive. That is 60 more live buffers per decode step, until the batch empties. When it doesn't empty for about 8,000 steps, the runner crashes.

Fixed in 1073bbc, now part of this PR: exo's decode step evaluates every cache's offsets, as it already did for Qwen3.5's linear attention lengths. Two regression tests (a stand-in model and a tiny MiniMax M3 through the batch generator) fail without it.

  • Log-probs are unchanged, bit for bit.
  • Decode at batch 8 costs about 0.5% more (0.35 ms per step); at batch 1 the cost is within noise.
  • A tiny-model reproduction that crashed after 7,864 steps ran 25,000 steps without leaking. Through the API, the full model crashed after about 7,000 decode steps without the fix. With it, it served 450 GSM8K requests 8 at a time over 34 minutes (about 13,000 decode steps without the batch emptying), with no errors and no growth.

🤖 Generated with Claude Code

@AlexCheema
AlexCheema force-pushed the deps/mlx-lm-upstream branch from d5eb3a5 to 66ea418 Compare November 1, 2026 16:02
Base automatically changed from deps/mlx-lm-upstream to main November 1, 2026 16:10
Landing commit: this PR's change on top of main, with conflicts with the PRs landed before it resolved as in the tested integration build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@AlexCheema
AlexCheema merged commit 6376052 into main Nov 1, 2026
6 checks passed
@AlexCheema
AlexCheema deleted the models/minimax-m3 branch November 1, 2026 18:24
cdvankammen added a commit to cdvankammen/exo that referenced this pull request Nov 2, 2026
… the right layers on pipeline ranks

Port upstream commit e4db325 from exo-explore/exo PR exo-explore#2543.

Every rank of a multi-node decode instance fetches the remote prefill on its own,
and the prefill server sends layers by their global index. A pipeline rank holds
only layers [start_layer, end_layer), but ingest_into_mlx_cache matched the global
index against the rank's local index, so ranks after the first silently loaded
layers 0..k. There was no error; attention was simply wrong.

Pass the shard's start_layer from MlxBuilder through BatchGenerator to
ExoBatchGenerator, and on to ingest_into_mlx_cache as layer_offset.

Nothing made the ranks agree on the outcome either: one rank could fall back to
local prefill (which runs collectives) while another did not, which hangs. After
the fetch, multi-node instances now check with mx_any; if any rank failed, every
rank discards its result and prefills the full prompt locally from a fresh cache.

Tests: test_pipeline_layer_offset.py (3 tests) passes, verifying that a rank
holding layers 3..5 gets exactly those layers with the offset, and layers 0..2
without it.

Note: test_sequential_remote_prefill_layer_offset.py cannot be collected due to
a pre-existing fork inconsistency — the fork's Architecture class at base 09f75ad
is missing fields (exact_think_tags, batched_generation, pipeline_parallel,
post_load) that upstream added between PR exo-explore#2536 and exo-explore#2543. The fork's
laguna/family.py already uses exact_think_tags=True, creating an import-time
TypeError. This is a fork-level issue unrelated to PR exo-explore#2543's changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cdvankammen pushed a commit to cdvankammen/exo that referenced this pull request Nov 3, 2026
… PR exo-explore#2557)

Port of upstream exo PR exo-explore#2557 (3a8b1b2) onto the fork, based on 09f75ad
(the fork's port of upstream exo-explore#2536).

A fake Hub (src/exo/download/tests/fake_hub.py) that serves the tree,
revision, resolve and CDN endpoints over real TCP, with ETags, Range,
redirects and pagination, and injects faults per request: resets,
stalls, short bodies, throttling, slow first byte, 5xx, 429 with the
RateLimit header, 401/403/404, ignored Range, 416, corrupt bodies, and
the endpoint going down (refused or blackholed) and coming back. Repos
have a commit history so tests can change files upstream mid-download.

A harness (harness.py) runs the real DownloadCoordinator and shard
downloader against it, applies the events with the real
apply_node_download_progress, and can play the worker's part
(re-requesting a wanted model). Timeouts and backoffs are shrunk
through a Timing parameter rather than slept through.

test_download_failure_modes.py covers network faults, restarts,
cancel/delete, duplicate and per-shard starts, disk full, read-only and
multiple model dirs, offline mode, upstream changes, hash mismatches and
broken repos. The 22 scenarios that fail today are xfail(strict=True)
with the reason.

Cherry-pick of upstream 3a8b1b2, no conflicts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant