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

[WIP] Qwen2-VL with VisionZip #12725

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
20 changes: 17 additions & 3 deletions python/llm/src/ipex_llm/transformers/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,10 +1181,10 @@ def replace_RotaryEmbed(m, target_m, replace_embed):


def replace_func(m, target_m, func_name, new_func):
if m.__class__ == target_m:
bound_method = new_func.__get__(m, m.__class__)
setattr(m, func_name, bound_method)
for _, sub_m in m.named_children():
if sub_m.__class__ == target_m:
bound_method = new_func.__get__(sub_m, sub_m.__class__)
setattr(sub_m, func_name, bound_method)
replace_func(sub_m, target_m, func_name, new_func)


Expand Down Expand Up @@ -1646,6 +1646,11 @@ def _optimize_post(model):
from ipex_llm.transformers.models.qwen2_vl import qwen2_vision_attention_forward
from ipex_llm.transformers.models.qwen2_vl import qwen2_vl_model_forward
from ipex_llm.transformers.models.qwen2_vl import qwen2_vl_attention_forward
from ipex_llm.transformers.models.qwen2_vl import qwen2_vit_pretrained_model_forward
from ipex_llm.transformers.models.qwen2_vl import qwen2_vl_vision_block_forward
from ipex_llm.transformers.models.qwen2_vl import qwen2_vl_conditional_generation_forward
from ipex_llm.transformers.models.qwen2_vl import get_rope_index
from ipex_llm.transformers.models.qwen2_vl import prepare_inputs_for_generation
convert_forward(model, module.Qwen2RMSNorm, rms_norm_forward)
convert_forward(model, module.Qwen2MLP, qwen2_mlp_forward)
model.visual.get_dtype = MethodType(qwen2_vision_get_dtype, model.visual)
Expand All @@ -1654,6 +1659,15 @@ def _optimize_post(model):
convert_forward(model, module.Qwen2VLModel, qwen2_vl_model_forward)
convert_forward(model, module.Qwen2VLAttention, qwen2_vl_attention_forward)
convert_forward(model, module.Qwen2VLSdpaAttention, qwen2_vl_attention_forward)
convert_forward(model, module.Qwen2VisionTransformerPretrainedModel,
qwen2_vit_pretrained_model_forward)
convert_forward(model, module.Qwen2VLVisionBlock, qwen2_vl_vision_block_forward)
convert_forward(model, module.Qwen2VLForConditionalGeneration,
qwen2_vl_conditional_generation_forward)
replace_func(model, module.Qwen2VLForConditionalGeneration,
"get_rope_index", get_rope_index)
replace_func(model, module.Qwen2VLForConditionalGeneration,
"prepare_inputs_for_generation", prepare_inputs_for_generation)
elif model.config.model_type == "aquila":
modeling_module_name = model.__class__.__module__
module = importlib.import_module(modeling_module_name)
Expand Down
Loading
Loading