[None][feat] Add AD custom model for MiMo-V2-Flash - #239
Conversation
| self.weight = nn.Parameter(torch.empty((self.n_routed_experts, config.hidden_size))) | ||
| self.e_score_correction_bias = nn.Parameter(torch.empty(self.n_routed_experts)) | ||
|
|
||
| def forward(self, hidden_states: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]: |
There was a problem hiding this comment.
consider using the torch.ops.trtllm.noaux_tc_op ?
|
please make sure to rebase |
|
[AGENT] Pushed fixes addressing the FP8 checkpoint loading and Triton kernel issues: Commit 2: FP8 fixes (
|
|
Some more todos:
|
|
[AGENT] Rebased and addressed reviewer feedback: Changes in this push:
Status of e2e runThe three main issues encountered during e2e:
GPUsAll 8 GPUs currently have ~43GB memory used by another process. Cannot run clean e2e test right now. Will re-run once GPUs are available. Verified
|
|
Add AutoDeploy custom model implementation for the XiaomiMiMo/MiMo-V2-Flash family. This is a complex architecture with hybrid attention (full causal + sliding window), MoE with 256 experts and noaux_tc routing, partial rotary embeddings, different Q/K vs V head dims, and attention sink bias. Key features: - Hybrid attention: layer-level full/SWA pattern with different RoPE thetas - Partial rotary: only rope_dim of head_dim gets RoPE applied - Different head dims: Q/K use head_dim=192, V uses v_head_dim=128 - MoE: noaux_tc routing in vanilla PyTorch (sigmoid + bias + group topk) - Attention sink bias on SWA layers via torch_attention canonical op - Uses canonical AD ops: torch_attention, torch_rope_with_explicit_cos_sin, torch_moe, torch_rmsnorm Files: - tensorrt_llm/_torch/auto_deploy/models/custom/modeling_mimo_v2_flash.py - tests/unittest/auto_deploy/singlegpu/models/test_mimo_v2_flash_modeling.py - Updated __init__.py with registration Signed-off-by: Lucas Liebenwein <lliebenwein@nvidia.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
…2 fallback Two fixes for FP8 quantized checkpoint support: 1. FP8 weight_scale_inv padding: Some checkpoints (e.g., MiMo-V2-Flash) pad weight_scale_inv tensors to multiples of the block size. When the weight dimension is not a multiple of 128, the checkpoint stores extra scale rows. The quantization load_hook now slices padded scales to match the expected shape derived from the actual weight dimensions. 2. Triton FP8 matmul non-power-of-2 fallback: After TP sharding, weight dimensions may not be powers of 2 (e.g., 192, 384). The HF Triton kernel (w8a8_block_fp8_matmul_triton) requires power-of-2 block dims. Added a dequant+cuBLAS fallback in torch_fake_quant_finegrained_fp8_linear matching the existing fallback in trtllm_finegrained_fp8_linear. Also updated MiMo-V2-Flash registry entry from world_size_8 to world_size_4 since the model has num_key_value_heads=4 (minimum for full attention layers) which cannot be evenly sharded across 8 GPUs. Signed-off-by: Lucas Liebenwein <lliebenwein@nvidia.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
…fallback Three fixes for MiMo-V2-Flash end-to-end support: 1. V-padding for uniform head_dim: Pad V from v_head_dim (128) to head_dim (192) before torch_attention so Q/K/V all have the same last dimension. The AD cached attention transform expects uniform head_dim. Output is sliced back to v_head_dim after attention. 2. Disable fuse_finegrained_fp8_moe: The trtllm fused MoE kernel fails with NVRTC compilation error for 256-expert FP8 MoE (same as MiniMax-M2). Use torch-simple compile backend as fallback. 3. Chat template fallback: AD's input processor wraps message content in multimodal list-of-dicts format, but text-only models like MiMo-V2-Flash have chat templates that expect plain strings. Added try/except fallback to use plain string format when list-of-dicts fails. Signed-off-by: Lucas Liebenwein <lliebenwein@nvidia.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
|
[AGENT] E2E run results — Step 1 (5 layers, 4 GPUs) PASSED Changes pushed
Reproduce (step 1 — reduced layers, 4 GPUs)CUDA_VISIBLE_DEVICES=0,1,2,3 python examples/auto_deploy/build_and_run_ad.py \
--model XiaomiMiMo/MiMo-V2-Flash \
--args.model-kwargs.num-hidden-layers=5 \
--use-registryRaw output (5 layers — generation is garbage as expected)Generation is nonsensical because only 5 of 48 layers are loaded — the model can't produce coherent text. This confirms the pipeline works end-to-end. Full model (48 layers) — OOMWith Unit testspytest tests/unittest/auto_deploy/singlegpu/models/test_mimo_v2_flash_modeling.py -vKnown limitations
|
|
NOTE: downgrading to draft PR for now as this requires support for heterogenous q/k vs v head_dim which is not supported in our attention backend atm. Will get back to it later |
Summary
torch_attentioncanonical opArchitecture highlights
hybrid_layer_pattern, GQA (4/8 KV heads)Files
tensorrt_llm/_torch/auto_deploy/models/custom/modeling_mimo_v2_flash.py— Custom modeltests/unittest/auto_deploy/singlegpu/models/test_mimo_v2_flash_modeling.py— Unit teststensorrt_llm/_torch/auto_deploy/models/custom/__init__.py— RegistrationCanonical ops used
torch.ops.auto_deploy.torch_attention(with sinks + sliding_window)torch.ops.auto_deploy.torch_rope_with_explicit_cos_sintorch.ops.auto_deploy.torch_moetorch.ops.auto_deploy.torch_rmsnormAD end-to-end run
The MiMo-V2-Flash checkpoint on HuggingFace is pre-quantized with FP8 (
quant_method: fp8,weight_block_size: [128, 128]). During the e2e run, weight loading fails with a shape mismatch onweight_scale_invtensors because the checkpoint pads FP8 scales to multiples of 128 (e.g., k_proj weight is [768, 4096] → scale_inv is [8, 32] instead of [6, 32]). This is a pre-existing AD framework limitation with FP8-padded checkpoints, not a custom model issue. The custom model weights and architecture are verified correct via comprehensive unit tests.Reproduce command (will hit the FP8 scale mismatch):
Registry entry
Already present in
models.yaml:Test plan
Run unit tests:
Test hierarchy:
torch_export_to_gmwith dynamic batch+seq dims🤖 Generated with Claude Code