[PR #490] [CLOSED] maya-mm3 (needs #477 first): prompts ~4.5x faster, decode up to 13% faster, GPU-side sampling candidates, opt-in rotated INT8 K/V, a MiniMax tool-call fix #562

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

📋 Pull Request Information

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

Base: main ← Head: mm3-perf


📝 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

42 files changed (+14919 additions, -48 deletions)

View changed files

📝 CMakeLists.txt (+11 -0)
➕ data/expert-profile-mm3.bin (+0 -0)
📝 maya.py (+214 -11)
📝 serve/frontend.py (+246 -5)
➕ serve/mm3_vision.py (+175 -0)
📝 serve/server.py (+40 -18)
➕ serve/test_minimax_frontend.py (+155 -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_cands.hpp (+33 -0)
➕ src/mm3/mm3_cpu.cpp (+443 -0)
➕ src/mm3/mm3_cpu.hpp (+50 -0)
➕ src/mm3/mm3_dspark.cu (+404 -0)
➕ src/mm3/mm3_dspark.hpp (+75 -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 (+1357 -0)

...and 22 more files

📄 Description

Depends on #477. Please merge #477 first. This branch is built on #477's minimax-m3.1-flash. Until #477 is merged, this PR's diff also shows #477's commits; its own changes are the last two: 8f1bfa4 (tool calls) and c5a9042 (the engine).

Speed and fixes for maya-mm3, the MiniMax-M3.1-Flash engine from #477. They come from studying llama.cpp's MiniMax-M3 support and exllamav3 1.6.4. Prompts read about 4.5× faster and decode up to 13% faster. Every change is exact: perplexity doesn't move, and the checks below compare bits where they can. Also new: an opt-in rotation that cuts the INT8 K/V cache's perplexity cost by about three-quarters, and a fix for MiniMax tool calls whose parameter admits a string or null.

Results

One PC: an RTX 3090 and 8 RTX 5060 Ti (PCIe 3.0 x8 each), --tp 4, DSpark on. "Before" is #477's binary on the same PC. "Server settings" are the default config's: 128K context, --kv-cache int8 --kv-streaming on.

Prompts

before after
6,099 tokens, 16K context 62.0 s (98.3 tok/s) 17.2 s (355 tok/s), 3.6×
53,225 tokens, server settings 632 s (84.2 tok/s) 141 s (377.7 tok/s), 4.5×

On the 6K prompt, the 1024-token chunk alone gives 207 tok/s, and the pipeline over the three GPU groups takes it to 349. On the 53K prompt, the pipeline is worth about 1.9×: 189 tok/s without it (that run also had the CPU cold experts on).

Decode (tok/s): 300-token answers through the serve protocol, each case three times in one process, warm runs. Single command-line runs swing ±20% on this machine.

before after
code, greedy, 8K context 40.1–40.3 45.4–45.5
prose, greedy, 8K 34.1–35.5 36.1–36.7
code, greedy, server settings 38.0–39.7 39.5–40.8
prose, greedy, server settings 29.8–32.0 31.2–32.7
code, temperature 1, server settings (mean of 3) 38.9 39.0
prose, temperature 1, server settings (mean of 3) 31.2 32.6

Perplexity, 16K tokens of assistant text:

perplexity
before (prompt chunks of 256) 6.995
after (chunks of 1024) 7.001
chunks of 2048 6.989
layer-split engine (reference) 6.996
INT8 K/V 7.008
INT8 K/V, --kv-rotate on 6.998

A change of prompt chunk size moves single rows' logits more than rounding would suggest: MSA's top-16 block picks are discrete. The layer-split engine moves as much between its own chunk sizes. Perplexity is the measure that matters, and it doesn't change.

What changes

Prompts (mm3_tp.cu)

  • Chunks of --tp-chunk tokens (1024, was 256): an expert not in VRAM is copied in once a chunk instead of once per 256 tokens.
  • A pipeline over the GPU groups: a host thread per group, and a residual buffer per chunk in flight, so the 3090 and the two 5060 Ti groups each work on their own chunk. MM3_TP_PIPE=0 takes one chunk at a time; the logits are bit-identical either way.
  • Staged experts copied on each member's copy stream while it runs the experts already in VRAM.
  • Prompts keep the decode's promoted experts. Promotions hold at most prom_cap slots; the rest are reserved for a prompt's staging, which never takes a promoted slot while another is free.
  • Less prompt scratch:
    • Positions are made on the device.
    • p_zero and p_out are gone.
    • The dense and shared FFNs' gate/up rows live in p_y.
    • That gives back about 75 MB per GPU for experts.
  • --ppl works with --tp (Model::forward_ppl): the head runs on each chunk's rows as the chunk finishes.
  • Opt-in:
    • --tp-ffn-rows N runs the FFN half in slices of N tokens. The bits are the same. At 256: 37 more experts in VRAM at the server settings, prompts 13% slower.
    • MM3_PROMPT_CPU runs a chunk's coldest experts on the CPU lane meanwhile; it was 4% slower once the pipeline was on.

Decode

  • MSA block scores: the grid also spans ranges of key blocks, where a verify window used to run 2 thread blocks walking every key block. The block picks read their score row from shared memory. The bits are the same.
  • NaN scores: a row of NaN scores now gives -1 picks instead of an index past the cache, which used to fault.
  • sparse_attn: a verify window's queries are split 16 ways over their kept blocks and combined in split order. A query's split doesn't depend on T, so the token path and the windows still agree bit for bit.
  • wait_pull: waiting on the host's counter and reading its rows is one kernel, off the copy engine. The window's positions and the draft's inputs are also made on the device, so none of them queue behind the expert cache's promotion copies (28 MB experts on the 3090). Drafting time had been swinging between 7.6 and 16.8 ms.
  • CPU lane: gate/up, its bands and down's row sums run as one dispatch whose jobs start as soon as their inputs are done. That's two barriers per call instead of four, with the same arithmetic, and about 10% less time per expert (tests/mm3_lane_test.cpp).
  • Sampling candidates on the GPU (Model::forward_cands): a sampled row's top_k, plus the penalised ids, is picked on the head's GPU with a radix select. That replaces copying 800 KB of logits per row to the host and sorting them there. mm3_sample.hpp's dist_c gives the whole row's distribution from them; ties are now broken by id in both.
  • Opt-in:
    • MM3_TP_HOST_ROUTER: router logits on the host. It saves a round trip but reads 171 MB of router weights per window, about +6 ms.
    • MM3_SAMPLED_DRAFTS: drafts drawn from the draft's own distribution, with speculative sampling's acceptance and residual. It keeps about 3% more drafts at temperature 1, but the draws cost more than that.
    • --dspark-cost X: cuts the drafts where their confidences' product falls below X.

INT8 K/V: --kv-rotate on (opt-in, with --kv-cache int8)

q, k and v rows go through a 128-point Hadamard transform before the INT8 rows' scales, and attention's output is rotated back. That spreads an outlier over its row before quantization: perplexity is 6.998 against 7.008 without it.

Server

MiniMax tool calls keep a string-admitting parameter's value as a string. Before, {"type": ["string","null"]} turned "12345" into 12345. The rule follows llama.cpp's may_be_string; covered by serve.test_minimax_frontend.

Checks

  • New engine, old prompt settings: with chunk 256, no pipeline and no CPU experts, its logits are bit-identical to #477's. The pipeline and --tp-ffn-rows don't change a bit either.
  • Verify window: repeated 300 times (MM3_STRESS, --no-promote), identical logits every time.
  • Greedy DSpark: identical to plain decoding for 128 of 128 tokens with --no-promote. With promotions on, both #477 and this branch drift apart, because promotions move experts between the CPU and the GPU.
  • tests/mm3_kernels_test.cu, on the 3090 and a 5060 Ti:
    • MSA scores and picks are bit-identical to a CPU reference, including a NaN query.
    • Split attention is within 6e-7 of F64.
    • Rotated INT8 attention error is 7.7e-3 against 1.3e-2 without the rotation.
    • topk_rows equals host_cands.
    • The sampled Markov step and wait_pull work.
  • tests/mm3_sampler_test.cpp: candidates against the whole row, 13,107 of 13,107 distributions the same. Sampled drafts' output stays within sampling noise of p (total variation ≤ 0.002 over 2M draws).
  • Python tests: serve.test_minimax_frontend, serve.test_tools, serve.test_stop and serve.test_server pass (142 tests, 2 skipped).
  • End to end through maya.py:
    • a chat
    • a tool call with a ["string","null"] parameter
    • a code word found in a 9.7K-token prompt
    • a sampled answer

Not covered

  • Only the tensor-parallel path's prompts are pipelined. The layer-split engine gets the kernel changes and --kv-rotate only.
  • The 3090's one-GPU group still goes through the host every layer (estimated at about 0.5%).
  • Tested only on this PC (sm_86 and sm_120, Linux).

🤖 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/490 **Author:** [@needmorevram](https://github.com/needmorevram) **Created:** 10/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `mm3-perf` --- ### 📝 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 **42 files changed** (+14919 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` (+246 -5) ➕ `serve/mm3_vision.py` (+175 -0) 📝 `serve/server.py` (+40 -18) ➕ `serve/test_minimax_frontend.py` (+155 -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_cands.hpp` (+33 -0) ➕ `src/mm3/mm3_cpu.cpp` (+443 -0) ➕ `src/mm3/mm3_cpu.hpp` (+50 -0) ➕ `src/mm3/mm3_dspark.cu` (+404 -0) ➕ `src/mm3/mm3_dspark.hpp` (+75 -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` (+1357 -0) _...and 22 more files_ </details> ### 📄 Description > **Depends on #477. Please merge #477 first.** This branch is built on #477's `minimax-m3.1-flash`. Until #477 is merged, this PR's diff also shows #477's commits; its own changes are the last two: 8f1bfa4 (tool calls) and c5a9042 (the engine). Speed and fixes for `maya-mm3`, the MiniMax-M3.1-Flash engine from #477. They come from studying llama.cpp's MiniMax-M3 support and exllamav3 1.6.4. Prompts read about 4.5× faster and decode up to 13% faster. Every change is exact: perplexity doesn't move, and the checks below compare bits where they can. Also new: an opt-in rotation that cuts the INT8 K/V cache's perplexity cost by about three-quarters, and a fix for MiniMax tool calls whose parameter admits a string or null. ## Results One PC: an RTX 3090 and 8 RTX 5060 Ti (PCIe 3.0 x8 each), `--tp 4`, DSpark on. "Before" is #477's binary on the same PC. "Server settings" are the default config's: 128K context, `--kv-cache int8 --kv-streaming on`. **Prompts** | | before | after | |---|---|---| | 6,099 tokens, 16K context | 62.0 s (98.3 tok/s) | 17.2 s (355 tok/s), 3.6× | | 53,225 tokens, server settings | 632 s (84.2 tok/s) | 141 s (377.7 tok/s), 4.5× | On the 6K prompt, the 1024-token chunk alone gives 207 tok/s, and the pipeline over the three GPU groups takes it to 349. On the 53K prompt, the pipeline is worth about 1.9×: 189 tok/s without it (that run also had the CPU cold experts on). **Decode** (tok/s): 300-token answers through the serve protocol, each case three times in one process, warm runs. Single command-line runs swing ±20% on this machine. | | before | after | |---|---|---| | code, greedy, 8K context | 40.1–40.3 | 45.4–45.5 | | prose, greedy, 8K | 34.1–35.5 | 36.1–36.7 | | code, greedy, server settings | 38.0–39.7 | 39.5–40.8 | | prose, greedy, server settings | 29.8–32.0 | 31.2–32.7 | | code, temperature 1, server settings (mean of 3) | 38.9 | 39.0 | | prose, temperature 1, server settings (mean of 3) | 31.2 | 32.6 | **Perplexity**, 16K tokens of assistant text: | | perplexity | |---|---| | before (prompt chunks of 256) | 6.995 | | after (chunks of 1024) | 7.001 | | chunks of 2048 | 6.989 | | layer-split engine (reference) | 6.996 | | INT8 K/V | 7.008 | | INT8 K/V, `--kv-rotate on` | 6.998 | A change of prompt chunk size moves single rows' logits more than rounding would suggest: MSA's top-16 block picks are discrete. The layer-split engine moves as much between its own chunk sizes. Perplexity is the measure that matters, and it doesn't change. ## What changes ### Prompts (`mm3_tp.cu`) - **Chunks of `--tp-chunk` tokens** (1024, was 256): an expert not in VRAM is copied in once a chunk instead of once per 256 tokens. - **A pipeline over the GPU groups:** a host thread per group, and a residual buffer per chunk in flight, so the 3090 and the two 5060 Ti groups each work on their own chunk. `MM3_TP_PIPE=0` takes one chunk at a time; the logits are bit-identical either way. - **Staged experts copied on each member's copy stream** while it runs the experts already in VRAM. - **Prompts keep the decode's promoted experts.** Promotions hold at most `prom_cap` slots; the rest are reserved for a prompt's staging, which never takes a promoted slot while another is free. - **Less prompt scratch:** - Positions are made on the device. - `p_zero` and `p_out` are gone. - The dense and shared FFNs' gate/up rows live in `p_y`. - That gives back about 75 MB per GPU for experts. - **`--ppl` works with `--tp`** (`Model::forward_ppl`): the head runs on each chunk's rows as the chunk finishes. - **Opt-in:** - `--tp-ffn-rows N` runs the FFN half in slices of N tokens. The bits are the same. At 256: 37 more experts in VRAM at the server settings, prompts 13% slower. - `MM3_PROMPT_CPU` runs a chunk's coldest experts on the CPU lane meanwhile; it was 4% slower once the pipeline was on. ### Decode - **MSA block scores:** the grid also spans ranges of key blocks, where a verify window used to run 2 thread blocks walking every key block. The block picks read their score row from shared memory. The bits are the same. - **NaN scores:** a row of NaN scores now gives `-1` picks instead of an index past the cache, which used to fault. - **`sparse_attn`:** a verify window's queries are split 16 ways over their kept blocks and combined in split order. A query's split doesn't depend on T, so the token path and the windows still agree bit for bit. - **`wait_pull`:** waiting on the host's counter and reading its rows is one kernel, off the copy engine. The window's positions and the draft's inputs are also made on the device, so none of them queue behind the expert cache's promotion copies (28 MB experts on the 3090). Drafting time had been swinging between 7.6 and 16.8 ms. - **CPU lane:** gate/up, its bands and down's row sums run as one dispatch whose jobs start as soon as their inputs are done. That's two barriers per call instead of four, with the same arithmetic, and about 10% less time per expert (`tests/mm3_lane_test.cpp`). - **Sampling candidates on the GPU** (`Model::forward_cands`): a sampled row's top_k, plus the penalised ids, is picked on the head's GPU with a radix select. That replaces copying 800 KB of logits per row to the host and sorting them there. `mm3_sample.hpp`'s `dist_c` gives the whole row's distribution from them; ties are now broken by id in both. - **Opt-in:** - `MM3_TP_HOST_ROUTER`: router logits on the host. It saves a round trip but reads 171 MB of router weights per window, about +6 ms. - `MM3_SAMPLED_DRAFTS`: drafts drawn from the draft's own distribution, with speculative sampling's acceptance and residual. It keeps about 3% more drafts at temperature 1, but the draws cost more than that. - `--dspark-cost X`: cuts the drafts where their confidences' product falls below X. ### INT8 K/V: `--kv-rotate on` (opt-in, with `--kv-cache int8`) q, k and v rows go through a 128-point Hadamard transform before the INT8 rows' scales, and attention's output is rotated back. That spreads an outlier over its row before quantization: perplexity is 6.998 against 7.008 without it. ### Server MiniMax tool calls keep a string-admitting parameter's value as a string. Before, `{"type": ["string","null"]}` turned `"12345"` into 12345. The rule follows llama.cpp's `may_be_string`; covered by `serve.test_minimax_frontend`. ## Checks - **New engine, old prompt settings:** with chunk 256, no pipeline and no CPU experts, its logits are bit-identical to #477's. The pipeline and `--tp-ffn-rows` don't change a bit either. - **Verify window:** repeated 300 times (`MM3_STRESS`, `--no-promote`), identical logits every time. - **Greedy DSpark:** identical to plain decoding for 128 of 128 tokens with `--no-promote`. With promotions on, both #477 and this branch drift apart, because promotions move experts between the CPU and the GPU. - **`tests/mm3_kernels_test.cu`, on the 3090 and a 5060 Ti:** - MSA scores and picks are bit-identical to a CPU reference, including a NaN query. - Split attention is within 6e-7 of F64. - Rotated INT8 attention error is 7.7e-3 against 1.3e-2 without the rotation. - `topk_rows` equals `host_cands`. - The sampled Markov step and `wait_pull` work. - **`tests/mm3_sampler_test.cpp`:** candidates against the whole row, 13,107 of 13,107 distributions the same. Sampled drafts' output stays within sampling noise of p (total variation ≤ 0.002 over 2M draws). - **Python tests:** `serve.test_minimax_frontend`, `serve.test_tools`, `serve.test_stop` and `serve.test_server` pass (142 tests, 2 skipped). - **End to end through `maya.py`:** - a chat - a tool call with a `["string","null"]` parameter - a code word found in a 9.7K-token prompt - a sampled answer ## Not covered - Only the tensor-parallel path's prompts are pipelined. The layer-split engine gets the kernel changes and `--kv-rotate` only. - The 3090's one-GPU group still goes through the host every layer (estimated at about 0.5%). - Tested only on this PC (sm_86 and sm_120, Linux). 🤖 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:52 +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#562
No description provided.