-
Notifications
You must be signed in to change notification settings - Fork 421
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
Add Qwen2MoE #593
Open
bozheng-hit
wants to merge
3
commits into
AutoGPTQ:main
Choose a base branch
from
bozheng-hit:qwen2_moe
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
Add Qwen2MoE #593
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 |
---|---|---|
|
@@ -760,6 +760,21 @@ def get_checkpoints(model_name_or_path: str, extensions: List[str], possible_mod | |
return False, resolved_archive_file, true_model_basename | ||
|
||
|
||
# generate inside layer modules for MoE models with massive experts | ||
def get_moe_inside_layer_modules(inside_layer_modules, num_experts): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add type hints and a small description here? |
||
new_inside_layer_modules = [] | ||
for names in inside_layer_modules: | ||
new_inside_layer_modules.append([]) | ||
for n in names: | ||
if "{expert_idx}" in n: | ||
for expert_idx in range(num_experts): | ||
new_inside_layer_modules[-1].append(n.replace("{expert_idx}", str(expert_idx))) | ||
else: | ||
new_inside_layer_modules[-1].append(n) | ||
|
||
return new_inside_layer_modules | ||
|
||
|
||
__all__ = [ | ||
"get_device", | ||
"move_to_device", | ||
|
This file contains 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 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,18 @@ | ||
from ._base import BaseGPTQForCausalLM | ||
|
||
|
||
class Qwen2MoeGPTQForCausalLM(BaseGPTQForCausalLM): | ||
layer_type = "Qwen2DecoderLayer" | ||
layers_block_name = "model.layers" | ||
outside_layer_modules = ["model.embed_tokens", "model.norm"] | ||
inside_layer_modules = [ | ||
["self_attn.k_proj", "self_attn.v_proj", "self_attn.q_proj"], | ||
["self_attn.o_proj"], | ||
["mlp.shared_expert.up_proj", "mlp.shared_expert.gate_proj"], | ||
["mlp.shared_expert.down_proj"], | ||
["mlp.experts.{expert_idx}.up_proj", "mlp.experts.{expert_idx}.gate_proj"], | ||
["mlp.experts.{expert_idx}.down_proj"], | ||
] | ||
|
||
|
||
__all__ = ["Qwen2MoeGPTQForCausalLM"] |
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.
Why is
self.inside_layer_modules
not enough?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.
We cannot write the names of all the parameters in our MoE model because we may have more experts. Besides, we may have different numbers of experts for different model sizes.
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.
I agree it is a bit clunky but you can just add like the highest amount of experts you may have and the models with less will work too.
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.
It will work, but I think the current codes look much better than writing hundreds of parameter names in the modeling file.
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.
I don't disagree, but I would prefer a separate PR for for something like this that others could rely on. I know that is just for slightly easier git history. I just prefer PRs to stay focused and do the minimum changes required. Feel free to ignore me, it's not that important.