Skip to content

Commit

Permalink
Update multimodal on vllm 0.6.6 (#12816)
Browse files Browse the repository at this point in the history
* add glm4v and minicpmv example

* fix
  • Loading branch information
hzjane authored Feb 19, 2025
1 parent 09150b6 commit e1809a6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,39 @@

model_path = "/llm/models/MiniCPM-V-2_6"
model_path = "/llm/models/Qwen2-VL-7B-Instruct"
model_path = "/llm/models/glm-4v-9b"
model_path = "/llm/models/InternVL2-8B"

prompt = "What is in the image?"

def run_internvl(question: str, modality: str):
assert modality == "image"

tokenizer = AutoTokenizer.from_pretrained(model_path,
trust_remote_code=True)
messages = [{'role': 'user', 'content': f"<image>\n{question}"}]
prompt = tokenizer.apply_chat_template(messages,
tokenize=False,
add_generation_prompt=True)

# Stop tokens for InternVL
# models variants may have different stop tokens
# please refer to the model card for the correct "stop words":
# https://huggingface.co/OpenGVLab/InternVL2-2B/blob/main/conversation.py
stop_tokens = ["<|endoftext|>", "<|im_start|>", "<|im_end|>", "<|end|>"]
stop_token_ids = [tokenizer.convert_tokens_to_ids(i) for i in stop_tokens]
return prompt, stop_token_ids

def run_glm4v(question: str, modality: str):
assert modality == "image"
model_name = "THUDM/glm-4v-9b"

prompt = f"<|user|>\n<|begin_of_image|><|endoftext|><|end_of_image|>\
{question}<|assistant|>"

stop_token_ids = [151329, 151336, 151338]
return prompt, stop_token_ids

def run_minicpmv(question, modality):
assert modality == "image"
tokenizer = AutoTokenizer.from_pretrained(model_path,
Expand Down Expand Up @@ -38,6 +69,9 @@ def run_qwen2_vl(question, modality):
model_example_map = {
"minicpmv": run_minicpmv,
"qwen2_vl": run_qwen2_vl,
# only for glm4v
"chatglm": run_glm4v,
"internvl_chat": run_internvl,
}

llm = LLM(
Expand Down
4 changes: 0 additions & 4 deletions python/llm/src/ipex_llm/vllm/xpu/model_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ def _ipex_llm_load_model(self) -> None:
modules = None
if "minicpm" in self.vllm_config.model_config.model.lower():
modules = ["vpm", "resampler"]
# only for minicpm_2_6
if "minicpm-v" in self.vllm_config.model_config.model.lower():
from ipex_llm.transformers.models.minicpmv import merge_qkv
self.model.vpm.apply(merge_qkv)
if "internvl2" in self.vllm_config.model_config.model.lower():
modules = ["vision_model", "mlp1"]
if "deepseek-v2" in self.vllm_config.model_config.model.lower():
Expand Down

0 comments on commit e1809a6

Please sign in to comment.