[Feature] Support apply_liger_kernel_to_deepseek_v3 - #1424
Open
Yulong-Cauli wants to merge 1 commit into
Open
Yulong-Cauli wants to merge 1 commit into
Yulong-Cauli wants to merge 1 commit into
Conversation
Add Liger Kernel support for DeepSeek-V3 (deepseek_v3 model type), closing the gap left open by issue linkedin#623: - model/deepseek_v3.py: lce_forward with FusedLinearCrossEntropy (logits never materialized in training) - monkey_patch.py: apply_liger_kernel_to_deepseek_v3 with RMSNorm, SwiGLU (dense MLP + shared experts, fused MoE routed experts on transformers v5+, per-expert patch on v4), and FLCE; RoPE is unsupported (interleaved partial RoPE) and warns + skips - class-level and instance-level patching, MODEL_TYPE registration - convergence tests (bf16/fp32, FLCE and logits paths), monkey-patch instance tests, revert util, README entry
Yulong-Cauli
force-pushed
the
feat/deepseek-v3-support
branch
from
September 13, 2026 06:55
32bec97 to
31c38e6
Compare
Contributor
Author
|
@arde171 @kolehma8 @BYHsu — friendly ping for a review when you get a chance. The branch is now a single commit rebased onto latest main ( Recap (closes #623): adds
Validation:
Could a maintainer approve the workflow run when convenient? (Checks are pending approval for fork PRs.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Liger Kernel support for DeepSeek-V3 (
deepseek_v3model type), closing the gap left open by #623.model/deepseek_v3.py: newlce_forward. In training with labels,skip_logitsdefaults toTrue, so logits are never materialized (FLCE path viaLigerForCausalLMLoss); otherwise logits are materialized and the HF-nativeself.loss_functionis used. ReturnsLigerCausalLMOutputWithPastwithtoken_accuracy/predicted_tokens.monkey_patch.py:apply_liger_kernel_to_deepseek_v3with class-level and instance-level patching, registered inMODEL_TYPE_TO_APPLY_LIGER_FN(AutoLigerKernelForCausalLMpicks it up automatically).DeepseekV3RMSNorm→LigerRMSNorm, including attentionq_a_layernorm/kv_a_layernorm.DeepseekV3MLP) →LigerQwen3MoeSwiGLUMLPon all supported versions. Routed experts: batchedDeepseekV3Experts→ fusedLigerExpertson transformers v5+; per-expert patch on transformers v4.liger_rotary_pos_emb.rope=Trueemits awarning_onceand skips (no silent behavior change); RoPE is intentionally not listed in the README table.deepseek_v3config,revert_liger_kernel_to_deepseek_v3util, README entry.Details
LigerExpertsacceptsDeepseekV3Config(num_local_expertsaliasesn_routed_experts), and its batched expert weights ((N, 2*I, H)/(N, H, I)) match the HF layout, so pretrained checkpoints load unchanged.Testing Done
Exact commands run on this change:
pytest test/transformers/test_monkey_patch.py -k deepseek_v3→ 1 passedpytest test/convergence/{bf16,fp32}/test_mini_models.py test/convergence/{bf16,fp32}/test_mini_models_with_logits.py -k deepseek_v3→ 4 passedruff check+ruff format --checkclean on all changed filesHardware Type: RTX 4060 Laptop GPU (8GB) — transformers 5.16.1, torch 2.11.0+cu128
run
make testto ensure correctnessrun
make checkstyleto ensure code stylerun
make test-convergenceto ensure convergenceCloses #623