[None][feat] Add AD custom model for DeepSeek-V3.2 family#232
Conversation
Add AutoDeploy custom model for the DeepSeek-V3.2 model family (deepseek-ai/DeepSeek-V3.2, DeepSeek-V3.2-Speciale, nvidia/DeepSeek-V3.2-NVFP4). The core forward path (MLA + MoE + RMSNorm + YaRN RoPE) is identical to DeepSeek-V3. V3.2 adds: - Indexer module (sparse attention selection) in every layer - included for weight loading but not used in forward (no-op for seq <= index_topk=2048) - MTP (Multi-Token Prediction) layers - extra decoder layers included for weight loading but not used for main logits Config subclasses DeepseekV3Config from transformers, adding V3.2-specific fields (index_head_dim, index_n_heads, index_topk, num_nextn_predict_layers). Also fixes FP8 tensor indexing in the shared MLA RoPE de-interleaving hook (mla_rope_utils.py) which is needed for FP8-quantized checkpoints. Files: - modeling_deepseek_v32.py: Custom model implementation - __init__.py: Registration - mla_rope_utils.py: FP8 support for de-interleaving - test_deepseek_v32_modeling.py: Hierarchical tests + HF V3 equivalence Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
lucaslie
left a comment
There was a problem hiding this comment.
I don't see any outputs from build_and_run_ad.py? please make sure to post it no matter if it's coherent or not
| cos, sin = self.rotary_emb(hidden_states, seq_len=kv_seq_len) | ||
| cos = cos[position_ids] | ||
| sin = sin[position_ids] |
There was a problem hiding this comment.
nit: do it once per model and just pass it into attention. This is wasteful
There was a problem hiding this comment.
[AGENT] Fixed in dc33142. Moved rotary_emb to DeepSeekV32Model level. cos/sin are now computed once in the model forward and passed pre-sliced to all layers.
| base=self.rope_theta, | ||
| ) | ||
|
|
||
| def forward( |
There was a problem hiding this comment.
I don't see indexer being used in the self.forward?
There was a problem hiding this comment.
[AGENT] Correct — the Indexer is intentionally NOT used in the forward path. It exists solely for weight loading compatibility (the checkpoint stores indexer weights in every attention layer). The torch_mla canonical op handles causal attention natively. For sequences <= index_topk (2048), the Indexer is a no-op in the original model. This is documented in the docstring at line 333-340.
Add deepseek_v2_ep.yaml to V3.2 registry entries to enable attention data parallelism. MLA attention is replicated, experts use EP. This avoids FP8 scale sharding issues with the q_b_proj LoRA projection. Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
|
[AGENT] AD End-to-End Run Results Run 1: Without attention DP (TP-only sharding)Stages completed:
Error: Fix: Added Run 2: With attention DP (
|
| Stage | Run 1 (TP only) | Run 2 (Attention DP) |
|---|---|---|
| Export | OK | OK |
| Transform matching | OK (MLA=5, MoE=2) | OK (MLA=5, MoE=2) |
| Weight loading (FP8) | OK | OK |
| Sharding | FAIL (FP8 scale) | OK |
| Cache init | - | OK |
| First forward | - | FAIL (FP8 matmul assertion) |
Both failures are in the FP8 infrastructure (sharding scale splits, triton block matmul), not in the custom model code.
- Move rotary_emb from per-attention to DeepSeekV32Model level - Compute cos/sin once in model forward and pass pre-sliced to layers - Attention and decoder layer forward now take (cos, sin) instead of position_ids - Update all tests for new forward signature Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
lucaslie
left a comment
There was a problem hiding this comment.
we might have to hold off on merging this PR and get some more detailed human eyes on it
Summary
model_type: deepseek_v32)deepseek-ai/DeepSeek-V3.2deepseek-ai/DeepSeek-V3.2-Specialenvidia/DeepSeek-V3.2-NVFP4mla_rope_utils.py)Architecture
DeepSeek-V3.2 is architecturally identical to V3 in the core forward path (MLA + MoE + RMSNorm + YaRN RoPE). V3.2 adds:
Indexer module (sparse attention selection) — present in every attention layer. Included for checkpoint weight loading but NOT used in the forward path. The
torch_mlacanonical op handles causal attention natively. For sequences <=index_topk(2048), the Indexer is effectively a no-op in the original model.MTP (Multi-Token Prediction) layers — extra decoder layers with additional modules (
embed_tokens,eh_proj,enorm,hnorm,shared_head). Included for weight loading but not used in the main logits path.Config —
DeepseekV32ConfigsubclassesDeepseekV3Configfrom transformers, adding V3.2-specific fields.Canonical ops used
torch_rmsnorm,torch_mla,torch_moe,torch_rope_with_explicit_cos_sinMoE routing (plain PyTorch)
The
noaux_tcrouting uses vanilla PyTorch: sigmoid + bias + group topk + normalize + scale.FP8 fix
The RoPE de-interleaving hook in
mla_rope_utils.pynow handles FP8 tensors by temporarily casting through float32 for the index operation.AD e2e run results (reduced layers,
num_hidden_layers=5)Known limitations
Test plan
Generated with Claude Code