[WIP] DeepSeek-V3.2 model support#3800
Conversation
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
Thanks for the proposal. I wonder what's your thought on supporting DeepSeek V4 #3634 vs. V3.2 |
|
@tianyu-l Thanks for the quick response. For context: we've been maintaining V3.2 and V4 on our internal version of torchtitan, and would like to polish and contribute them upstream. We're also actively improving the V4 PR (#3634); these are parallel efforts. Currently DeepSeek-V3.2 is put in a separate folder. Would you prefer merging it into the existing DeepSeek-V3 directory instead, since it's more of a variant of the original V3, to keep the model directory cleaner? FMPV, V3.2 is simpler, while also being able to exercise new features like indexer loss and sparse attentions. We'd appreciate your thoughts on any potential concerns, and are willing to iterate based on the project's direction. |
| config.model_spec = model_registry("debugmodel") | ||
| config.parallelism = ParallelismConfig( | ||
| tensor_parallel_degree=2, | ||
| spmd_backend="full_dtensor", |
There was a problem hiding this comment.
we are migrating from full_dtensor to spmd_types -- would you be interested in help migrate this model?
There was a problem hiding this comment.
Sure, will investigate this.
| deepseekv32_configs = { | ||
| "debugmodel": _debugmodel, | ||
| } |
There was a problem hiding this comment.
this is debugmodel only, can we add real configs?
There was a problem hiding this comment.
would benefit from a README.md listing out the distributed training techniques supported and verified, including parallelisms, per-layer compilation, activation checkpointing, etc.
There was a problem hiding this comment.
Please report numerics compared with HF native impl. See https://github.com/pytorch/torchtitan/tree/main/scripts/checkpoint_conversion for more details. We don't have to land the custom scripts, but good to convince ourselves.
There was a problem hiding this comment.
OK, thanks for the pointer, I briefly tested with fp32 against DeepSeek-V3.2 HF, confirmed bitwise-exact logits given CosSinRoPE is modified per #3787. Will share a more comprehensive result later.
Updated in 7.14:
Moved code into
deepseek_v3, and with first attempt for indexer loss.Adds the DeepSeek-V3.2 (DeepSeek-V3.2-Exp) transformer model with Lightning Indexer + DeepSeek Sparse Attention (DSA). Based on DeepSeek-V3 modeling in torchtitan, and this PR depends on #3787.
Indexer— Lightning Indexer for sparse token selectionwq_bfrom the MLA latent query), and key (viawk) into a low-rank index space.LayerNorm(k_norm), non-interleaved RoPE (rotate-half, usingCosSinRoPEwith yarn-scaled frequencies), and a Hadamard rotation to both index query and key.weights_proj).select()computes\sum_h \mathrm{relu}(q_h\cdot k) \cdot w_h, masks with the causal+document attention mask, and returns a per-token boolean selection via top-k.DSAFlexAttention— fused sparse inner attentionFlexAttention. CallsIndexer.selectto get the per-token selection, composes it with the document mask into a combinedBlockMask, then delegates to standardflex_attentionwith that sparse mask.build_dsa_block_maskbuilds the combinedBlockMask.Attention— V3 MLA + Indexer + DSAAttention. In addition to the MLA q/k/v projections, it runs theIndexeron(x, qr)and passes the index tensors intoDSAFlexAttention.Sharding
wq_b/weights_projcolwiseS(0)@TP;wk/k_norm/ rope cacheReplicate@TP.Replicate@TP(q/k/v are gathered for the indexer KL loss;idx_*are gathered forselect()'s reduce_sum over index heads). Theout_srcisReplicate@TP(truthful, since the inputs are replicated), andout_dstreshards toS(2)@TPto feed the rowwisewo.TODO
in_dst = Replicate@TPon q/k/v already prepares for).