Skip to content

feat(minimax): support MiniMax-Text-01 and MiniMax-M2 - #583

Open
y258dd wants to merge 8 commits into
InfiniTensor:InfiniLM-v0.2.9cfrom
y258dd:feat/minimax-model-support
Open

y258dd wants to merge 8 commits into
InfiniTensor:InfiniLM-v0.2.9cfrom
y258dd:feat/minimax-model-support

Conversation

@y258dd

@y258dd y258dd commented Sep 19, 2026

Copy link
Copy Markdown

Summary

  • Add MiniMaxForCausalLM support under csrc/models/minimax/.
  • Support hybrid full-attention and lightning linear-attention layers.
  • Support MiniMax-style indexed recurrent state pools for prefill and decode.
  • Add the MiniMax block-sparse MoE path with a dense fallback.
  • Add the _remap_minimax HuggingFace weight remapper in python/infinilm/modeling_utils.py.
  • Add MiniMax operator, smoke, and HuggingFace-aligned end-to-end tests under test/models/minimax/.

Motivation

MiniMax-Text-01 and MiniMax-M2 use hybrid attention and a recurrent linear-attention state. The linear-attention path evaluates:

ratio   = exp(-slope)
state   = ratio * state + outer(k_t, v_t)
out_t   = q_t @ state

The recurrent state is read from initial_state[initial_state_indices[b]] and written to initial_state[final_state_indices[b]]. This model adaptation is needed to run MiniMax models in InfiniLM.

Closes # (N/A: internal model-support work; no tracking issue in this fork)

Type of Change

  • feat — new feature / new model
  • fix — bug fix
  • perf — performance improvement (no behavioral change)
  • refactor — code restructuring without behavior change
  • test — adding or fixing tests only
  • docs — documentation only
  • build / ci — build system or CI configuration
  • chore — tooling, formatting, or other non-code changes
  • Breaking change

Test Results of Involved Models on Supported Platforms (Please attach screenshots)

Platform Test Result Notes
CPU MiniMax lightning attention operator Passed Matches NumPy reference
CPU MiniMax smoke prefill/decode Passed State continuity error 1.16e-10
CPU MiniMax vs HF transformers Passed Prefill 5.59e-4, decode 1.59e-4
NVIDIA MiniMax model-level tests Pending Planned on RTX 4090 / sm_89
Ascend New-architecture InfiniOps operator 24/24 passed Separate InfiniOps PR #995; not this old-architecture branch

Not yet run:

  • examples/test_infer.py: pending NVIDIA/real-model validation.
  • examples/bench.py: no performance claim.
  • test/bench/test_benchmark.py: pending.
  • python/infinilm/server/inference_server.py + scripts/test_perf.py: pending.

Benchmark / Performance Impact

N/A. This PR adds model support and does not claim performance improvements.

Notes for Reviewers

  • The PR targets the InfiniLM-v0.2.9c branch as requested by the administrator.
  • The model supports both minimax and minimax_m2 model types.
  • The linear-attention implementation requires the companion lightning_attention InfiniCore operator.
  • The current CPU tests use num_experts=1, which exercises the dense fallback. The full multi-expert MoE comparison is the next validation step.
  • The source state row is never modified; the destination row is written only after all tokens have been processed.
  • The old-architecture NVIDIA model-level tests are still pending; this PR is intentionally opened as a draft until that validation is complete.

CI / ChatOps

CI does not run automatically on pull requests. Trigger it manually from the Actions tab, or ask a maintainer to comment /retest or /test on this PR.


Checklist

Title, Branch, and Commits

  • PR title follows Conventional Commits: feat(minimax): support MiniMax-Text-01 and MiniMax-M2.
  • Branch name follows <type>/xxx-yyyy-zzzz: feat/minimax-model-support.
  • Each commit message follows Conventional Commits.
  • This is a two-commit PR; each commit is focused and meaningful.
  • No fixup!, squash!, or wip commits remain.
  • Branch is based directly on InfiniLM-v0.2.9c, not the refactored main branch.

Scope and Design

  • Changes are limited to MiniMax model support, tests, and related documentation.
  • No debug prints or stray TODO/FIXME were found in the MiniMax source and test paths.
  • No unrelated formatting churn is intended.
  • No public API changes are introduced.

General Code Hygiene

  • Added files end with a newline.
  • No trailing whitespace or BOMs are intended.
  • Comments and error messages are in English.
  • Changed files have not yet been run through scripts/format.py on this branch.

C++ Specific

  • Google C++ formatting and scripts/format.py verification are still pending.
  • No raw new/delete were intentionally introduced.
  • No changes or references to csrc/models/llama_legacy/.

Python Specific

  • scripts/format.py verification is still pending.
  • No changes or references to python/infinilm/auto_config.py.

Testing

  • CPU operator test passed.
  • CPU smoke test passed.
  • CPU HuggingFace alignment test passed.
  • NVIDIA model-level test is pending on the old architecture branch.
  • Single request test was not run yet.
  • Offline performance test was not run; no performance claim.
  • Sanity benchmark test was not run yet.
  • Service test was not run yet.

Build, CI, and Tooling

  • The model was built and tested on CPU in the archived branch.
  • CI has not been triggered for this branch yet.

Documentation

  • MiniMax model documentation was added under docs/minimax/.

Security and Safety

  • No secrets, tokens, private URLs, or personal hardware identifiers are intentionally included.
  • No third-party code was added.
  • No unsafe pointer arithmetic was intentionally introduced.

NVIDIA RTX 4090 / sm_89 Validation (2026-09-19)

Validated with:

  • InfiniCore feat/minimax-lightning-attention at 7bcaa623
  • InfiniLM feat/minimax-model-support at e23eba79
  • RTX 4090, compute capability sm_89, driver 570.124.06, CUDA 12.8 (V12.8.61)
  • PyTorch 2.6.0a0+ecf3bae40a.nv25.01 with CUDA 12.8, torch.cuda.is_available() == True
  • Python 3.12.3, g++ 13.3.0, xmake 3.1.1+20260919

Results

Test Device Result Error
MiniMax lightning attention operator NVIDIA Passed decode: out 4.768e-07, state 2.384e-07; prefill: out 1.907e-06, state 4.768e-07
MiniMax smoke prefill/decode NVIDIA Passed finite logits; state continuity 3.127381e-06
MiniMax vs HuggingFace, 1 expert, FP32 NVIDIA Passed prefill 5.257875e-04; decode 2.117679e-04
MiniMax vs HuggingFace, 4 experts, top-2, FP16 NVIDIA Passed prefill 7.324219e-04; decode 3.662109e-04

All tests are below the 1e-2 model-level tolerance. The 4-expert top-2 result exercises the CUDA Fused MoE path rather than the dense fallback.

Validation Commands

source /data/InfiniCore/scripts/set_env_linux.sh
cd /data/InfiniLM

MINIMAX_DEVICE=cuda python3 test/models/minimax/test_lightning_attention_op.py
MINIMAX_DEVICE=cuda python3 test/models/minimax/smoke_minimax.py
MINIMAX_DEVICE=cuda python3 test/models/minimax/test_minimax_vs_hf.py

MINIMAX_DEVICE=cuda \
MINIMAX_TORCH_DTYPE=float16 \
MINIMAX_NUM_LOCAL_EXPERTS=4 \
MINIMAX_NUM_EXPERTS_PER_TOK=2 \
python3 test/models/minimax/test_minimax_vs_hf.py

Fixes Included

  • CUDA Lightning Attention now supports FP16 and BF16 in addition to FP32.
  • MiniMax linear-attention state uses the model dtype instead of always allocating FP32.
  • Sampling offsets are copied to host before host-side indexing on CUDA.
  • HuggingFace MiniMax MoE weights are remapped from block_sparse_moe.experts.{i}.{w1,w2,w3} to moe.experts.{i}.{gate_proj,up_proj,down_proj} and block_sparse_moe.gate to moe.gate.
  • Lightning-attention GPU tests use disjoint initial/final state rows to avoid cross-request races.

Server Logs

  • /data/minimax-final-gpu-op.log
  • /data/minimax-final-gpu-smoke.log
  • /data/minimax-final-gpu-vs-hf.log
  • /data/minimax-gpu-test-moe4-top2-fp16-final.log

@y258dd
y258dd marked this pull request as ready for review September 19, 2026 09:24
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