refactor(glm): reuse DeepseekV3 base implementation via template methods#604
Open
wtsung wants to merge 1 commit into
Open
refactor(glm): reuse DeepseekV3 base implementation via template methods#604wtsung wants to merge 1 commit into
wtsung wants to merge 1 commit into
Conversation
566de33 to
0b3f5bb
Compare
0b3f5bb to
ec44a6b
Compare
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
Refactor
GlmMoeDsaDecoderLayerandGlmMoeDsaModelto fully leverage inheritance from theirDeepseekV3base classes.This change introduces two template methods in the
DeepseekV3implementation so that subclasses only need to customize the components that differ, eliminating approximately 170 lines of duplicated code without changing behavior.Changes
deepseek_v3.pyIntroduce two extension points for subclasses:
DeepseekV3DecoderLayer._create_attn()to allow subclasses to customize the attention implementation.DeepseekV3Model._create_decoder_layer()to allow subclasses to customize decoder layer construction.glm5.pySimplify the GLM-specific subclasses by relying on the inherited implementation wherever possible.
GlmMoeDsaDecoderLayersuper().__init__()instead of duplicating the parent initialization._create_attn()to instantiateGlmMoeDsaAttention.forward(),forward_mlp(), and initialization logic, all of which are identical toDeepseekV3DecoderLayer.GlmMoeDsaModel_create_decoder_layer()to constructGlmMoeDsaDecoderLayer.__init__()implementation and inherit the base initialization directly.Additional cleanup
_retired_decode_workspacesin__init__()._resolve_decode_q_len()._qkv_widthtoqkv_width.Verification
The refactor is behavior-preserving:
forward()andforward_mlp()implementations inGlmMoeDsaDecoderLayerare identical to those inherited fromDeepseekV3DecoderLayer.GlmMoeDsaModel.__init__()performs the same initialization sequence asDeepseekV3Model.__init__().