feat(models): load the original MiniMax-M3.1-Flash mxfp8+NVFP4 export
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 8/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- huggingface, rust
- Ambito
- machine-learning
Direzione di ricerca
Start with the loader entry points: load_minimax_m3_vl in src/loading/vlm_minimax_m3_vl.rs and MiniMaxM3Model::load with sanitize_weights in src/models/minimax_m3.rs, then the NVFP4 pass in src/models/sanitize.rs. The new prepare_original_checkpoint step goes in src/models/minimax_m3_checkpoint.rs, with tests in src/models/minimax_m3_checkpoint_tests.rs. Done means those tests pass, the router and e_score_correction_bias stay float32, and a logit trace matches the mlx-lm reference, which needs a 256 GB host.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
mlxcel cannot load MiniMax's own release of MiniMax M3.1, MiniMaxAI/MiniMax-M3.1-Flash (model_type: minimax_m3_vl, about 224 GB). The checkpoint mixes MXFP8 (weight_scale_inv E8M0 group scales) for attention, the indexer and the shared expert, compressed-tensors NVFP4 for the routed experts, and an unquantized float32 router. The earlier expectation that #3169's compressed-tensors NVFP4 pass covers it does not hold, as traced below. This issue makes the original checkpoint load and run through both the text and VLM loaders, with the router kept in float32.
Upstream reference
ml-explore/mlx-lm#2003 (59995f1), now at https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/minimax_m3_vl/checkpoint.py and https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/minimax_m3_vl/model.py:
- MXFP8: for every
{p}.weight_scale_inv, rename it to{p}.scalesand view{p}.weight(e4m3 bytes) asuint32; that is MLX's nativemxfp8layout (group 32, 8 bits). The loader setsquantization = {group_size: 32, bits: 8, mode: "mxfp8"}forquant_method: "mxfp8"(https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/utils.py), and per-layer modes are inferred from the scales (infer_quant_config: uint8 scales at 4 bits / group 16 arenvfp4). - Compressed-tensors NVFP4 experts:
{p}.weight_packedviewed asuint32becomes{p}.weight,{p}.weight_scalebecomes{p}.scales,{p}.global_scale = 2688 / weight_global_scale,input_global_scaleis dropped; per-expertglobal_scaleis stacked with the expert weights. cast_predicatekeepse_score_correction_biasandblock_sparse_moe.gate.*out of dtype casting: "Keep the router in float32 so expert selection matches the original."
What the checkpoint holds
Hub API and safetensors headers, 2026-11-23. The id MiniMaxAI/MiniMax-M3.1 returns 401 (not public); the public release is MiniMaxAI/MiniMax-M3.1-Flash, architecture MiniMaxM3SparseForConditionalGeneration, 89632 tensors in 48 shards.
quantization_config:{"quant_method": "mxfp8", "activation_scheme": "dynamic", "weight_block_size": [1, 32], "group_size": 16, "moe_quant_algo": "NVFP4", "moe_quant_format": "nvfp4-pack-quantized"}withignored_layerscovering everyblock_sparse_moe.gate,lm_head,model.embed_tokens,vision_tower,multi_modal_projectorandpatch_merge_mlp.- MXFP8 layers (
self_attn.{q,k,v,o}_proj,self_attn.index_{q,k}_proj,block_sparse_moe.shared_experts.{gate,up,down}_proj):weightF8_E4M3[out, in],weight_scale_invU8[out, in/32]. - Routed experts
block_sparse_moe.experts.N.{w1,w2,w3}:weight_packedU8[out, in/2],weight_scaleF8_E4M3[out, in/16],weight_global_scaleandinput_global_scaleF32 scalars. - Router
block_sparse_moe.gate.weightF32[128, 6144];block_sparse_moe.e_score_correction_biasF32[128]; norms, embeddings,lm_headand the vision tower BF16.
Current mlxcel behavior
src/models/detection.rs:959routesminimax_m3_vltoload_minimax_m3_vl(src/loading/vlm_minimax_m3_vl.rs:43), which reads weights throughload_vlm_weights_common(:70). Its finishing passfinish_vlm_weights_common(src/loading/vlm.rs:383) applies the bf16-to-f16 policy andapply_native_global_scale_flags_to_subset, but never callssanitize_modelopt_nvfp4_weights(src/models/sanitize.rs:1264), soweight_packed/weight_global_scaleare never rewritten on the VLM path.- On the text path (
MiniMaxM3Model::load,src/models/minimax_m3.rs:292-301),load_text_weightsruns the NVFP4 pass only whenis_modelopt_nvfp4_text_checkpoint(sanitize.rs:1443) accepts the config, andcompressed_tensors_nvfp4_as_modelopt(sanitize.rs:1362) requiresquant_method: "compressed-tensors"withformat: "nvfp4-pack-quantized". This checkpoint declaresquant_method: "mxfp8"withmoe_quant_format, so #3169's detection returnsNoneon both paths. - Nothing in
src/models/minimax_m3*.rshandles.weight_scale_inv.fp8_block(src/models/fp8_block.rs:148) is Qwen-specific and accepts onlyquant_method: "fp8"with 128x128 blocks. ModelArgs::group_size()/bits()(src/models/minimax_m3_config.rs:202-211) default to 64 / 4 when there is noquantizationblock, so every MXFP8UnifiedLinearwould be read with the wrong group geometry even after a rename.minimax_m3::sanitize_weights(src/models/minimax_m3.rs:359) is called by both loaders and only drops vision keys, rewrites thelanguage_model.prefix and drops MTP layers.- The parts that already work: the router input is cast to float32 (
src/models/minimax_m3_moe.rs:166); the routerUnifiedLinear(:205) stays a regular f32 linear when the plane has no scales; per-expert NVFP4global_scalesidecars stack intoinv_global_scale(stack_individual_experts_with_count,src/models/switch_layers.rs:1441); the bf16-to-f16 conversion touches only bf16 tensors, so the F32 router and bias survive it.is_model_quantized(vlm.rs:475) reads onlyquantization, so the BF16 norms, embeddings,lm_headand vision tower convert to f16 on Apple Silicon; that matches the non-quantized-weight rule, and there are no bf16 quantization scales in this checkpoint for the "keep bf16 scales" rule to protect.
#3201 (ModelOpt MIXED_PRECISION) is a different declaration (quant_method: "modelopt", per-layer FP8 / NVFP4 with hf_quant_config.json) and does not cover this one; share helpers with it rather than duplicating them if it lands first.
Required changes
- New
src/models/minimax_m3_checkpoint.rs(keepsminimax_m3.rsfocused), withpub(crate) fn prepare_original_checkpoint(weights: &mut WeightMap, config: &Value) -> Result<bool, String>that is a no-op (Ok(false)) unless the config (top level ortext_config) declaresquant_method: "mxfp8". When it does:- Every
{p}.weight_scale_invwith a U8 / F8_E4M3 weight beside it: move it to{p}.scalesandmlxcel_core::viewthe weight asUINT32([out, in/4]). Reject aninnot divisible by 32, a scale shape other than[out, in/32], or aweight_scale_invthat is not uint8 (that would be the 128x128 float layoutfp8_blockhandles), with an error naming the key. - Run the existing
sanitize_modelopt_nvfp4_weights(weights, Some(config))socompressed_tensors_nvfp4_to_modelopt_tripletsand the repack turn the expert triplets into native NVFP4 planes withglobal_scalesidecars. Dropinput_global_scale. Do not write a second NVFP4 converter. - Leave
block_sparse_moe.gate.*ande_score_correction_biasuntouched (float32). - Layout facts this relies on (index of the checkpoint): layers 0 to 2 are dense (
moe_layer_freqstarts[0, 0, 0, 1, ...]) with MXFP8mlp.{gate,up,down}_projundermlp., not underblock_sparse_moe, so the rename covers them and no dense-under-MoE remap is needed; the routed experts are namedw1/w2/w3, whichexpert_proj_names(src/models/minimax_m3_moe.rs:77) maps to gate/down/up onceexperts.0.w1.weightexists, so the NVFP4 rewrite (which turnsweight_packedintoweight) must run beforeMoeBlock::from_weights; and the expert planes' mode comes from their packed shapes (src/models/switch_layers.rs:1177-1195, words per group 2 isnvfp4at group 16), not from the 32 / 8 default.
- Every
- Config: when the declaration is detected, insert
quantization: {"group_size": 32, "bits": 8, "mode": "mxfp8"}into the text config beforeModelArgsis parsed (bothMiniMaxM3Model::loadandload_minimax_m3_vl:49-58), followingfp8_block::merge_fp8_block_quantization's rule that an explicitquantizationwins. Per-plane mode inference (infer_plane_quantization_mode,src/lib/mlxcel-core/src/layers.rs) then reads the NVFP4 expert planes as group-16nvfp4from their scales. Confirmgate_bits()(minimax_m3_config.rs:217) cannot quantize the scale-less router. - Call
prepare_original_checkpointfrom both loaders immediately beforesanitize_weights(after the vision tower has been built from the raw keys in the VLM loader, so the BF16 tower is unaffected). Updatesanitize_weights's doc comment to say which loader calls what. - Do not change
is_model_quantizedor the global bf16-to-f16 policy here; record the decision in the module doc.
Acceptance criteria
-
src/models/minimax_m3_checkpoint_tests.rs:mxfp8_weight_scale_inv_becomes_native_scalesbuilds a tiny[64, 64]E4M3 plane with a U8[64, 2]weight_scale_invand asserts{p}.scalesexists, the weight isUINT32 [64, 16], and aUnifiedLinearloaded from it with group 32 / 8 bits reports modemxfp8and matches a dense dequantized reference within 1e-3. Fails today (the key is unknown). - Same file:
compressed_tensors_experts_load_under_mxfp8_declarationbuilds twoexperts.N.w1NVFP4 triplets under aquant_method: "mxfp8"config and asserts they become stacked native NVFP4 planes with a two-elementinv_global_scale, and thatinput_global_scaleis gone. Fails today on both paths. - Same file:
router_and_bias_stay_f32writes a syntheticminimax_m3_vldirectory to a temp dir (pattern ofsrc/loading/vlm_mage_vl_tests.rs) holding an F32 router, an F32 bias and a BF16 norm, runs the same sequenceload_minimax_m3_vlruns (load_vlm_weights_common, thenprepare_original_checkpoint, thensanitize_weights), and asserts the router weight ande_score_correction_biasare float32 afterwards while the norm followed the bf16-to-f16 policy. - Same file: a config without
quant_method: "mxfp8"leaves the weight map unchanged (mlx-community conversions keep loading byte-identically). - Wired into the real flow:
mlxcel generate,mlxcel-serverand theminimax_m3text route load the original checkpoint; no flag is needed.
Validation
Checkpoint: MiniMaxAI/MiniMax-M3.1-Flash, about 224 GB on disk (206.6 G U8 elements, 10.6 G F8, 3.3 G BF16, 46 M F32), so it runs on the 256 GB+ host, not a 128 GB box. Download model-*.safetensors and the configs (the repo also carries a dspark/ drafter directory that is not needed).
make verify-test
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
./target/release/mlxcel generate -m models/MiniMax-M3.1-Flash -p "Explain the difference between TCP and UDP." -n 256
./target/release/mlxcel generate -m models/MiniMax-M3.1-Flash --image tests/fixtures/test_image_shapes.png -p "Describe the image." -n 128
Loading the original planes changes which arithmetic runs, so per CLAUDE.md "Changes that move the numbers" report a teacher-forced trace (examples/logit_trace.rs, scripts/compare_logit_traces.py --decided 2) against an mlx-lm main reference that loads the same original checkpoint (scripts/mlx_lm_logit_trace.py, same arguments as logit_trace); upstream's own check was that long generations match. Record peak RSS and decode tok/s.
Related
#3169 (compressed-tensors NVFP4 text checkpoints; detection does not fire here), #3201 (ModelOpt MIXED_PRECISION), #764 (MiniMax-M3-VL port), #2411 (compressed-tensors FP8). Upstream: ml-explore/mlx-lm#2003.
- Lingua principale
- Rust
- Stelle
- 505
- Fork
- 81
- Merge medio
- 14h 2m
- PR unite (30g)
- 448
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di lablup/mlxcel
-
area:core priority:high status:ready type:security
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
priority:medium status:ready type:security
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
area:models modeltype:text priority:medium status:in-progress type:bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 57/100
I maintainer di solito rispondono entro 1 giorno
-
area:models priority:low status:ready type:test
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
area:models modeltype:omni priority:medium status:ready type:bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di lablup/mlxcel
Issue simili
-
area:ui effort:medium enhancement P7 source:agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
machine rename accepts a label already used by another machine, making --machine <label> ambiguousApertamaintainer-needed p2 remote triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug help wanted ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
userFRM/egui-charts#4605 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno