Repository navigation
Conversation
|
Hi @ZenAlexa! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@claude review this PR, describe what's the problem and what's the fix, evaluate if the fix is the most proper way. In particular, why do we need to make changes in both deepseek v3 and v4 state dict adapters. |
|
Claude finished @tianyu-l's task in 6m 55s —— View job PR Review: Fix DeepSeek V4 checkpoint conversion with optional MTP
What's the problemIssue #4496 is really three distinct bugs, two of which live in the shared V3 adapter that V4 inherits from:
There is also a latent placement-restoration bug in V3 that this PR fixes (see below). What's the fix
Why both V3 and V4 must change (tianyu-l's question)Two independent reasons, both because V4 delegates the bulk of conversion to
So V3 changes are load-bearing for correctness (not refactoring for its own sake), and V4 changes handle the V4-specific Is this the most proper way?Overall yes - it reuses the existing helpers rather than adding parallel logic, keeps the V4-specific naming quirk isolated at the adapter boundary, and is well covered by the new tests (0/1/2 MTP layers, sink round-trip, sharded-expert placements). A few observations:
I could not run |
tianyu-l
left a comment
There was a problem hiding this comment.
to be honest, I couldn't follow the details, but I don't mind these converters being reviewed / maintained by agents.
cc @Matrix-Z97
Fixes #4496.
DeepSeek V4 currently raises
len(None)when restoring the default model and a missing-key error when exporting an MTP attention sink. The shared V3 conversion also uses a different MTP layer layout from the official V4 checkpoint, which stores these weights undermtp.<index>.This patch reuses the existing layer-mapping helpers, handles optional MTP layers, and translates the V4 MTP prefix at the adapter boundary. Reusing the helper for routed experts also preserves their original TorchTitan key when recording DTensor metadata, so MTP expert weights retain their placements during restoration.
Validation on Ubuntu 24.04 ARM64 with PyTorch 2.14.0+cpu:
python3 -m unittest tests.unit_tests.cpu.test_state_dict_adapter tests.unit_tests.cpu.test_deepseek_v4_flops -v: six tests completed successfully. Coverage includes V3 and GPT-OSS regression tests, initialized V4 models with 0/1/2 MTP layers, and MTP expert placements.HuggingFaceStorageWriter/HuggingFaceStorageReader. All 118/150/182 state entries retained their values, shapes, and dtypes for the three V4 configurations.CheckpointManager.dcp_loadmethod andModelWrapper. Native DCP save/clear/load restores every entry exactly, including shapes and dtypes; expert tensors also retain their strides andShard(0)placements. The checkpoint manager constructor and GPU training are outside this check.hc_head_fn), embedding norm, and output norm. Their converted shapes match the FLASH model, and the reverse conversion preserves their exact bytes and dtypes.pre-commit run --all-filesreported an existing import-formatting change intorchtitan/experiments/rl/tests/test_dapo_math.pyand a missing localpyreflyexecutable. The changed files satisfy the formatting and lint hooks; a separate Pyrefly 0.45.1 check of all three changed files reports zero errors.Validation covers checkpoint conversion and restoration. Full quantized-weight loading and multi-GPU training remain outside the executed scope.