Repository navigation
feat(minimax_m3): add bounded MiniMax-M3.1-Flash continuation #2803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
willg-nv
wants to merge
10
commits into
NVIDIA:main
Choose a base branch
from
willg-nv:bringup/minimax-m3-1-flash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,434
−18
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b813889
feat(minimax_m3): add bounded text continuation
willg-nv 6705758
fix(minimax_m3): link logits JSON dependency
willg-nv 342e1c4
fix(minimax_m3): report declared E2E case ID
willg-nv c8906bb
fix(minimax_m3): tighten precision and tokenizer checks
willg-nv 3fd7117
fix(minimax_m3): build native tokenizer test consumers
willg-nv f6e8797
fix(minimax_m3): explicitly reject zero-mass routing
willg-nv a589546
test(minimax_m3): cover two-token continuation
willg-nv 22b6a32
fix(minimax_m3): reject empty added tokens
willg-nv 3095bf4
fix(minimax_m3): ship a native TensorRT precision plugin
willg-nv 31e8e4a
fix(minimax_m3): bound prefix encoding and pin bundle reads
willg-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # MiniMax M3.1 Flash | ||
|
|
||
| The `minimax_m3` family implements a bounded text continuation path for | ||
| `MiniMaxAI/MiniMax-M3.1-Flash`, revision | ||
| `ce7f4df87d2e05262f5775f373dac4772f134041`. It owns the checkpoint mapping, | ||
| TensorRT graphs, staged weight loading, NFC byte-level BPE tokenizer, greedy | ||
| generation, and validation. | ||
|
|
||
| The initial Task is `text_continuation`, with raw UTF-8 text or token IDs as | ||
| the decoder prefix. Chat templating, images, video, DSpark, sampling, batching, | ||
| parallelism, streaming, and KV caching are not implemented by this path. | ||
|
|
||
| ## Build and run | ||
|
|
||
| Use the repository development environment with TensorRT 11.1 or newer and | ||
| ICU development libraries (`libicu-dev` on Ubuntu). Python dependencies are | ||
| provided by the repository's base environment. No | ||
| family-specific Python package installation is required. | ||
|
|
||
| ```bash | ||
| cmake -S . -B build -DTRTMC_BUILD_TESTS=ON | ||
| cmake --build build --parallel 12 --target \ | ||
| trtmc trtmc_backend_trt trtmc_model_minimax_m3 \ | ||
| test_minimax_m3_sdk_c test_minimax_m3_sdk_cpp test_bundle_format_v1 | ||
| export PYTHONPATH=core/builder:apps/benchmark:. | ||
| export CMAKE_PREFIX_PATH="$PWD/build${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}" | ||
| export LD_LIBRARY_PATH="$PWD/build${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" | ||
| python -m tensorrt_model_connect build MiniMaxAI/MiniMax-M3.1-Flash \ | ||
| --revision ce7f4df87d2e05262f5775f373dac4772f134041 \ | ||
| --precision bf16 --max-sequence-length 128 --output minimax-m3.bundle | ||
|
|
||
| build/trtmc run minimax-m3.bundle --runtime-root "$PWD/build" \ | ||
| --task text_continuation --prompt 'The capital of France is' \ | ||
| --set max_new_tokens=1 | ||
| ``` | ||
|
|
||
| The builder preserves BF16 activation boundaries and disables TF32. Projection | ||
| reductions use format-aware integer arithmetic when lossless encoding and range | ||
| checks establish that the sum fits; otherwise they use FP32 GEMM. The original | ||
| MXFP8 projection codes/scales and NVFP4 expert codes/scales remain unchanged. | ||
| This is not a new quantization or calibration pass. The native runtime expands | ||
| only projections needed for the current stage and passes their values through | ||
| the ordinary backend Tensor API. | ||
|
|
||
| The family-owned TensorRT plugin evaluates Gemma normalization, the small router, | ||
| rotary products, causal attention reductions, and the weighted expert merge in | ||
| FP64 before the specified FP32/BF16 rounding boundaries. Attention scores and probabilities | ||
| retain FP32 boundaries; final vocabulary logits use FP32 GEMM. These precision | ||
| reductions limit summation noise before quantization. | ||
| The native wheel provides the precision plugin in `libtrtmc_model_minimax_m3.so`. | ||
| For source builds, include the native build directory in `CMAKE_PREFIX_PATH`, | ||
| as shown above. The family registers its plugin before deserializing engine | ||
| plans. Rebuild MiniMax M3 bundles created with earlier precision plans. | ||
| Rotary tables are calculated in FP64 before FP32 storage; rotation products | ||
| are reduced before the FP32/BF16 boundaries. All model topology, kernels, and | ||
| orchestration remain inside this family. The runtime validates each bundle | ||
| against the required precision and input-scaling contract. | ||
|
|
||
| NVFP4 activation rounding compares values against scaled FP4 midpoints in the | ||
| graph, including round-to-even ties. This avoids reciprocal-scale rounding | ||
| moving an exact midpoint to the wrong FP4 level. The regression sweep checks | ||
| all BF16 mantissas across 17 exponents, including subnormal FP8 scales. | ||
|
|
||
| The first routed-expert GEMM uses the pinned per-token NVFP4 input recipe: | ||
| `outer = max(row_absmax, 1e-4) / 2688`, FP8 scales per 16 values, and FP4 | ||
| round-to-even codes. The outer multiplier is applied in the projection epilogue | ||
| before BF16 conversion. The second expert GEMM retains the published unit | ||
| static activation global scale. Dyadic regression cases cover multiple token | ||
| amplitudes, including inputs that a missing outer multiplier collapses to zero. | ||
| This follows the pre-dispatch contract in SGLang's pinned `sgl-deep-gemm==0.2.7`. | ||
|
|
||
| A router row with zero selected score mass has no normalized mixture. The | ||
| kernel marks its weights as NaN before division. The native Task rejects the | ||
| request before dispatching routed experts. The independent reference equation | ||
| also produces NaN for that row. | ||
|
|
||
| All 60 decoder layers, 128 routed experts per MoE layer, the four-expert router, | ||
| shared experts, Gemma RMS norms, partial RoPE, and the checkpoint's clipped | ||
| SwiGLU-OAI activation are retained. For prefixes within one 128-token block, | ||
| the mandatory local sparse block covers all causal keys. All checkpoint index | ||
| value paths are disabled. The initial graph therefore implements that exact | ||
| bounded case without an indexer that cannot change the selected key set. | ||
| Requests beyond the configured total prefix/output capacity are rejected. | ||
|
|
||
| Build capacity is between 2 and 128 tokens, default 128 when unspecified. | ||
| `max_new_tokens` is the only Task Config field and defaults to 2. Decoding | ||
| recomputes the full prefix for each output token. Native inference requires | ||
| neither Python nor the original checkpoint directory. The large bundle keeps | ||
| its packed source weights on disk and uses bounded section ranges to read the | ||
| current tensors; callers must keep the bundle available during inference. | ||
|
|
||
| The checkpoint is approximately 250 GB. Building uses additional temporary | ||
| space for staged bundle sections and the final bundle. The staged execution | ||
| path bounds resident weight memory at the cost of host decoding and transfers. | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| It is an initial correctness path, not a latency or throughput qualification. | ||
|
|
||
| Local validation uses one NVIDIA Blackwell GPU (compute capability 10.3) with | ||
| 143 GiB of visible GPU memory, 251 GiB of host RAM, and TensorRT 11.4 on | ||
| Linux x86-64. These capacities describe the validation machine. Minimum | ||
| memory requirements have not been measured. | ||
|
|
||
| ## Validate | ||
|
|
||
| The family oracle independently evaluates the complete 60-layer text model in | ||
| PyTorch with BF16 activation boundaries and explicit FP32 rounding points, using | ||
| the published checkpoint and equations from SGLang commit | ||
| `b2568f706b5caa2daf800355b015b042d8dbb535`. It preserves dynamic MXFP8/NVFP4 | ||
| activation rounding and original packed weight values. It does not import the | ||
| TensorRT graph or runtime implementation. Reductions use FP64 to establish the | ||
| value before FP32/BF16 rounding. Independent rational cancellation, BF16 tie, | ||
| weighted-sum, Decimal normalization, sigmoid, rotary, and attention fixtures | ||
| verify the rounding behavior. This oracle checks the declared precision profile; it does | ||
| not reproduce the accumulation order of an upstream fused serving kernel. | ||
|
|
||
| The direct E2E compares six intermediate layer outputs and final full-vocabulary | ||
| logits (relative L2 below `1e-2`, cosine above `0.9999`), then requires an exact | ||
| greedy token and text match through the CLI and public C/C++ SDKs. The manifest | ||
| exercises an explicit one-token request and a two-token request using the | ||
| default configuration. The independent oracle recomputes logits after the | ||
| first generated token to check the second decode step. The C++ | ||
| consumer repeats a request through one loaded Task. Both SDK consumers inspect | ||
| owned results after releasing the model wrapper. Native tokenizer IDs and | ||
| decoded text are compared against the checkpoint tokenizer on English, Arabic, | ||
| Chinese, normalization, whitespace, number, contraction, and special-token cases. | ||
|
|
||
| ```bash | ||
| export LD_LIBRARY_PATH="$PWD/build${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" | ||
| export TRTMC_BINARY="$PWD/build/trtmc" | ||
| export TRTMC_RUNTIME_ROOT="$PWD/build" | ||
| export TRTMC_NATIVE_BUILD_DIR="$PWD/build" | ||
| export CMAKE_PREFIX_PATH="$PWD/build${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}" | ||
| export TRTMC_MINIMAX_M3_MODEL_DIR=/path/to/pinned/checkpoint | ||
| PYTHONPATH=core/builder:apps/benchmark:. python -m pytest \ | ||
| families/minimax_m3/tests --e2e-model minimax_m3 -q -s | ||
| ctest --test-dir build -R '^bundle_format_v1$' --output-on-failure | ||
| ``` | ||
|
|
||
| Set `TRTMC_MINIMAX_M3_BUNDLE` only to reuse an already-built bundle. Tests still | ||
| execute the independent reference and real native inference. The manifest pins | ||
| the checkpoint and declares the prompt and build profile. These cases do not | ||
| establish corpus-level accuracy, chat/vision/video support, | ||
| long-context behavior, performance, or other hardware/TensorRT cohorts. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """MiniMax M3 sparse mixture-of-experts text continuation.""" |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.