Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jintao-Huang committed Oct 29, 2024
1 parent 2a3a351 commit ea79337
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 591 deletions.
16 changes: 2 additions & 14 deletions swift/llm/model/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@
class LLMModelType:
# dense
qwen = 'qwen'
modelscope_agent = 'modelscope_agent'
qwen2 = 'qwen2'
qwen2_5 = 'qwen2_5'

llama2 = 'llama2'
llama3 = 'llama3'
llama3_1 = 'llama3_1'
llama3_2 = 'llama3_2'
llama = 'llama'
yi = 'yi'
yi_coder = 'yi_coder'

reflection_llama3_1 = 'reflection_llama3_1'

chatglm2 = 'chatglm2'
codegeex2 = 'codegeex2'
codefuse_codegeex2 = 'codefuse_codegeex2'
chatglm3 = 'chatglm3'
glm4 = 'glm4'
codegeex4 = 'codegeex4'

internlm = 'internlm'
internlm2 = 'internlm2'
Expand All @@ -45,10 +36,7 @@ class MLLMModelType:

glm4v = 'glm4v'
cogvlm = 'cogvlm'
cogagent_vqa = 'cogagent_vqa'
cogagent_chat = 'cogagent_chat'
cogvlm2 = 'cogvlm2'
cogvlm2_video = 'cogvlm2_video'

xcomposer2 = 'xcomposer2'
xcomposer2_4khd = 'xcomposer2_4khd'
Expand Down
238 changes: 83 additions & 155 deletions swift/llm/model/model/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,61 +56,38 @@ def cross_entropy_forward(self, inputs: torch.Tensor, target: torch.Tensor) -> t
register_model(
ModelMeta(
LLMModelType.chatglm2,
'ChatGLMModel',
ModelGroup([
Model('ZhipuAI/chatglm3-6b-base', 'THUDM/chatglm3-6b-base'),
Model('ZhipuAI/chatglm2-6b', 'THUDM/chatglm2-6b'),
Model('ZhipuAI/chatglm2-6b-32k', 'THUDM/chatglm2-6b-32k')
]),
TemplateType.chatglm2, # chatglm_generation
get_model_tokenizer_chatglm,
requires=['transformers<4.42'],
support_vllm=True,
))

register_model(
ModelMeta(
LLMModelType.codegeex2,
'ChatGLMModel',
ModelGroup(
[Model('ZhipuAI/codegeex2-6b', 'THUDM/codegeex2-6b')],
tags=['coding'],
),
TemplateType.chatglm2,
get_model_tokenizer_chatglm,
requires=['transformers<4.34'],
support_vllm=True,
))

register_model(
ModelMeta(
LLMModelType.codefuse_codegeex2,
'ChatGLMModel',
ModelGroup(
[Model('codefuse-ai/CodeFuse-CodeGeeX2-6B', 'codefuse-ai/CodeFuse-CodeGeeX2-6B')],
tags=['coding'],
),
TemplateType.codefuse,
get_model_tokenizer_chatglm,
requires=['transformers<4.34'],
support_vllm=True))

register_model(
ModelMeta(
LLMModelType.chatglm3,
'ChatGLMModel',
ModelGroup(
[
['ChatGLMModel', 'ChatGLMForConditionalGeneration'],
[
ModelGroup([
Model('ZhipuAI/chatglm2-6b', 'THUDM/chatglm2-6b'),
Model('ZhipuAI/chatglm2-6b-32k', 'THUDM/chatglm2-6b-32k')
],
TemplateType.chatglm2,
requires=['transformers<4.42']),
ModelGroup([
Model('ZhipuAI/chatglm3-6b-base', 'THUDM/chatglm3-6b-base'),
Model('ZhipuAI/chatglm3-6b', 'THUDM/chatglm3-6b'),
Model('ZhipuAI/chatglm3-6b-32k', 'THUDM/chatglm3-6b-32k'),
Model('ZhipuAI/chatglm3-6b-128k', 'THUDM/chatglm3-6b-128k'),
],
tags=['coding'],
),
TemplateType.chatglm3,
requires=['transformers<4.42']),
ModelGroup(
[Model('ZhipuAI/codegeex2-6b', 'THUDM/codegeex2-6b')],
TemplateType.chatglm2,
requires=['transformers<4.34'],
tags=['coding'],
),
ModelGroup(
[Model('codefuse-ai/CodeFuse-CodeGeeX2-6B', 'codefuse-ai/CodeFuse-CodeGeeX2-6B')],
TemplateType.codefuse,
requires=['transformers<4.34'],
tags=['coding'],
),
],
get_model_tokenizer_chatglm,
TemplateType.chatglm3,
requires=['transformers<4.42'],
support_vllm=True))
support_vllm=True,
))


def get_model_tokenizer_glm4(model_dir: str,
Expand All @@ -119,57 +96,36 @@ def get_model_tokenizer_glm4(model_dir: str,
load_model: bool = True,
**kwargs):
AttnImpl.update_attn_impl(model_config, kwargs.get('attn_impl'))
return get_model_tokenizer_chatglm(model_dir, model_config, model_kwargs, load_model, **kwargs)


register_model(
ModelMeta(
LLMModelType.glm4,
'ChatGLMModel',
ModelGroup([
Model('ZhipuAI/glm-4-9b', 'THUDM/glm-4-9b'),
Model('ZhipuAI/glm-4-9b-chat', 'THUDM/glm-4-9b-chat'),
Model('ZhipuAI/glm-4-9b-chat-1m', 'THUDM/glm-4-9b-chat-1m'),
]),
TemplateType.chatglm4,
get_model_tokenizer_glm4,
requires=['transformers>=4.42'],
support_vllm=True,
support_flash_attn=True,
support_lmdeploy=True))

register_model(
ModelMeta(
LLMModelType.codegeex4,
'ChatGLMModel',
ModelGroup([
Model('ZhipuAI/codegeex4-all-9b', 'THUDM/codegeex4-all-9b'),
], tags=['coding']),
TemplateType.codegeex4,
get_model_tokenizer_glm4,
requires=['transformers<4.42'],
support_vllm=True,
support_flash_attn=True,
support_lmdeploy=True))


def get_model_tokenizer_longwriter_glm4(*args, **kwargs):
model, tokenizer = get_model_tokenizer_glm4(*args, **kwargs)
for k in tokenizer.special_tokens.keys():
tokenizer.add_tokens(k)
model, tokenizer = get_model_tokenizer_chatglm(model_dir, model_config, model_kwargs, load_model, **kwargs)
if len(tokenizer.encode('<|user|>', add_special_tokens=False)) > 1:
for k in tokenizer.special_tokens.keys():
tokenizer.add_tokens(k)
return model, tokenizer


register_model(
ModelMeta(
LLMModelType.longwriter_glm4,
'ChatGLMModel',
ModelGroup([
Model('ZhipuAI/LongWriter-glm4-9b', 'THUDM/LongWriter-glm4-9b'),
]),
TemplateType.chatglm4,
get_model_tokenizer_longwriter_glm4,
requires=['transformers>=4.42'],
LLMModelType.glm4, ['ChatGLMModel', 'ChatGLMForConditionalGeneration'], [
ModelGroup([
Model('ZhipuAI/glm-4-9b', 'THUDM/glm-4-9b'),
Model('ZhipuAI/glm-4-9b-chat', 'THUDM/glm-4-9b-chat'),
Model('ZhipuAI/glm-4-9b-chat-1m', 'THUDM/glm-4-9b-chat-1m'),
],
TemplateType.chatglm4,
requires=['transformers>=4.42']),
ModelGroup([
Model('ZhipuAI/codegeex4-all-9b', 'THUDM/codegeex4-all-9b'),
],
TemplateType.codegeex4,
requires=['transformers<4.42'],
tags=['coding']),
ModelGroup([
Model('ZhipuAI/LongWriter-glm4-9b', 'THUDM/LongWriter-glm4-9b'),
],
TemplateType.chatglm4,
requires=['transformers>=4.42'])
],
get_model_tokenizer_glm4,
support_vllm=True,
support_flash_attn=True,
support_lmdeploy=True))
Expand Down Expand Up @@ -199,12 +155,10 @@ def get_model_tokenizer_glm4v(model_dir: str,

register_model(
ModelMeta(
MLLMModelType.glm4v,
'ChatGLMModel',
ModelGroup([
MLLMModelType.glm4v, ['ChatGLMModel', 'ChatGLMForConditionalGeneration'],
[ModelGroup([
Model('ZhipuAI/glm-4v-9b', 'THUDM/glm-4v-9b'),
]),
TemplateType.glm4v,
], TemplateType.glm4v)],
get_model_tokenizer_glm4v,
is_multimodal=True,
requires=['transformers>=4.42']))
Expand All @@ -228,43 +182,24 @@ def get_model_tokenizer_cogvlm(model_dir: str,
register_model(
ModelMeta(
MLLMModelType.cogvlm,
'CogVLMForCausalLM',
ModelGroup([
Model('ZhipuAI/cogvlm-chat', 'THUDM/cogvlm-chat-hf'),
]),
TemplateType.cogvlm,
['CogVLMForCausalLM', 'CogAgentForCausalLM'],
[
ModelGroup([
Model('ZhipuAI/cogvlm-chat', 'THUDM/cogvlm-chat-hf'),
], TemplateType.cogvlm),
ModelGroup([
Model('ZhipuAI/cogagent-chat', 'THUDM/cogagent-chat-hf'),
], TemplateType.cogvlm),
ModelGroup([
Model('ZhipuAI/cogagent-vqa', 'THUDM/cogagent-vqa-hf'),
], TemplateType.cogagent_vqa)
],
get_model_tokenizer_cogvlm,
is_multimodal=True,
support_gradient_checkpointing=False,
requires=['transformers<4.42'],
))

register_model(
ModelMeta(
MLLMModelType.cogagent_chat,
'CogAgentForCausalLM',
ModelGroup([
Model('ZhipuAI/cogagent-chat', 'THUDM/cogagent-chat-hf'),
]),
TemplateType.cogvlm,
get_model_tokenizer_cogvlm,
is_multimodal=True,
support_gradient_checkpointing=False,
requires=['transformers<4.42']))

register_model(
ModelMeta(
MLLMModelType.cogagent_vqa,
'CogAgentForCausalLM',
ModelGroup([
Model('ZhipuAI/cogagent-vqa', 'THUDM/cogagent-vqa-hf'),
]),
TemplateType.cogagent_vqa,
get_model_tokenizer_cogvlm,
is_multimodal=True,
support_gradient_checkpointing=False,
requires=['transformers<4.42']))


def get_model_tokenizer_cogvlm2(*args, **kwargs):
model, tokenizer = get_model_tokenizer_from_local(*args, **kwargs)
Expand All @@ -282,28 +217,21 @@ def get_model_tokenizer_cogvlm2(*args, **kwargs):

register_model(
ModelMeta(
MLLMModelType.cogvlm2,
'CogVLMForCausalLM',
ModelGroup([
Model('ZhipuAI/cogvlm2-llama3-chat-19B', 'THUDM/cogvlm2-llama3-chat-19B'),
Model('ZhipuAI/cogvlm2-llama3-chinese-chat-19B', 'THUDM/cogvlm2-llama3-chinese-chat-19B'),
]),
TemplateType.cogvlm,
get_model_tokenizer_cogvlm2,
is_multimodal=True,
support_gradient_checkpointing=False,
requires=['transformers<4.42'],
support_lmdeploy=True))

register_model(
ModelMeta(
MLLMModelType.cogvlm2_video,
'CogVLMVideoForCausalLM',
ModelGroup([
Model('ZhipuAI/cogvlm2-video-llama3-chat', 'THUDM/cogvlm2-video-llama3-chat'),
], tags=['video']),
TemplateType.cogvlm2_video,
MLLMModelType.cogvlm2, ['CogVLMForCausalLM', 'CogVLMVideoForCausalLM'], [
ModelGroup([
Model('ZhipuAI/cogvlm2-llama3-chat-19B', 'THUDM/cogvlm2-llama3-chat-19B'),
Model('ZhipuAI/cogvlm2-llama3-chinese-chat-19B', 'THUDM/cogvlm2-llama3-chinese-chat-19B'),
],
TemplateType.cogvlm,
requires=['transformers<4.42'],
support_lmdeploy=True),
ModelGroup([
Model('ZhipuAI/cogvlm2-video-llama3-chat', 'THUDM/cogvlm2-video-llama3-chat'),
],
TemplateType.cogvlm2_video,
requires=['transformers>=4.42'],
tags=['video']),
],
get_model_tokenizer_cogvlm2,
is_multimodal=True,
support_gradient_checkpointing=False,
requires=['transformers>=4.42']))
support_gradient_checkpointing=False))
29 changes: 14 additions & 15 deletions swift/llm/model/model/internlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ def get_model_tokenizer_internlm_chat(model_dir: str,

register_model(
ModelMeta(
LLMModelType.internlm,
'InternLMForCausalLM',
ModelGroup([
Model('Shanghai_AI_Laboratory/internlm-7b', 'internlm/internlm-7b'),
Model('Shanghai_AI_Laboratory/internlm-chat-7b', 'internlm/internlm-chat-7b'),
Model('Shanghai_AI_Laboratory/internlm-chat-7b-8k'),
Model('Shanghai_AI_Laboratory/internlm-20b', 'internlm/internlm-20b'),
Model('Shanghai_AI_Laboratory/internlm-chat-20b', 'internlm/internlm-chat-20b'),
]),
TemplateType.internlm,
LLMModelType.internlm, ['InternLMForCausalLM'], [
ModelGroup([
Model('Shanghai_AI_Laboratory/internlm-7b', 'internlm/internlm-7b'),
Model('Shanghai_AI_Laboratory/internlm-chat-7b', 'internlm/internlm-chat-7b'),
Model('Shanghai_AI_Laboratory/internlm-chat-7b-8k'),
Model('Shanghai_AI_Laboratory/internlm-20b', 'internlm/internlm-20b'),
Model('Shanghai_AI_Laboratory/internlm-chat-20b', 'internlm/internlm-chat-20b'),
], TemplateType.internlm)
],
get_model_tokenizer_internlm_chat,
support_vllm=True,
support_lmdeploy=True), )
support_lmdeploy=True))


def get_model_tokenizer_internlm2(model_dir: str,
Expand All @@ -62,8 +61,7 @@ def get_model_tokenizer_internlm2(model_dir: str,

register_model(
ModelMeta(
LLMModelType.internlm2,
'InternLM2ForCausalLM', [
LLMModelType.internlm2, ['InternLM2ForCausalLM'], [
ModelGroup([
Model('Shanghai_AI_Laboratory/internlm2-1_8b', 'internlm/internlm2-1_8b'),
Model('Shanghai_AI_Laboratory/internlm2-chat-1_8b', 'internlm/internlm2-chat-1_8b'),
Expand All @@ -76,13 +74,14 @@ def get_model_tokenizer_internlm2(model_dir: str,
Model('Shanghai_AI_Laboratory/internlm2-20b', 'internlm/internlm2-20b'),
Model('Shanghai_AI_Laboratory/internlm2-chat-20b', 'internlm/internlm2-chat-20b'),
Model('Shanghai_AI_Laboratory/internlm2-chat-20b-sft', 'internlm/internlm2-chat-20b-sft'),
]),
], TemplateType.internlm2),
ModelGroup([
Model('Shanghai_AI_Laboratory/internlm2-math-base-7b', 'internlm/internlm2-math-base-7b'),
Model('Shanghai_AI_Laboratory/internlm2-math-7b', 'internlm/internlm2-math-7b'),
Model('Shanghai_AI_Laboratory/internlm2-math-base-20b', 'internlm/internlm2-math-base-20b'),
Model('Shanghai_AI_Laboratory/internlm2-math-20b', 'internlm/internlm2-math-20b'),
],
TemplateType.internlm2,
tags=['math']),
ModelGroup([
Model('Shanghai_AI_Laboratory/internlm2_5-1_8b', 'internlm/internlm2_5-1_8b'),
Expand All @@ -93,9 +92,9 @@ def get_model_tokenizer_internlm2(model_dir: str,
Model('Shanghai_AI_Laboratory/internlm2_5-20b', 'internlm/internlm2_5-20b'),
Model('Shanghai_AI_Laboratory/internlm2_5-20b-chat', 'internlm/internlm2_5-20b-chat'),
],
TemplateType.internlm2,
tags=['math'])
],
TemplateType.internlm2,
get_model_tokenizer_internlm2,
requires=['transformers>=4.38'],
support_flash_attn=True,
Expand Down
Loading

0 comments on commit ea79337

Please sign in to comment.