fix: ollama template mapping (#1354)

* feat ollama template qwen3

* add phi4, llama4, qwen2.5vl

* fix dpsk-r1-qwen3

* rm duplicate case

---------

Co-authored-by: suluyan <suluyan.sly@aliabab-inc.com>
This commit is contained in:
suluyana
2025-06-04 20:13:35 +08:00
committed by GitHub
parent f9b8d4b9d2
commit 800543d1aa
2 changed files with 97 additions and 72 deletions

View File

@@ -54,6 +54,12 @@ def no_multi_modal():
# Order matters
template_info = [
# llama
TemplateInfo(
template_regex=
f'.*{cases("llama4", "llama-4")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama4',
),
## "llama3"
TemplateInfo(
template_regex=
@@ -152,7 +158,66 @@ template_info = [
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama2',
),
# "deepseek"
TemplateInfo(
template=TemplateType.deepseek2_5,
template_regex=
f'.*{cases("deepseek")}.*{cases("v2.5")}{no_multi_modal()}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v2.5',
),
TemplateInfo(
template=TemplateType.deepseek_coder,
template_regex=
f'.*{cases("deepseek")}.*{cases("coder")}.*{cases("v2")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-coder-v2',
),
TemplateInfo(
template=TemplateType.deepseek_coder,
template_regex=
f'.*{cases("deepseek")}{no("v2", "v2.5")}.*{cases("coder")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-coder',
),
TemplateInfo(
template=TemplateType.deepseek2,
template_regex=
f'.*{cases("deepseek")}.*{cases("v2")}{no("v2.5")}{no_multi_modal()}.*{chat_suffix}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v2',
),
TemplateInfo(
template=TemplateType.deepseek,
template_regex=
f'.*{cases("deepseek")}{no("v2", "v2.5", "coder")}{no_multi_modal()}.*{chat_suffix}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-llm',
),
TemplateInfo(
template_regex=
f'.*{cases("deepseek")}.*{cases("v3")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v3',
),
TemplateInfo(
template_regex=
f'.*{cases("deepseek")}.*{cases("r1")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-r1',
),
# qwen
TemplateInfo(
template_regex=f'.*{cases("qwen3")}{no_multi_modal()}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen3',
),
TemplateInfo(
template_regex=f'.*{cases("qwen2.5")}.*{cases("vl")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen2.5vl',
),
TemplateInfo(
template=TemplateType.qwen,
template_regex=f'.*{cases("qwen2.5")}.*{cases("coder")}.*{chat_suffix}.*',
@@ -243,6 +308,18 @@ template_info = [
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/dolphin3'),
# "phi"
TemplateInfo(
template_regex=
f'.*{cases("phi-4-reasoning")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phi4-reasoning',
),
TemplateInfo(
template_regex=
f'.*{cases("phi-4-mini-reasoning")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phi4-mini-reasoning',
),
TemplateInfo(
template_regex=
f'.*{cases("llava-phi3", "llava-phi-3")}.*',
@@ -369,43 +446,6 @@ template_info = [
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nous-hermes'),
# "deepseek"
TemplateInfo(
template=TemplateType.deepseek2_5,
template_regex=
f'.*{cases("deepseek")}.*{cases("v2.5")}{no_multi_modal()}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v2.5',
),
TemplateInfo(
template=TemplateType.deepseek_coder,
template_regex=
f'.*{cases("deepseek")}.*{cases("coder")}.*{cases("v2")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-coder-v2',
),
TemplateInfo(
template=TemplateType.deepseek_coder,
template_regex=
f'.*{cases("deepseek")}{no("v2", "v2.5")}.*{cases("coder")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-coder',
),
TemplateInfo(
template=TemplateType.deepseek2,
template_regex=
f'.*{cases("deepseek")}.*{cases("v2")}{no("v2.5")}{no_multi_modal()}.*{chat_suffix}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v2',
),
TemplateInfo(
template=TemplateType.deepseek,
template_regex=
f'.*{cases("deepseek")}{no("v2", "v2.5", "coder")}{no_multi_modal()}.*{chat_suffix}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-llm',
),
# "yi"
TemplateInfo(
template=TemplateType.yi_coder,
@@ -626,41 +666,6 @@ template_info = [
template=TemplateType.zephyr,
template_regex=f'.*{cases("zephyr")}{no_multi_modal()}.*'),
# deepseek
TemplateInfo(
template=TemplateType.deepseek,
template_regex=
f'.*{cases("deepseek")}{no("v2", "v2.5", "v3", "r1", "coder")}{no_multi_modal()}.*{chat_suffix}.*'
),
TemplateInfo(
template=TemplateType.deepseek2,
template_regex=
f'.*{cases("deepseek")}.*{cases("v2")}{no("v2.5")}{no_multi_modal()}.*{chat_suffix}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v2',
),
TemplateInfo(
template=TemplateType.deepseek_coder,
template_regex=
f'.*{cases("deepseek")}{no("v2", "v2.5")}.*{cases("coder")}.*{chat_suffix}.*'
),
TemplateInfo(
template=TemplateType.deepseek2_5,
template_regex=
f'.*{cases("deepseek")}.*{cases("v2.5")}{no_multi_modal()}.*'),
TemplateInfo(
template_regex=
f'.*{cases("deepseek")}.*{cases("v3")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v3',
),
TemplateInfo(
template_regex=
f'.*{cases("deepseek")}.*{cases("r1")}.*',
modelfile_prefix=
'https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-r1',
),
# orion
TemplateInfo(
template=TemplateType.orion,

View File

@@ -122,6 +122,26 @@ class TestToOllama(unittest.TestCase):
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_check_template_type(self):
_test_check_tmpl_type(
'unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF',
'deepseek-r1',
gguf_meta={'general.name': 'Deepseek-R1-0528-Qwen3-8B'})
_test_check_tmpl_type(
'unsloth/Qwen2.5-VL-3B-Instruct-GGUF',
'qwen2.5vl',
gguf_meta={'general.name': 'Qwen2.5-Vl-3B-Instruct'})
_test_check_tmpl_type(
'unsloth/Phi-4-reasoning-GGUF',
'phi4-reasoning',
gguf_meta={'general.name': 'Phi-4-Reasoning-Plus'})
_test_check_tmpl_type('unsloth/Phi-4-mini-reasoning-GGUF',
'phi4-mini-reasoning')
_test_check_tmpl_type('unsloth/Llama-4-Scout-17B-16E-Instruct-GGUF',
'llama4')
_test_check_tmpl_type(
'unsloth/Qwen3-32B-GGUF',
'qwen3',
gguf_meta={'general.name': 'Qwen3-32B'})
_test_check_tmpl_type(
'lmstudio-community/granite-3.3-2b-instruct-GGUF',
'granite3.3',