Skip to content
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

Qwen support #78

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion awq/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
from .falcon import FalconAWQForCausalLM
from .bloom import BloomAWQForCausalLM
from .gptj import GPTJAWQForCausalLM
from .gpt_bigcode import GptBigCodeAWQForCausalLM
from .gpt_bigcode import GptBigCodeAWQForCausalLM
from .qwen import QwenAWQForCausalLM
3 changes: 2 additions & 1 deletion awq/models/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"falcon": FalconAWQForCausalLM,
"bloom": BloomAWQForCausalLM,
"gptj": GPTJAWQForCausalLM,
"gpt_bigcode": GptBigCodeAWQForCausalLM
"gpt_bigcode": GptBigCodeAWQForCausalLM,
"qwen": QwenAWQForCausalLM
}

def check_and_get_model_type(model_dir, trust_remote_code=True):
Expand Down
3 changes: 2 additions & 1 deletion awq/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def from_quantized(self, model_path, model_type, model_filename='',
load_checkpoint_in_model(
model,
checkpoint=model_weights_path,
device_map=device_map
device_map=device_map,
dtype=torch_dtype
)

# Dispath to devices
Expand Down
50 changes: 50 additions & 0 deletions awq/models/qwen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from .base import BaseAWQForCausalLM

class QwenAWQForCausalLM(BaseAWQForCausalLM):
layer_type = "QWenBlock"
max_new_tokens_key = "seq_length"

@staticmethod
def get_model_layers(model):
return model.transformer.h

@staticmethod
def get_act_for_scaling(module):
return dict(
is_scalable=False
)

@staticmethod
def move_embed(model, device: str):
model.transformer.wte = model.transformer.wte.to(device)
model.transformer.rotary_emb = model.transformer.rotary_emb.to(device)

@staticmethod
def get_layers_for_scaling(module, input_feat, module_kwargs):
layers = []

# attention
layers.append(dict(
prev_op=module.ln_1,
layers=[module.attn.c_attn, module.attn.c_proj],
inp=input_feat['attn.c_attn'],
module2inspect=module.attn,
kwargs=module_kwargs
))

# mlp
layers.append(dict(
prev_op=module.ln_2,
layers=[module.mlp.w1, module.mlp.w2],
inp=input_feat['mlp.w1'],
module2inspect=module.mlp
))

# linear 2
# layers.append(dict(
# prev_op=module.mlp.w2,
# layers=[module.mlp.c_proj],
# inp=input_feat['mlp.c_proj']
# ))

return layers