Repository navigation
Compute DeepSeek-V4 router logits in fp32 - #5849
AusarYao28 wants to merge 1 commit into
Conversation
|
🤖 Hi @AusarYao28, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
|
🤖 Hi @AusarYao28, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
The DeepSeek-V4 reference Gate always projects router logits in fp32 (linear(x.float(), weight.float())), but deepseek4-284b.yml inherits float32_gate_logits: false, so bf16 runs route on bf16 logits and flip experts. - Set float32_gate_logits: true in src/maxtext/configs/models/deepseek4-284b.yml (config-only; same setting as the qwen3.5 fp8 model configs). - Validated on v5p-8 bf16 against the fp32 reference on real Flash weights: layers 3-6 h_out rel_l2 8.21e-2 -> 2.44e-2, router.3 top-k slot overlap 0.886 -> 0.996, dh_in 0.213 -> 0.064; layers 41-42 + head pass all checks. FIXES: b/566474598
fab2d5e to
a3ac525
Compare
There was a problem hiding this comment.
📋 Review Summary
Verdict: Spec met; core config setting lacks automated regression test coverage.
Top issues:
- [Tests] Core requirement is not covered by automated regression tests in CI (see inline comment on
src/maxtext/configs/models/deepseek4-284b.yml). → Add a test verifyingcfg.float32_gate_logits is Truefordeepseek4-284b(mirroringDeepSeekV4ProConfigSmokeTestintests/unit/flop_calculation_test.py) or registerdeepseek4-284b.ymlinDEEPSEEK_CONFIGSintests/unit/configs_test.py. - [Spec]
src/maxtext/configs/models/deepseek4-tiny.ymlstill inheritsfloat32_gate_logits: falsefrombase.yml, leaving CPU testing ondeepseek4-tinydivergent from V4-Pro and V4-Flash router behavior. → Confirm whetherdeepseek4-tiny.ymlshould also enablefloat32_gate_logits: truefor consistency across all DeepSeek-V4 configs.
Inferred spec & validation
- Sources: PR description; linked Buganizer ticket b/566474598 (not readable here);
src/maxtext/configs/models/deepseek4-284b.yml;src/maxtext/configs/models/deepseek4-1600b.yml;src/maxtext/configs/base.yml. - Problem:
deepseek4-284b.ymlomittedfloat32_gate_logits, inheritingfalsefrombase.ymland causing router logits to project in bfloat16 instead of float32, which diverged from the official reference and flipped top-$k$ expert selection near boundaries.
| Spec item | Implementation | Validating test |
|---|---|---|
R1 (stated): deepseek4-284b.yml sets float32_gate_logits: true so MoE router projections run in fp32 |
✅ | ❌ none (configs_test.py omits deepseek4-284b.yml; deepseek_v4_routed_bias_test.py overrides the flag via CLI) |
| R2 (inferred): DeepSeek-V4 test configs mirror production router precision | deepseek4-tiny.yml still inherits false) |
❌ none |
| C1 (inferred): YAML syntax and schema validation remain valid | ✅ preserved | ❌ none (configs_test.py does not include deepseek4-284b.yml) |
| C2 (inferred): Other model families without explicit overrides retain default behavior | ✅ preserved | tests/unit/configs_test.py ✅ |
| log_moe_bias_norms: false | ||
| routed_scaling_factor: 1.5 | ||
| # Reference Gate computes router logits in fp32 (linear(x.float(), weight.float())) regardless of model dtype. | ||
| float32_gate_logits: true |
There was a problem hiding this comment.
🟡 The new config setting is unvalidated by automated regression tests in CI. While the PR description cites tests/unit/configs_test.py and tests/unit/deepseek_v4_routed_bias_test.py, deepseek4-284b.yml is omitted from DEEPSEEK_CONFIGS in configs_test.py, and deepseek_v4_routed_bias_test.py sets float32_gate_logits explicitly via CLI args rather than validating model config defaults.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Description
The official DeepSeek-V4 reference
Gatealways projects MoE router logits infloat32(linear(x.float(), weight.float())). Whiledeepseek4-1600b.ymlsetsfloat32_gate_logits: true,src/maxtext/configs/models/deepseek4-284b.ymlinheritedfloat32_gate_logits: falsefrombase.yml, causingbfloat16runs on DeepSeek-V4-Flash (deepseek4-284b) to project router logits inbfloat16and flip top-$k$ expert selections near decision boundaries.float32_gate_logits: trueinsrc/maxtext/configs/models/deepseek4-284b.yml, matchingdeepseek4-1600b.ymland the official reference implementation.FIXES: b/566474598
Tests
tests/unit/configs_test.py(81 passed),tests/unit/deepseek_v4_routed_bias_test.py(4 passed).yamllintandcodespellclean.v5p-128(deepseek4-284b,float32_gate_logits: true, official bf16 golden): PASS,KL[0] = 0.0429,max KL divergence = 0.116(Log: https://cloudlogging.app.goo.gl/XtFn6fS4w15PdhQk9 ).Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.