[PR #477] [CLOSED] MiniMax-M3.1-Flash on Maya: its own engine (maya-mm3) with tensor parallel, DSpark, pictures, INT8 KV and KV streaming; the setup offers it beside GLM and DeepSeek #552

Closed
opened 2026-10-29 21:26:44 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/477
Author: @needmorevram
Created: 10/25/2026
Status: ❌ Closed

Base: main ← Head: minimax-m3.1-flash


📝 Commits (10+)

  • d69f718 maya-mm3: MiniMax-M3.1-Flash (EXL3) - its own engine, first working forward
  • 40273ea maya-mm3: decode at 16 tok/s - expert profile, pinned pool, token kernels, CPU lane
  • 2801329 maya-mm3: Maya's engine protocol, and MiniMax-M3.1 in the server
  • 0471fed Setup: MiniMax-M3.1-Flash as Maya's third model (maya-mm3)
  • 6a628e6 maya-mm3: DSpark drafting - exact, ~1.5x decode
  • 2134b60 maya-mm3: DSpark's confidence floor 0.7 by default
  • c35772f maya-mm3: the CPU lane's pool - a late worker can no longer take a job of the next phase
  • 6daf756 maya-mm3: the staging slots as an expert cache in decode
  • 768099e maya-mm3: the expert cache's copies at a forward's end, its slots live two forwards on
  • faf4583 maya-mm3: pictures - MiniMax-M3.1-Flash's vision tower in the engine

📊 Changes

37 files changed (+12896 additions, -48 deletions)

View changed files

📝 CMakeLists.txt (+11 -0)
➕ data/expert-profile-mm3.bin (+0 -0)
📝 maya.py (+214 -11)
📝 serve/frontend.py (+218 -5)
➕ serve/mm3_vision.py (+175 -0)
📝 serve/server.py (+40 -18)
➕ serve/test_minimax_frontend.py (+140 -0)
➕ serve/test_mm3_vision.py (+70 -0)
📝 serve/web/app.css (+2 -0)
📝 serve/web/app.js (+38 -12)
📝 serve/web/index.html (+2 -0)
➕ src/mm3/mm3_cpu.cpp (+392 -0)
➕ src/mm3/mm3_cpu.hpp (+47 -0)
➕ src/mm3/mm3_dspark.cu (+373 -0)
➕ src/mm3/mm3_dspark.hpp (+65 -0)
➕ src/mm3/mm3_exl3.cu (+2495 -0)
➕ src/mm3/mm3_exl3.hpp (+221 -0)
➕ src/mm3/mm3_geo.hpp (+72 -0)
➕ src/mm3/mm3_kernels.cu (+973 -0)
➕ src/mm3/mm3_kernels.cuh (+127 -0)

...and 17 more files

📄 Description

MiniMax-M3.1-Flash as Maya's third model, with its own engine maya-mm3, built for the community EXL3 quant Mia-AiLab/MiniMax-M3.1-Flash-EXL3-EAQ-v1-3.5-bpw (196.7 GB; its card says no engine had loaded it before). ./setup.sh offers it beside GLM and DeepSeek, and maya.py serves it with chat, tools, all five thinking levels, DSpark drafting, pictures, tensor parallel and a 128K context. GLM's and DeepSeek's engines are untouched. Rebased on main v1.1.27.

Results

One PC: an RTX 3090 and 8 RTX 5060 Ti (152 GB VRAM, each GPU on PCIe 3.0 x8), 183 GB RAM, 2 NUMA nodes. Experts that don't fit in VRAM run on the CPU from pinned RAM, so nothing is read from the SSD after loading.

decode, code decode, prose prompt
layer split (each GPU a run of layers), plain decode ~16 tok/s ~16 tok/s ~40 tok/s
layer split + DSpark 27.7 tok/s ~19 tok/s
--tp 4 + DSpark, 8K context 38.2 tok/s 32.4 tok/s ~99 tok/s (6K)
--tp 4 + DSpark, 64K context ~31 tok/s ~31 tok/s
--tp 4, INT8 + streaming, 128K context 84.1 tok/s (53K prompt)

Decode is 300-token greedy answers to a code prompt and a prose prompt. The CPU lane (about 0.55 ms an expert, compute-bound) is what limits code; per-layer round trips and the draft's acceptance limit prose.

Quality checks:

  • tools/mm3/ref.py, a torch reference over the EXL3 pack, matches transformers' MiniMaxM3VL modules to about 3e-7 on real layers.
  • Engine vs reference on a 199-token chat: the same top token at 64 of 64 positions, mean KL 0.001 (reference decoding EXL3 the engine's way) and 0.005 (exact).
  • Needles found at 9K, 30K and 53K tokens, so the sparse block selection retrieves from far back.
  • Greedy decode with DSpark gives the same tokens as plain decode (128 of 128, at every confidence floor).
  • --tp is deterministic: MM3_STRESS repeated one verify window's forward 300 times with the same logits bit for bit.

What it adds

maya-mm3: the engine (src/mm3)

  • The model as MiniMax's code defines it:
    • GQA with 64 query / 4 KV heads, per-head QK norm, partial NeoX RoPE (64 of 128 dims, θ 1e7).
    • MiniMax Sparse Attention in all 60 layers: per KV group and per query, the top 16 blocks of 128 by FP32 index scores, the query's own block forced in. Layers 0-2 are sparse too in M3.1 (llama.cpp's M3 graph makes them dense).
    • Routing: sigmoid with a correction bias, top 4 of 128 renormalised and scaled 2.0, plus the shared expert. Activation: swigluoai.
  • EXL3 read in place (mul1 codebook, 3-6 bit widths), with its own copy of the EXL3 kernels and the activation built in. The CPU lane runs on the shared CPU EXL3 library unchanged.
  • Expert placement:
    • An expert profile (data/expert-profile-mm3.bin) keeps the most-routed experts in VRAM.
    • Every other expert is assembled once into a pinned pool, so a miss costs one DMA or one CPU-lane job.
    • Staging slots double as an expert cache: an expert that keeps coming back is copied in at a forward's end and goes live two forwards later, so runs stay bit-identical.
  • Tensor parallel (--tp 1|2|4):
    • The GPUs form groups: the 3090 alone, then 2 × 4 5060 Ti.
    • Each member of a group holds its query heads and their KV heads, its index heads, o_proj's columns, and a quarter of every FFN's width.
    • The host keeps the residual stream. It sums the members' parts in a fixed order (AVX2), routes on the CPU, and runs the experts not in VRAM on the CPU lane as tp sub-experts.
    • A decode window's work is enqueued up front by a thread per GPU, gated by wait kernels on pinned counters. Prompts go in chunks of 256.
  • DSpark drafting (--dspark on):
    • The pack's 5-layer draft, with its MXFP8 weights read as stored (mx_rows).
    • Taps from layers 3/17/31/45/59, blocks of 7, confidence floor 0.7.
    • Verification takes the target's own distribution, so sampling is unchanged.
  • Pictures (--vision on): the 32-layer vision tower in the engine; the server resizes as image_processor.py does.
  • KV cache options:
    • --kv-cache int8: opt-in, one scale per row of 128. On 16K tokens of assistant text, perplexity goes from 6.996 to 7.009 (+0.19%), flat across positions. It's not exact, so BF16 stays the default.
    • --kv-streaming on: the last --kv-resident positions (32768 by default) stay in VRAM as a tagged ring; every position also lives in mapped pinned RAM, and attention reads older keys from there. It's exact: 6K logits came out byte for byte the same with it on and off, 8K perplexity matched at all 7972 positions, and the 53K needle at 128K gave the same answer. At 128K, INT8, --tp 4 it fits 4428 experts in VRAM instead of 4182, at the same prompt speed (84.1 tok/s at 53K).
  • The Monitor:
    • STAT lines with the tier keys: experts in VRAM and in pinned RAM, what the CPU computed and what was promoted each token.
    • VRAM lines for the GPU map, built from every device allocation counted by what it holds.

Server, setup and dashboard

  • Setup: maya.py gains a minimax family: download with sha256 per file, tools/mm3/pack.py, the config, and a start check.
    • It picks --tp 4 (or 2) when the GPUs make whole groups, turns on --kv-streaming on, and sets reasoning_effort: max.
    • A setup run again keeps --kv-cache, --kv-resident, --tp and the other engine flags.
  • Tokenizer: a minimax pre-tokenizer in tools/strata_tokenizer.py, checked token for token against HF tokenizers (tools/mm3/tok_check.py).
  • Chat template: MiniMax's own chat_template.jinja, rendered as transformers renders it.
    • <mm:think> reasoning, and ]<]minimax[>[-tagged tool calls through OutputParser(minimax=True).
    • Stop id 200020.
    • Pictures for the engine's own tower (ENGINE_VISION, serve/mm3_vision.py). Videos get a clear 400.
  • Thinking levels: MiniMax's five (low, medium, high, xhigh, max) reach its template by their own names.
    • effort_kwargs adds the client's word as effort_name where it differs from GLM's four, so GLM, Qwen and DeepSeek render as before.
    • The dashboard shows Off / Low / Medium / High / XHigh / Max for MiniMax, with Max as the default and its own saved settings.
  • Dashboard: MiniMax's expert tiers labelled as such (computed on the CPU from pinned RAM), the per-GPU map, and the KV line ("8-bit, streamed: 32768 positions per layer in VRAM, the rest in RAM").

Rebase onto v1.1.27

Two places met main's video input (#248) in serve/server.py. MiniMax's pictures now come from media_of's images, and its token count takes the engine-vision path DeepSeek uses. All 378 server tests pass (9 skipped). In one earlier full run test_server.FailedRestartKeepsContext failed under load; it passes on its own and in the next full run, and this branch doesn't change that code.

Not covered

  • Decode speed deep into a long context with streaming on. The 53K and 6K needle answers are 7 tokens, too short to time.
  • --ppl needs the layer-split engine: --tp returns at most 16 rows of logits per prompt.
  • Tested only on this PC (sm_86 + sm_120, Linux); not on Windows or AMD.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/mw00/project-maya/pull/477 **Author:** [@needmorevram](https://github.com/needmorevram) **Created:** 10/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `minimax-m3.1-flash` --- ### 📝 Commits (10+) - [`d69f718`](https://github.com/mw00/project-maya/commit/d69f718fe8c6974f225a0e105881cc2dba5c3073) maya-mm3: MiniMax-M3.1-Flash (EXL3) - its own engine, first working forward - [`40273ea`](https://github.com/mw00/project-maya/commit/40273ea486466738a8a7ed60071d3e6318b6c288) maya-mm3: decode at 16 tok/s - expert profile, pinned pool, token kernels, CPU lane - [`2801329`](https://github.com/mw00/project-maya/commit/280132927a92005afbce59ba7c110bc64ba3e1b9) maya-mm3: Maya's engine protocol, and MiniMax-M3.1 in the server - [`0471fed`](https://github.com/mw00/project-maya/commit/0471fed2743a317e9e08a64fa3b5a63eea49d3b7) Setup: MiniMax-M3.1-Flash as Maya's third model (maya-mm3) - [`6a628e6`](https://github.com/mw00/project-maya/commit/6a628e6724f2f222d5bf9d656bc86236d8b9ff12) maya-mm3: DSpark drafting - exact, ~1.5x decode - [`2134b60`](https://github.com/mw00/project-maya/commit/2134b60103df4451699f436e57bd3bfd1336a2d4) maya-mm3: DSpark's confidence floor 0.7 by default - [`c35772f`](https://github.com/mw00/project-maya/commit/c35772f9973f807b5420d0ca8f1abb38add0f9bb) maya-mm3: the CPU lane's pool - a late worker can no longer take a job of the next phase - [`6daf756`](https://github.com/mw00/project-maya/commit/6daf756ecdbc2c46c708151bef05f1fa08e98fea) maya-mm3: the staging slots as an expert cache in decode - [`768099e`](https://github.com/mw00/project-maya/commit/768099e3ad84d2a6fc9d9ca3f9fad8e4eb7c6c73) maya-mm3: the expert cache's copies at a forward's end, its slots live two forwards on - [`faf4583`](https://github.com/mw00/project-maya/commit/faf4583cdda88c9e232007c88b5bf9afd9009ffb) maya-mm3: pictures - MiniMax-M3.1-Flash's vision tower in the engine ### 📊 Changes **37 files changed** (+12896 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+11 -0) ➕ `data/expert-profile-mm3.bin` (+0 -0) 📝 `maya.py` (+214 -11) 📝 `serve/frontend.py` (+218 -5) ➕ `serve/mm3_vision.py` (+175 -0) 📝 `serve/server.py` (+40 -18) ➕ `serve/test_minimax_frontend.py` (+140 -0) ➕ `serve/test_mm3_vision.py` (+70 -0) 📝 `serve/web/app.css` (+2 -0) 📝 `serve/web/app.js` (+38 -12) 📝 `serve/web/index.html` (+2 -0) ➕ `src/mm3/mm3_cpu.cpp` (+392 -0) ➕ `src/mm3/mm3_cpu.hpp` (+47 -0) ➕ `src/mm3/mm3_dspark.cu` (+373 -0) ➕ `src/mm3/mm3_dspark.hpp` (+65 -0) ➕ `src/mm3/mm3_exl3.cu` (+2495 -0) ➕ `src/mm3/mm3_exl3.hpp` (+221 -0) ➕ `src/mm3/mm3_geo.hpp` (+72 -0) ➕ `src/mm3/mm3_kernels.cu` (+973 -0) ➕ `src/mm3/mm3_kernels.cuh` (+127 -0) _...and 17 more files_ </details> ### 📄 Description MiniMax-M3.1-Flash as Maya's third model, with its own engine `maya-mm3`, built for the community EXL3 quant [Mia-AiLab/MiniMax-M3.1-Flash-EXL3-EAQ-v1-3.5-bpw](https://huggingface.co/Mia-AiLab/MiniMax-M3.1-Flash-EXL3-EAQ-v1-3.5-bpw) (196.7 GB; its card says no engine had loaded it before). `./setup.sh` offers it beside GLM and DeepSeek, and `maya.py` serves it with chat, tools, all five thinking levels, DSpark drafting, pictures, tensor parallel and a 128K context. GLM's and DeepSeek's engines are untouched. Rebased on main v1.1.27. ## Results One PC: an RTX 3090 and 8 RTX 5060 Ti (152 GB VRAM, each GPU on PCIe 3.0 x8), 183 GB RAM, 2 NUMA nodes. Experts that don't fit in VRAM run on the CPU from pinned RAM, so nothing is read from the SSD after loading. | | decode, code | decode, prose | prompt | |---|---|---|---| | layer split (each GPU a run of layers), plain decode | ~16 tok/s | ~16 tok/s | ~40 tok/s | | layer split + DSpark | 27.7 tok/s | ~19 tok/s | | | **`--tp 4` + DSpark, 8K context** | **38.2 tok/s** | **32.4 tok/s** | **~99 tok/s** (6K) | | `--tp 4` + DSpark, 64K context | ~31 tok/s | ~31 tok/s | | | `--tp 4`, INT8 + streaming, 128K context | | | 84.1 tok/s (53K prompt) | Decode is 300-token greedy answers to a code prompt and a prose prompt. The CPU lane (about 0.55 ms an expert, compute-bound) is what limits code; per-layer round trips and the draft's acceptance limit prose. Quality checks: - `tools/mm3/ref.py`, a torch reference over the EXL3 pack, matches transformers' `MiniMaxM3VL` modules to about 3e-7 on real layers. - Engine vs reference on a 199-token chat: the same top token at 64 of 64 positions, mean KL 0.001 (reference decoding EXL3 the engine's way) and 0.005 (exact). - Needles found at 9K, 30K and 53K tokens, so the sparse block selection retrieves from far back. - Greedy decode with DSpark gives the same tokens as plain decode (128 of 128, at every confidence floor). - `--tp` is deterministic: `MM3_STRESS` repeated one verify window's forward 300 times with the same logits bit for bit. ## What it adds ### maya-mm3: the engine (`src/mm3`) - **The model as MiniMax's code defines it:** - GQA with 64 query / 4 KV heads, per-head QK norm, partial NeoX RoPE (64 of 128 dims, θ 1e7). - MiniMax Sparse Attention in all 60 layers: per KV group and per query, the top 16 blocks of 128 by FP32 index scores, the query's own block forced in. Layers 0-2 are sparse too in M3.1 (llama.cpp's M3 graph makes them dense). - Routing: sigmoid with a correction bias, top 4 of 128 renormalised and scaled 2.0, plus the shared expert. Activation: swigluoai. - **EXL3 read in place** (mul1 codebook, 3-6 bit widths), with its own copy of the EXL3 kernels and the activation built in. The CPU lane runs on the shared CPU EXL3 library unchanged. - **Expert placement:** - An expert profile (`data/expert-profile-mm3.bin`) keeps the most-routed experts in VRAM. - Every other expert is assembled once into a pinned pool, so a miss costs one DMA or one CPU-lane job. - Staging slots double as an expert cache: an expert that keeps coming back is copied in at a forward's end and goes live two forwards later, so runs stay bit-identical. - **Tensor parallel (`--tp 1|2|4`):** - The GPUs form groups: the 3090 alone, then 2 × 4 5060 Ti. - Each member of a group holds its query heads and their KV heads, its index heads, o_proj's columns, and a quarter of every FFN's width. - The host keeps the residual stream. It sums the members' parts in a fixed order (AVX2), routes on the CPU, and runs the experts not in VRAM on the CPU lane as tp sub-experts. - A decode window's work is enqueued up front by a thread per GPU, gated by wait kernels on pinned counters. Prompts go in chunks of 256. - **DSpark drafting** (`--dspark on`): - The pack's 5-layer draft, with its MXFP8 weights read as stored (`mx_rows`). - Taps from layers 3/17/31/45/59, blocks of 7, confidence floor 0.7. - Verification takes the target's own distribution, so sampling is unchanged. - **Pictures** (`--vision on`): the 32-layer vision tower in the engine; the server resizes as `image_processor.py` does. - **KV cache options:** - `--kv-cache int8`: opt-in, one scale per row of 128. On 16K tokens of assistant text, perplexity goes from 6.996 to 7.009 (+0.19%), flat across positions. It's not exact, so BF16 stays the default. - `--kv-streaming on`: the last `--kv-resident` positions (32768 by default) stay in VRAM as a tagged ring; every position also lives in mapped pinned RAM, and attention reads older keys from there. It's exact: 6K logits came out byte for byte the same with it on and off, 8K perplexity matched at all 7972 positions, and the 53K needle at 128K gave the same answer. At 128K, INT8, `--tp 4` it fits 4428 experts in VRAM instead of 4182, at the same prompt speed (84.1 tok/s at 53K). - **The Monitor:** - `STAT` lines with the tier keys: experts in VRAM and in pinned RAM, what the CPU computed and what was promoted each token. - `VRAM` lines for the GPU map, built from every device allocation counted by what it holds. ### Server, setup and dashboard - **Setup:** `maya.py` gains a `minimax` family: download with sha256 per file, `tools/mm3/pack.py`, the config, and a start check. - It picks `--tp 4` (or 2) when the GPUs make whole groups, turns on `--kv-streaming on`, and sets `reasoning_effort: max`. - A setup run again keeps `--kv-cache`, `--kv-resident`, `--tp` and the other engine flags. - **Tokenizer:** a `minimax` pre-tokenizer in `tools/strata_tokenizer.py`, checked token for token against HF `tokenizers` (`tools/mm3/tok_check.py`). - **Chat template:** MiniMax's own `chat_template.jinja`, rendered as transformers renders it. - `<mm:think>` reasoning, and `]<]minimax[>[`-tagged tool calls through `OutputParser(minimax=True)`. - Stop id 200020. - Pictures for the engine's own tower (`ENGINE_VISION`, `serve/mm3_vision.py`). Videos get a clear 400. - **Thinking levels:** MiniMax's five (low, medium, high, xhigh, max) reach its template by their own names. - `effort_kwargs` adds the client's word as `effort_name` where it differs from GLM's four, so GLM, Qwen and DeepSeek render as before. - The dashboard shows Off / Low / Medium / High / XHigh / Max for MiniMax, with Max as the default and its own saved settings. - **Dashboard:** MiniMax's expert tiers labelled as such (computed on the CPU from pinned RAM), the per-GPU map, and the KV line ("8-bit, streamed: 32768 positions per layer in VRAM, the rest in RAM"). ## Rebase onto v1.1.27 Two places met main's video input (#248) in `serve/server.py`. MiniMax's pictures now come from `media_of`'s images, and its token count takes the engine-vision path DeepSeek uses. All 378 server tests pass (9 skipped). In one earlier full run `test_server.FailedRestartKeepsContext` failed under load; it passes on its own and in the next full run, and this branch doesn't change that code. ## Not covered - Decode speed deep into a long context with streaming on. The 53K and 6K needle answers are 7 tokens, too short to time. - `--ppl` needs the layer-split engine: `--tp` returns at most 16 rows of logits per prompt. - Tested only on this PC (sm_86 + sm_120, Linux); not on Windows or AMD. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:44 +07:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#552
No description provided.