feat: support MiniMax-Text-01 (hybrid Lightning/full-attention MoE, MXFP4, TP/PP) - #563
Open
Kritace wants to merge 1 commit into
Open
feat: support MiniMax-Text-01 (hybrid Lightning/full-attention MoE, MXFP4, TP/PP)#563Kritace wants to merge 1 commit into
Kritace wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
interleaves Lightning (linear) attention (70 layers) with full
attention (10 layers) and uses per-layer MoE with a shared expert pool.
csrc/models/minimax_text_01/*(14 files):minimax_text_01_linear_attention— Lightning attention withtoken-by-token recurrent decode and a chunked (block-scan) prefill,
mathematically equivalent to the HF reference (A/B diff ~1e-4);
minimax_text_01_attention(full attention, GQA + partial RoPE),minimax_text_01_fused_moe_experts/sparse_moe_block(TP-aware,MXFP4-capable MoE),
minimax_text_01_decoder_layer,minimax_text_01_for_causal_lm,minimax_text_01_allocate_kv_cache_tensors(hybrid cache: full layers → paged/static KV, linear layers → recurrent
state pool, both split per PP stage).
to shared model code):
python/infinilm/modeling_utils.py—_remap_minimax_text_01weightremapper (qkv split, linear-attn rename, MoE packing);
python/infinilm/infer_engine.py— recognizeattn_type_list-basedmodels as mamba-cache models (MiniMax is identified and driven through the
existing hybrid-cache engine path);
python/infinilm/processors/minimax_text_01_processor.py— request↔stateslot mapping for the Lightning state pool.
is chunked (default chunk 64,
INFINILM_LIGHTNING_CHUNK/ config override tofall back to the token-by-token path).
Motivation
MiniMax-Text-01 is a widely used open-weight model with a novel hybrid
attention architecture (Lightning linear attention + full attention + MoE) that
InfiniLM did not previously support. This PR adapts it following the project's
model-adapter conventions (
MODELS.md/CONTRIBUTING.md), keeping all changesnon-invasive (no edits to framework-shared code,
llama_legacy/orauto_config.py). A chunked prefill optimization is included because thetoken-by-token Lightning recurrence was the prefill bottleneck
(~6.3× speed-up at seq=2048 on a single 4090D).
Type of Change
feat— new feature / new modelfix— bug fixperf— performance improvement (no behavioral change; chunked prefillis numerically equivalent to the recurrent path, A/B diff ~1e-4)
refactor/test/docs/build/ci/choreTest Results of Involved Models on Supported Platforms
examples/test_infer.pynum_blocks=128): prompt rendered, 32 tokens sampled, response printed. Reproduced in three configurations with bit-identical sampled token sequences (local RTX 3050 / server single 4090D / server TP=2), greedy determinism confirming cross-environment/TP consistency — see Run Logs below.examples/bench.pybench.pyruns end-to-end and reports prefill/decode metrics on a 4090D: input_len 16 → prefill TTFT 295.9 ms, decode avg ITL 2.61 ms (~383 tok/s); input_len 32 → TTFT 3.2 ms, decode ITL 2.03 ms (~494 tok/s). Real-weight numbers require the official 456B checkpoint.test/bench/test_benchmark.pyinference_server.py+scripts/test_perf.pyGET /v1/models→minimax_text_01_small;POST /v1/chat/completions→ 200 with a 16-token completion (finish_reason=length, usage 14/16). The fulltest_perf.pyload test needs real weights to be meaningful.Platforms tested:
examples/test_infer.py, synthetic small weights):Real-456B end-to-end tests remain blocked by the ~913 GB bf16 (or ~228 GB
MXFP4, needs 6×80GB+) official checkpoint — please tag a reviewer with access
to such resources if this must be completed in-repo.
Numeric correctness matrix (all PASS, synthetic small weights vs. HF
reference and vs. single-GPU baseline):
Run Logs
Single request — 4×4090D server, single GPU (
total_time: 360.27 ms):Single request — 4×4090D server, TP=2 distributed (
total_time: 498.21 ms):Single request — local WSL, RTX 3050 (
total_time: 1384.23 ms):Offline performance —
examples/bench.py(4×4090D server, single GPU):Service —
inference_server.py(OpenAI-compatible,curlagainst port8011):
Reproduction / Deployment Command
Once the official checkpoint (or an MXFP4-converted copy) is available, the
model runs through the standard entry points on NVIDIA, e.g. distributed:
Synthetic-weight reproduction used for this PR (single-request demo above) is
examples/test_infer.py --model <small-synthetic-checkpoint> --enable-paged-attn --disable-prefix-caching, which completes end-to-end on 1 GPU and under TP=2.Benchmark / Performance Impact
Chunked Lightning prefill vs. the previous token-by-token recurrence
(single 4090D, small model, 3 runs min):
ms (seq 1024/2048/4096); default
64, upper bound512, chunk0/1keepsthe recurrent path. Chunked vs. recurrent outputs differ only by bf16
accumulation order (max ≈1.2e-4).
Notes for Reviewers
csrc/models/minimax_text_01/; theonly shared-file touches are standard extension points (weight-remap entry,
mamba-cache detection in
infer_engine.py, new processor) — same pattern asqwen3_next/kimi_k3/videonsa.attention_biasread from config (official hard-codesfalse); partial RoPE (
rotary_dim);postnormresidual vialayernorm_*_alpha/beta.quant_method == "quark"(packed per-expert MoE +linear), reusing project MXFP4 ops; converter kept out-of-PR (no data files).
minimax_m1(same architecture) registration;real-456B end-to-end + service once weights are available; the
paged-compiler/graph path is not exercised for the Lightning state pool
(mamba-cache) — the model runs eager (chunked prefill + recurrent decode).
CI / ChatOps
CI does not run automatically on pull requests. Trigger it manually (Actions →
CI, branch: this PR's head) or ask a maintainer to
/retest. Formattingcheck (
scripts/format.py --check) passes for all changed files(clang-format-21 / ruff).
Checklist
Title, Branch, and Commits
feat: support MiniMax-Text-01 (hybrid Lightning/full-attention MoE, MXFP4, TP/PP).<type>/xxx-...—feat/minimax-text-01.feat:commit (17 files vs. upstream).
fixup!/squash!/wip.Scope and Design
Changes are minimal (new model dir + the standard Python extension
points only; exactly 17 files vs. upstream).
No dead code / debug prints / unowned TODOs.
No unrelated formatting churn (only the new dir's own formatting).
N/A — no public API change (new files only; no signature/behavior change to
existing callers).
General Code Hygiene
(41 Chinese comment lines translated in this branch).
C++ Specific
only init-list initializes a single member; others assign in the body).
new/delete; RAII/smart pointers only.scripts/format.py(clang-format-21,--checkpasses).
csrc/models/llama_legacy/.Python Specific
scripts/format.py(ruff passes).python/infinilm/auto_config.py.Testing
examples/test_infer.py) passed (synthetic weights;local + server + server TP=2, see table/logs).
examples/bench.py) passed (workflow-level,synthetic weights; metrics in table/logs).
inference_server.py) passed (workflow-level OpenAI smoke).end-to-end tests — author to tag one when opening the PR.
Build, CI, and Tooling
on the 4×4090D cluster).
/retestrequested — to be doneonce the PR is open.
Documentation
README.md/CONTRIBUTING.mdbehavior or build-flag change outsidethe new model dir (the model list is not maintained in README).
Security and Safety
checks (only pointer casts are read-only index views).