Skip to content

AWQ CohereForCausalLM & Gemma mappings #1570

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
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/llmcompressor/modifiers/awq/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,54 @@ class AWQMapping:
),
]

# Gemma includes a pre_feedforward_layernorm in between
# post_attention_layernorm and the mlp down/gate proj layers
# use that instead of post_attention_layernorm in 3rd mapping:
_gemma_mappings = [
AWQMapping(
"re:.*input_layernorm$",
["re:.*q_proj$", "re:.*k_proj$", "re:.*v_proj$"],
),
AWQMapping("re:.*v_proj$", ["re:.*o_proj$"]),
AWQMapping(
"re:.*pre_feedforward_layernorm$",
["re:.*gate_proj$", "re:.*up_proj$"],
),
AWQMapping(
"re:.*up_proj$",
["re:.*down_proj$"],
),
]


# Cohere architecture is similar to default, with a very fundamental difference.
# The MLP block is executed in parallel to the attention. So the tensor goes
# through input_layernorm and then from there it goes directly to the attention
# module and to the MLP module.
_cohere_mappings = [
AWQMapping(
"re:.*input_layernorm$",
[
"re:.*self_attn.q_proj$",
"re:.*self_attn.k_proj$",
"re:.*self_attn.v_proj$",
"re:.*mlp.gate_proj$",
"re:.*mlp.up_proj$",
],
),
AWQMapping("re:.*v_proj$", ["re:.*o_proj$"]),
AWQMapping(
"re:.*up_proj$",
["re:.*down_proj$"],
),
]

AWQ_MAPPING_REGISTRY: Dict[str, list[AWQMapping]] = {
"CohereForCausalLM": _cohere_mappings,
"Cohere2ForCausalLM": _cohere_mappings,
"Gemma2ForCausalLM": _gemma_mappings,
"Gemma3ForCausalLM": _gemma_mappings,
"Gemma3ForConditionalGeneration": _gemma_mappings,
"LlamaForCausalLM": _default_mappings,
"MistralForCausalLM": _default_mappings,
"Phi3ForCausalLM": _phi_mappings,
Expand Down