-
Notifications
You must be signed in to change notification settings - Fork 327
support gemma4 #1304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WANDY666
wants to merge
22
commits into
main
Choose a base branch
from
support_gemma4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
support gemma4 #1304
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
21c3eeb
support 31B
WANDY666 99b790c
fix
WANDY666 4c30c73
Merge branch 'main' of https://github.com/ModelTC/LightLLM into suppo…
WANDY666 15a5379
support moe
WANDY666 83f4983
support e4b (PLE and shared_kv)
WANDY666 d969a5f
support visual module
WANDY666 08f066d
optimize sliding window
WANDY666 7678de8
fix
WANDY666 63c658a
simplify
WANDY666 300e577
minor improvements
WANDY666 50822f0
fix
WANDY666 b4b13cc
fix attention cuda graph
WANDY666 f19074b
fused gelu gate up
WANDY666 5b61450
add out_dtype
WANDY666 c0ca212
minor improvements
WANDY666 9499a00
fix eos_token_ids
WANDY666 de7e220
for HF format
WANDY666 bfc59ff
Merge branch 'main' of https://github.com/ModelTC/LightLLM into suppo…
WANDY666 109d27c
fix window_size
WANDY666 2ea258e
fix window_size
WANDY666 b297af5
fix
WANDY666 7a81e85
add reasoning_parser for gemma4
WANDY666 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
34 changes: 34 additions & 0 deletions
34
...m/common/basemodel/layer_weights/meta_weights/fused_moe/gemma4_packed_fused_moe_weight.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from lightllm.common.basemodel.layer_weights.meta_weights.fused_moe.fused_moe_weight import FusedMoeWeight | ||
|
|
||
|
|
||
| class Gemma4PackedFusedMoeWeight(FusedMoeWeight): | ||
| def load_hf_weights(self, weights): | ||
| gate_up_name = f"{self.weight_prefix}.gate_up_proj" | ||
| down_name = f"{self.weight_prefix}.down_proj" | ||
| if gate_up_name not in weights and down_name not in weights and self.per_expert_scale_name not in weights: | ||
| return super().load_hf_weights(weights) | ||
|
|
||
| assert self.quant_method.method_name == "none", "Gemma-4 packed MoE currently supports bf16/no-quant weights." | ||
| assert not self.enable_ep_moe, "Gemma-4 packed MoE currently supports TP mode only." | ||
|
|
||
| start = self.split_inter_size * self.tp_rank_ | ||
| end = self.split_inter_size * (self.tp_rank_ + 1) | ||
| moe_intermediate_size = self.moe_intermediate_size | ||
|
|
||
| if gate_up_name in weights: | ||
| gate_up_weight = weights[gate_up_name] | ||
| for expert_idx, local_expert_idx in self.expert_idx_to_local_idx.items(): | ||
| gate_weight = gate_up_weight[expert_idx, start:end, :].contiguous() | ||
| up_weight = gate_up_weight[ | ||
| expert_idx, moe_intermediate_size + start : moe_intermediate_size + end, : | ||
| ].contiguous() | ||
| self.quant_method.load_weight(gate_weight, self.w1_list[local_expert_idx]) | ||
| self.quant_method.load_weight(up_weight, self.w3_list[local_expert_idx]) | ||
|
|
||
| if down_name in weights: | ||
| down_weight = weights[down_name] | ||
| for expert_idx, local_expert_idx in self.expert_idx_to_local_idx.items(): | ||
| down_weight_slice = down_weight[expert_idx, :, start:end].contiguous() | ||
| self.quant_method.load_weight(down_weight_slice, self.w2_list[local_expert_idx]) | ||
|
|
||
| self._load_per_expert_scale(weights) | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
.contiguous()on slices ofgate_up_weightcreates additional copies of the expert weights in memory during the loading process. If the model has a large number of experts or a high intermediate dimension, this could significantly increase the peak memory usage of the loader. Ifself.quant_method.load_weightcan handle non-contiguous tensors, these calls should be removed.