Repository navigation
Add DeepSeek-V4 HyperHead, align Sinkhorn implementation, and add parity tests - #4337
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
d596a57 to
1395bae
Compare
parambole
left a comment
There was a problem hiding this comment.
nit: Could you please make the PR title more descriptive ?
|
🤖 Hi @RissyRan, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
|
🤖 I'm sorry @RissyRan, but I was unable to process your request. Please see the logs for more details. |
RissyRan
left a comment
There was a problem hiding this comment.
LGTM, just a few minor comments. Thanks!
I was able to run it yesterday for other PRs. Potentially the changes are large and it met |
7f4b99f to
aee748b
Compare
|
@googlebot I signed it! |
…e.py, and match maxtext sinkhorn implementation to HF reference.
aee748b to
2d1c867
Compare
Description
This PR introduces necessary bug fixes to DeepSeek4 in the implementation and checkpoint mapping to pass a logit parity test against the HuggingFace implementation.
Bug Fixes & Architectural Additions for DeepSeek4:
DeepSeek4HyperHeadmodule inlayers/mhc.pyand routedDEEPSEEK4decoder blocks to use it inlayers/decoders.py. Also fixed thesinkhornfunction by adding an epsilon (1e-5) for numerical stability during normalization and adjusting the loop iterations.layers/attention_compressed.pywhere decoding withseq_len == 1orcompressed_len == 0returnedNonefor the causal mask. It now properly returns a tensor of zeros to prevent shape mismatch errors downstream.layers/moe.pyto ensureDEEPSEEK4uses the appropriate top-K weight scaling and SwiGLU MLP activation bounds clipping, matching the DeepSeek standard.DEEPSEEKV4_MAXTEXT_TO_HF_PARAM_MAPPINGandDEEPSEEKV4_MAXTEXT_TO_HF_PARAM_HOOK_FN) inutils/param_mapping.pyto support correct weight loading/saving for the mHC and attention compressor blocks.deepseek4-tiny.ymlconfiguration for debugging.deepseek4-284b.ymlconfig with necessary routing biases, top-k probabilities, and RoPE positional embeddings.tests/unit/deepseek_v4_vs_reference_test.py.Tests
tests/unit/deepseek_v4_vs_reference_test.py. We test the conversion mapping for each unique layer type (sliding window + hash routing, CSA/Indexer + hash routing, HCA + topk routing, CSA/Indexer + topk routing) used to do checkpoint conversion as part of unit tests by generating reference logits from the pytorch implementation, converting weights to maxtext implementation, generating maxtext logits, and verifying parity of the logits.Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.