Skip to content

Commit 4c6bc99

Browse files
committed
support qwen3-omni
1 parent f1e1a05 commit 4c6bc99

File tree

14 files changed

+1437
-35
lines changed

14 files changed

+1437
-35
lines changed

lmdeploy/archs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ def check_vl_llm(config: dict) -> bool:
110110
'InternVLChatModel', 'MiniCPMV', 'LlavaForConditionalGeneration', 'LlavaNextForConditionalGeneration',
111111
'Phi3VForCausalLM', 'Qwen2VLForConditionalGeneration', 'Qwen2_5_VLForConditionalGeneration',
112112
'Qwen3VLForConditionalGeneration', 'Qwen3VLMoeForConditionalGeneration', 'Qwen3_5ForConditionalGeneration',
113-
'Qwen3_5MoeForConditionalGeneration', 'MllamaForConditionalGeneration', 'MolmoForCausalLM',
114-
'Gemma3ForConditionalGeneration', 'Llama4ForConditionalGeneration', 'InternVLForConditionalGeneration',
115-
'InternS1ForConditionalGeneration', 'InternS1ProForConditionalGeneration',
113+
'Qwen3_5MoeForConditionalGeneration', 'Qwen3OmniMoeForConditionalGeneration', 'MllamaForConditionalGeneration',
114+
'MolmoForCausalLM', 'Gemma3ForConditionalGeneration', 'Llama4ForConditionalGeneration',
115+
'InternVLForConditionalGeneration', 'InternS1ForConditionalGeneration', 'InternS1ProForConditionalGeneration',
116116
'InternS1_1_ForConditionalGeneration', 'Glm4vForConditionalGeneration'
117117
])
118118
if arch == 'QWenLMHeadModel' and 'visual' in config:

lmdeploy/model.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,19 @@ class HFChatTemplate(BaseChatTemplate):
685685
def __init__(self, model_path: str = '', **kwargs):
686686
self.model_path = model_path
687687
try:
688-
from transformers import AutoTokenizer
688+
from transformers import AutoProcessor, AutoTokenizer
689689
self.tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
690+
691+
# Some tokenizers do not have chat_template, in this case try to get chat_template from processor
692+
# If this still does not work, fallback to BaseChatTemplate.
693+
if getattr(self.tokenizer, 'chat_template', None) is None:
694+
try:
695+
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
696+
self.tokenizer.chat_template = getattr(processor, 'chat_template', None)
697+
except Exception as e:
698+
logger.warning(f'Failed to load processor from {model_path} for chat template. '
699+
f'Fallback to tokenizer only. Error: {e}')
700+
690701
# Verify if the model can perform apply_chat_template with different roles.
691702
self.user_start, self.user_end, _, _ = self._user_instruction()
692703
self.assistant_start, self.assistant_end, _, _ = self._assistant_instruction()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) OpenMMLab. All rights reserved.
2+
from .builder import AutoModelConfigBuilder
3+
from .default import DefaultModelConfigBuilder
4+
5+
6+
class Qwen3OmniModelConfigBuilder(AutoModelConfigBuilder):
7+
8+
@classmethod
9+
def condition(cls, hf_config):
10+
"""config."""
11+
return hf_config.model_type == 'qwen3_omni_moe'
12+
13+
@classmethod
14+
def build(cls, hf_config, model_path: str = None, **kwargs):
15+
"""build."""
16+
cfg = DefaultModelConfigBuilder.build(hf_config.thinker_config.text_config, model_path, **kwargs)
17+
cfg.hf_config = hf_config
18+
return cfg

lmdeploy/pytorch/models/module_map.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@
186186
f'{LMDEPLOY_PYTORCH_MODEL_PATH}.qwen3_5_moe.Qwen3_5MoeForConditionalGeneration',
187187
})
188188

189+
# qwen3 omni moe thinker
190+
# only support thinker module, so map to Qwen3OmniMoeThinkerForConditionalGeneration
191+
MODULE_MAP.update({
192+
'Qwen3OmniMoeForConditionalGeneration':
193+
f'{LMDEPLOY_PYTORCH_MODEL_PATH}.qwen3_omni_moe_thinker.Qwen3OmniMoeThinkerForConditionalGeneration',
194+
})
195+
189196
# starcoder2
190197
MODULE_MAP.update({
191198
'Starcoder2ForCausalLM': f'{LMDEPLOY_PYTORCH_MODEL_PATH}.starcoder2.Starcoder2ForCausalLM',

0 commit comments

Comments
 (0)