Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- added_tokens.json +37 -0
- config.json +210 -0
- configuration_intern_vit.py +119 -0
- configuration_internvl_chat.py +115 -0
- conversation.py +391 -0
- generation_config.json +4 -0
- layer-0-ep-0-of-1.safetensors +3 -0
- layer-1-ep-0-of-1.safetensors +3 -0
- layer-10-ep-0-of-1.safetensors +3 -0
- layer-11-ep-0-of-1.safetensors +3 -0
- layer-12-ep-0-of-1.safetensors +3 -0
- layer-13-ep-0-of-1.safetensors +3 -0
- layer-14-ep-0-of-1.safetensors +3 -0
- layer-15-ep-0-of-1.safetensors +3 -0
- layer-16-ep-0-of-1.safetensors +3 -0
- layer-17-ep-0-of-1.safetensors +3 -0
- layer-18-ep-0-of-1.safetensors +3 -0
- layer-19-ep-0-of-1.safetensors +3 -0
- layer-2-ep-0-of-1.safetensors +3 -0
- layer-20-ep-0-of-1.safetensors +3 -0
- layer-21-ep-0-of-1.safetensors +3 -0
- layer-22-ep-0-of-1.safetensors +3 -0
- layer-23-ep-0-of-1.safetensors +3 -0
- layer-24-ep-0-of-1.safetensors +3 -0
- layer-25-ep-0-of-1.safetensors +3 -0
- layer-26-ep-0-of-1.safetensors +3 -0
- layer-27-ep-0-of-1.safetensors +3 -0
- layer-28-ep-0-of-1.safetensors +3 -0
- layer-29-ep-0-of-1.safetensors +3 -0
- layer-3-ep-0-of-1.safetensors +3 -0
- layer-30-ep-0-of-1.safetensors +3 -0
- layer-31-ep-0-of-1.safetensors +3 -0
- layer-32-ep-0-of-1.safetensors +3 -0
- layer-33-ep-0-of-1.safetensors +3 -0
- layer-34-ep-0-of-1.safetensors +3 -0
- layer-35-ep-0-of-1.safetensors +3 -0
- layer-36-ep-0-of-1.safetensors +3 -0
- layer-37-ep-0-of-1.safetensors +3 -0
- layer-38-ep-0-of-1.safetensors +3 -0
- layer-39-ep-0-of-1.safetensors +3 -0
- layer-4-ep-0-of-1.safetensors +3 -0
- layer-40-ep-0-of-1.safetensors +3 -0
- layer-41-ep-0-of-1.safetensors +3 -0
- layer-42-ep-0-of-1.safetensors +3 -0
- layer-43-ep-0-of-1.safetensors +3 -0
- layer-44-ep-0-of-1.safetensors +3 -0
- layer-45-ep-0-of-1.safetensors +3 -0
- layer-46-ep-0-of-1.safetensors +3 -0
- layer-47-ep-0-of-1.safetensors +3 -0
- layer-5-ep-0-of-1.safetensors +3 -0
added_tokens.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"</box>": 151677,
|
3 |
+
"</img>": 151670,
|
4 |
+
"</quad>": 151673,
|
5 |
+
"</ref>": 151675,
|
6 |
+
"</think>": 151668,
|
7 |
+
"</tool_call>": 151658,
|
8 |
+
"</tool_response>": 151666,
|
9 |
+
"<IMG_CONTEXT>": 151671,
|
10 |
+
"<box>": 151676,
|
11 |
+
"<img>": 151669,
|
12 |
+
"<quad>": 151672,
|
13 |
+
"<ref>": 151674,
|
14 |
+
"<think>": 151667,
|
15 |
+
"<tool_call>": 151657,
|
16 |
+
"<tool_response>": 151665,
|
17 |
+
"<|box_end|>": 151649,
|
18 |
+
"<|box_start|>": 151648,
|
19 |
+
"<|endoftext|>": 151643,
|
20 |
+
"<|file_sep|>": 151664,
|
21 |
+
"<|fim_middle|>": 151660,
|
22 |
+
"<|fim_pad|>": 151662,
|
23 |
+
"<|fim_prefix|>": 151659,
|
24 |
+
"<|fim_suffix|>": 151661,
|
25 |
+
"<|im_end|>": 151645,
|
26 |
+
"<|im_start|>": 151644,
|
27 |
+
"<|image_pad|>": 151655,
|
28 |
+
"<|object_ref_end|>": 151647,
|
29 |
+
"<|object_ref_start|>": 151646,
|
30 |
+
"<|quad_end|>": 151651,
|
31 |
+
"<|quad_start|>": 151650,
|
32 |
+
"<|repo_name|>": 151663,
|
33 |
+
"<|video_pad|>": 151656,
|
34 |
+
"<|vision_end|>": 151653,
|
35 |
+
"<|vision_pad|>": 151654,
|
36 |
+
"<|vision_start|>": 151652
|
37 |
+
}
|
config.json
ADDED
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_commit_hash": null,
|
3 |
+
"architectures": [
|
4 |
+
"InternVLChatModel"
|
5 |
+
],
|
6 |
+
"auto_map": {
|
7 |
+
"AutoConfig": "configuration_internvl_chat.InternVLChatConfig",
|
8 |
+
"AutoModel": "modeling_internvl_chat.InternVLChatModel",
|
9 |
+
"AutoModelForCausalLM": "modeling_internvl_chat.InternVLChatModel"
|
10 |
+
},
|
11 |
+
"downsample_ratio": 0.5,
|
12 |
+
"dynamic_image_size": true,
|
13 |
+
"force_image_size": 448,
|
14 |
+
"llm_config": {
|
15 |
+
"_attn_implementation_autoset": false,
|
16 |
+
"_name_or_path": "/root/codespace/checkpoints/Qwen3-30B-A3B",
|
17 |
+
"add_cross_attention": false,
|
18 |
+
"architectures": [
|
19 |
+
"Qwen3MoeForCausalLM"
|
20 |
+
],
|
21 |
+
"attention_bias": false,
|
22 |
+
"attention_dropout": 0.0,
|
23 |
+
"bad_words_ids": null,
|
24 |
+
"begin_suppress_tokens": null,
|
25 |
+
"bos_token_id": 151643,
|
26 |
+
"chunk_size_feed_forward": 0,
|
27 |
+
"cross_attention_hidden_size": null,
|
28 |
+
"decoder_sparse_step": 1,
|
29 |
+
"decoder_start_token_id": null,
|
30 |
+
"diversity_penalty": 0.0,
|
31 |
+
"do_sample": false,
|
32 |
+
"early_stopping": false,
|
33 |
+
"encoder_no_repeat_ngram_size": 0,
|
34 |
+
"eos_token_id": 151645,
|
35 |
+
"exponential_decay_length_penalty": null,
|
36 |
+
"finetuning_task": null,
|
37 |
+
"forced_bos_token_id": null,
|
38 |
+
"forced_eos_token_id": null,
|
39 |
+
"head_dim": 128,
|
40 |
+
"hidden_act": "silu",
|
41 |
+
"hidden_size": 2048,
|
42 |
+
"id2label": {
|
43 |
+
"0": "LABEL_0",
|
44 |
+
"1": "LABEL_1"
|
45 |
+
},
|
46 |
+
"initializer_range": 0.02,
|
47 |
+
"intermediate_size": 6144,
|
48 |
+
"is_decoder": false,
|
49 |
+
"is_encoder_decoder": false,
|
50 |
+
"label2id": {
|
51 |
+
"LABEL_0": 0,
|
52 |
+
"LABEL_1": 1
|
53 |
+
},
|
54 |
+
"length_penalty": 1.0,
|
55 |
+
"max_length": 20,
|
56 |
+
"max_position_embeddings": 40960,
|
57 |
+
"max_window_layers": 48,
|
58 |
+
"min_length": 0,
|
59 |
+
"mlp_only_layers": [],
|
60 |
+
"model_type": "qwen3_moe",
|
61 |
+
"moe_intermediate_size": 768,
|
62 |
+
"no_repeat_ngram_size": 0,
|
63 |
+
"norm_topk_prob": true,
|
64 |
+
"num_attention_heads": 32,
|
65 |
+
"num_beam_groups": 1,
|
66 |
+
"num_beams": 1,
|
67 |
+
"num_experts": 128,
|
68 |
+
"num_experts_per_tok": 8,
|
69 |
+
"num_hidden_layers": 48,
|
70 |
+
"num_key_value_heads": 4,
|
71 |
+
"num_return_sequences": 1,
|
72 |
+
"output_attentions": false,
|
73 |
+
"output_hidden_states": false,
|
74 |
+
"output_router_logits": false,
|
75 |
+
"output_scores": false,
|
76 |
+
"pad_token_id": null,
|
77 |
+
"prefix": null,
|
78 |
+
"problem_type": null,
|
79 |
+
"pruned_heads": {},
|
80 |
+
"remove_invalid_values": false,
|
81 |
+
"repetition_penalty": 1.0,
|
82 |
+
"return_dict": true,
|
83 |
+
"return_dict_in_generate": false,
|
84 |
+
"rms_norm_eps": 1e-06,
|
85 |
+
"rope_scaling": null,
|
86 |
+
"rope_theta": 1000000.0,
|
87 |
+
"router_aux_loss_coef": 0.001,
|
88 |
+
"sep_token_id": null,
|
89 |
+
"sliding_window": null,
|
90 |
+
"suppress_tokens": null,
|
91 |
+
"task_specific_params": null,
|
92 |
+
"temperature": 1.0,
|
93 |
+
"tf_legacy_loss": false,
|
94 |
+
"tie_encoder_decoder": false,
|
95 |
+
"tie_word_embeddings": false,
|
96 |
+
"tokenizer_class": null,
|
97 |
+
"top_k": 50,
|
98 |
+
"top_p": 1.0,
|
99 |
+
"torch_dtype": "bfloat16",
|
100 |
+
"torchscript": false,
|
101 |
+
"transformers_version": "4.51.1",
|
102 |
+
"typical_p": 1.0,
|
103 |
+
"use_bfloat16": false,
|
104 |
+
"use_cache": true,
|
105 |
+
"use_sliding_window": false,
|
106 |
+
"vocab_size": 151936
|
107 |
+
},
|
108 |
+
"max_dynamic_patch": 12,
|
109 |
+
"min_dynamic_patch": 1,
|
110 |
+
"model_type": "internvl_chat",
|
111 |
+
"pad2square": false,
|
112 |
+
"ps_version": "v2",
|
113 |
+
"select_layer": -1,
|
114 |
+
"template": "internvl2_5",
|
115 |
+
"tie_word_embeddings": false,
|
116 |
+
"torch_dtype": "bfloat16",
|
117 |
+
"transformers_version": null,
|
118 |
+
"use_backbone_lora": 0,
|
119 |
+
"use_llm_lora": 0,
|
120 |
+
"use_thumbnail": true,
|
121 |
+
"vision_config": {
|
122 |
+
"_attn_implementation_autoset": false,
|
123 |
+
"_name_or_path": "",
|
124 |
+
"add_cross_attention": false,
|
125 |
+
"architectures": [
|
126 |
+
"InternVisionModel"
|
127 |
+
],
|
128 |
+
"attention_dropout": 0.0,
|
129 |
+
"auto_map": {
|
130 |
+
"AutoConfig": "configuration_intern_vit.InternVisionConfig",
|
131 |
+
"AutoModel": "modeling_intern_vit.InternVisionModel"
|
132 |
+
},
|
133 |
+
"bad_words_ids": null,
|
134 |
+
"begin_suppress_tokens": null,
|
135 |
+
"bos_token_id": null,
|
136 |
+
"chunk_size_feed_forward": 0,
|
137 |
+
"cross_attention_hidden_size": null,
|
138 |
+
"decoder_start_token_id": null,
|
139 |
+
"diversity_penalty": 0.0,
|
140 |
+
"do_sample": false,
|
141 |
+
"drop_path_rate": 0.1,
|
142 |
+
"dropout": 0.0,
|
143 |
+
"early_stopping": false,
|
144 |
+
"encoder_no_repeat_ngram_size": 0,
|
145 |
+
"eos_token_id": null,
|
146 |
+
"exponential_decay_length_penalty": null,
|
147 |
+
"finetuning_task": null,
|
148 |
+
"forced_bos_token_id": null,
|
149 |
+
"forced_eos_token_id": null,
|
150 |
+
"hidden_act": "gelu",
|
151 |
+
"hidden_size": 1024,
|
152 |
+
"id2label": {
|
153 |
+
"0": "LABEL_0",
|
154 |
+
"1": "LABEL_1"
|
155 |
+
},
|
156 |
+
"image_size": 448,
|
157 |
+
"initializer_factor": 1.0,
|
158 |
+
"initializer_range": 0.02,
|
159 |
+
"intermediate_size": 4096,
|
160 |
+
"is_decoder": false,
|
161 |
+
"is_encoder_decoder": false,
|
162 |
+
"label2id": {
|
163 |
+
"LABEL_0": 0,
|
164 |
+
"LABEL_1": 1
|
165 |
+
},
|
166 |
+
"layer_norm_eps": 1e-06,
|
167 |
+
"length_penalty": 1.0,
|
168 |
+
"max_length": 20,
|
169 |
+
"min_length": 0,
|
170 |
+
"model_type": "intern_vit_6b",
|
171 |
+
"no_repeat_ngram_size": 0,
|
172 |
+
"norm_type": "layer_norm",
|
173 |
+
"num_attention_heads": 16,
|
174 |
+
"num_beam_groups": 1,
|
175 |
+
"num_beams": 1,
|
176 |
+
"num_channels": 3,
|
177 |
+
"num_hidden_layers": 24,
|
178 |
+
"num_return_sequences": 1,
|
179 |
+
"output_attentions": false,
|
180 |
+
"output_hidden_states": false,
|
181 |
+
"output_scores": false,
|
182 |
+
"pad_token_id": null,
|
183 |
+
"patch_size": 14,
|
184 |
+
"prefix": null,
|
185 |
+
"problem_type": null,
|
186 |
+
"pruned_heads": {},
|
187 |
+
"qk_normalization": false,
|
188 |
+
"qkv_bias": true,
|
189 |
+
"remove_invalid_values": false,
|
190 |
+
"repetition_penalty": 1.0,
|
191 |
+
"return_dict": true,
|
192 |
+
"return_dict_in_generate": false,
|
193 |
+
"sep_token_id": null,
|
194 |
+
"suppress_tokens": null,
|
195 |
+
"task_specific_params": null,
|
196 |
+
"temperature": 1.0,
|
197 |
+
"tf_legacy_loss": false,
|
198 |
+
"tie_encoder_decoder": false,
|
199 |
+
"tie_word_embeddings": true,
|
200 |
+
"tokenizer_class": null,
|
201 |
+
"top_k": 50,
|
202 |
+
"top_p": 1.0,
|
203 |
+
"torch_dtype": "bfloat16",
|
204 |
+
"torchscript": false,
|
205 |
+
"transformers_version": "4.51.1",
|
206 |
+
"typical_p": 1.0,
|
207 |
+
"use_bfloat16": false,
|
208 |
+
"use_flash_attn": true
|
209 |
+
}
|
210 |
+
}
|
configuration_intern_vit.py
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# --------------------------------------------------------
|
2 |
+
# InternVL
|
3 |
+
# Copyright (c) 2024 OpenGVLab
|
4 |
+
# Licensed under The MIT License [see LICENSE for details]
|
5 |
+
# --------------------------------------------------------
|
6 |
+
import os
|
7 |
+
from typing import Union
|
8 |
+
|
9 |
+
from transformers.configuration_utils import PretrainedConfig
|
10 |
+
from transformers.utils import logging
|
11 |
+
|
12 |
+
logger = logging.get_logger(__name__)
|
13 |
+
|
14 |
+
|
15 |
+
class InternVisionConfig(PretrainedConfig):
|
16 |
+
r"""
|
17 |
+
This is the configuration class to store the configuration of a [`InternVisionModel`]. It is used to
|
18 |
+
instantiate a vision encoder according to the specified arguments, defining the model architecture.
|
19 |
+
|
20 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
21 |
+
documentation from [`PretrainedConfig`] for more information.
|
22 |
+
|
23 |
+
Args:
|
24 |
+
num_channels (`int`, *optional*, defaults to 3):
|
25 |
+
Number of color channels in the input images (e.g., 3 for RGB).
|
26 |
+
patch_size (`int`, *optional*, defaults to 14):
|
27 |
+
The size (resolution) of each patch.
|
28 |
+
image_size (`int`, *optional*, defaults to 224):
|
29 |
+
The size (resolution) of each image.
|
30 |
+
qkv_bias (`bool`, *optional*, defaults to `False`):
|
31 |
+
Whether to add a bias to the queries and values in the self-attention layers.
|
32 |
+
hidden_size (`int`, *optional*, defaults to 3200):
|
33 |
+
Dimensionality of the encoder layers and the pooler layer.
|
34 |
+
num_attention_heads (`int`, *optional*, defaults to 25):
|
35 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
36 |
+
intermediate_size (`int`, *optional*, defaults to 12800):
|
37 |
+
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
|
38 |
+
qk_normalization (`bool`, *optional*, defaults to `True`):
|
39 |
+
Whether to normalize the queries and keys in the self-attention layers.
|
40 |
+
num_hidden_layers (`int`, *optional*, defaults to 48):
|
41 |
+
Number of hidden layers in the Transformer encoder.
|
42 |
+
use_flash_attn (`bool`, *optional*, defaults to `True`):
|
43 |
+
Whether to use flash attention mechanism.
|
44 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
|
45 |
+
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
|
46 |
+
`"relu"`, `"selu"` and `"gelu_new"` ``"gelu"` are supported.
|
47 |
+
layer_norm_eps (`float`, *optional*, defaults to 1e-6):
|
48 |
+
The epsilon used by the layer normalization layers.
|
49 |
+
dropout (`float`, *optional*, defaults to 0.0):
|
50 |
+
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
|
51 |
+
drop_path_rate (`float`, *optional*, defaults to 0.0):
|
52 |
+
Dropout rate for stochastic depth.
|
53 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
54 |
+
The dropout ratio for the attention probabilities.
|
55 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
56 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
57 |
+
initializer_factor (`float`, *optional*, defaults to 0.1):
|
58 |
+
A factor for layer scale.
|
59 |
+
"""
|
60 |
+
|
61 |
+
model_type = 'intern_vit_6b'
|
62 |
+
|
63 |
+
def __init__(
|
64 |
+
self,
|
65 |
+
num_channels=3,
|
66 |
+
patch_size=14,
|
67 |
+
image_size=224,
|
68 |
+
qkv_bias=False,
|
69 |
+
hidden_size=3200,
|
70 |
+
num_attention_heads=25,
|
71 |
+
intermediate_size=12800,
|
72 |
+
qk_normalization=True,
|
73 |
+
num_hidden_layers=48,
|
74 |
+
use_flash_attn=True,
|
75 |
+
hidden_act='gelu',
|
76 |
+
norm_type='rms_norm',
|
77 |
+
layer_norm_eps=1e-6,
|
78 |
+
dropout=0.0,
|
79 |
+
drop_path_rate=0.0,
|
80 |
+
attention_dropout=0.0,
|
81 |
+
initializer_range=0.02,
|
82 |
+
initializer_factor=0.1,
|
83 |
+
**kwargs,
|
84 |
+
):
|
85 |
+
super().__init__(**kwargs)
|
86 |
+
|
87 |
+
self.hidden_size = hidden_size
|
88 |
+
self.intermediate_size = intermediate_size
|
89 |
+
self.dropout = dropout
|
90 |
+
self.drop_path_rate = drop_path_rate
|
91 |
+
self.num_hidden_layers = num_hidden_layers
|
92 |
+
self.num_attention_heads = num_attention_heads
|
93 |
+
self.num_channels = num_channels
|
94 |
+
self.patch_size = patch_size
|
95 |
+
self.image_size = image_size
|
96 |
+
self.initializer_range = initializer_range
|
97 |
+
self.initializer_factor = initializer_factor
|
98 |
+
self.attention_dropout = attention_dropout
|
99 |
+
self.layer_norm_eps = layer_norm_eps
|
100 |
+
self.hidden_act = hidden_act
|
101 |
+
self.norm_type = norm_type
|
102 |
+
self.qkv_bias = qkv_bias
|
103 |
+
self.qk_normalization = qk_normalization
|
104 |
+
self.use_flash_attn = use_flash_attn
|
105 |
+
|
106 |
+
@classmethod
|
107 |
+
def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> 'PretrainedConfig':
|
108 |
+
config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)
|
109 |
+
|
110 |
+
if 'vision_config' in config_dict:
|
111 |
+
config_dict = config_dict['vision_config']
|
112 |
+
|
113 |
+
if 'model_type' in config_dict and hasattr(cls, 'model_type') and config_dict['model_type'] != cls.model_type:
|
114 |
+
logger.warning(
|
115 |
+
f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
|
116 |
+
f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'
|
117 |
+
)
|
118 |
+
|
119 |
+
return cls.from_dict(config_dict, **kwargs)
|
configuration_internvl_chat.py
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# --------------------------------------------------------
|
2 |
+
# InternVL
|
3 |
+
# Copyright (c) 2024 OpenGVLab
|
4 |
+
# Licensed under The MIT License [see LICENSE for details]
|
5 |
+
# --------------------------------------------------------
|
6 |
+
|
7 |
+
import copy
|
8 |
+
from typing import Dict, Any, Optional
|
9 |
+
|
10 |
+
from transformers.configuration_utils import PretrainedConfig
|
11 |
+
from transformers.utils import logging
|
12 |
+
|
13 |
+
from .configuration_intern_vit import InternVisionConfig
|
14 |
+
|
15 |
+
logger = logging.get_logger(__name__)
|
16 |
+
|
17 |
+
|
18 |
+
class InternVLChatConfig(PretrainedConfig):
|
19 |
+
model_type = 'internvl_chat'
|
20 |
+
is_composition = True
|
21 |
+
|
22 |
+
def __init__(
|
23 |
+
self,
|
24 |
+
vision_config: Optional[Dict[str, Any]] = None,
|
25 |
+
llm_config: Optional[Dict[str, Any]] = None,
|
26 |
+
use_backbone_lora=0,
|
27 |
+
use_llm_lora=0,
|
28 |
+
select_layer=-1,
|
29 |
+
force_image_size=None,
|
30 |
+
downsample_ratio=0.5,
|
31 |
+
template=None,
|
32 |
+
dynamic_image_size=False,
|
33 |
+
use_thumbnail=False,
|
34 |
+
ps_version="v1",
|
35 |
+
min_dynamic_patch=1,
|
36 |
+
max_dynamic_patch=6,
|
37 |
+
**kwargs,
|
38 |
+
):
|
39 |
+
super().__init__(**kwargs)
|
40 |
+
|
41 |
+
if vision_config is None:
|
42 |
+
vision_config = {'architectures': ['InternVisionModel']}
|
43 |
+
logger.info('vision_config is None. Initializing the InternVisionConfig with default values.')
|
44 |
+
|
45 |
+
if llm_config is None:
|
46 |
+
llm_config = {'architectures': ['Qwen2ForCausalLM']}
|
47 |
+
logger.info('llm_config is None. Initializing the LlamaConfig config with default values (`LlamaConfig`).')
|
48 |
+
assert 'architectures' in llm_config, "Should specify architecture in llm_config"
|
49 |
+
|
50 |
+
if isinstance(vision_config, dict):
|
51 |
+
self.vision_config = InternVisionConfig(**vision_config)
|
52 |
+
else:
|
53 |
+
self.vision_config = vision_config
|
54 |
+
|
55 |
+
if isinstance(llm_config, dict):
|
56 |
+
architecture: str = llm_config['architectures'][0]
|
57 |
+
if architecture == 'LlamaForCausalLM':
|
58 |
+
from transformers import LlamaConfig
|
59 |
+
self.llm_config = LlamaConfig(**llm_config)
|
60 |
+
elif architecture == 'Qwen2ForCausalLM':
|
61 |
+
from transformers import Qwen2Config
|
62 |
+
self.llm_config = Qwen2Config(**llm_config)
|
63 |
+
elif architecture == 'Qwen3MoeForCausalLM':
|
64 |
+
from transformers import Qwen3MoeConfig
|
65 |
+
self.llm_config = Qwen3MoeConfig(**llm_config)
|
66 |
+
elif architecture == 'Qwen3ForCausalLM':
|
67 |
+
from transformers import Qwen3Config
|
68 |
+
self.llm_config = Qwen3Config(**llm_config)
|
69 |
+
else:
|
70 |
+
raise ValueError('Unsupported architecture: {}'.format(architecture))
|
71 |
+
else:
|
72 |
+
self.llm_config = llm_config
|
73 |
+
|
74 |
+
self.use_backbone_lora = use_backbone_lora
|
75 |
+
self.use_llm_lora = use_llm_lora
|
76 |
+
self.select_layer = select_layer
|
77 |
+
self.force_image_size = force_image_size
|
78 |
+
self.downsample_ratio = downsample_ratio
|
79 |
+
self.template = template
|
80 |
+
self.dynamic_image_size = dynamic_image_size
|
81 |
+
self.use_thumbnail = use_thumbnail
|
82 |
+
self.ps_version = ps_version # pixel shuffle version
|
83 |
+
self.min_dynamic_patch = min_dynamic_patch
|
84 |
+
self.max_dynamic_patch = max_dynamic_patch
|
85 |
+
self.tie_word_embeddings = self.llm_config.tie_word_embeddings
|
86 |
+
|
87 |
+
logger.info(f'vision_select_layer: {self.select_layer}')
|
88 |
+
logger.info(f'ps_version: {self.ps_version}')
|
89 |
+
logger.info(f'min_dynamic_patch: {self.min_dynamic_patch}')
|
90 |
+
logger.info(f'max_dynamic_patch: {self.max_dynamic_patch}')
|
91 |
+
|
92 |
+
def to_dict(self):
|
93 |
+
"""
|
94 |
+
Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`].
|
95 |
+
|
96 |
+
Returns:
|
97 |
+
`Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
|
98 |
+
"""
|
99 |
+
output = copy.deepcopy(self.__dict__)
|
100 |
+
output['vision_config'] = self.vision_config.to_dict()
|
101 |
+
output['llm_config'] = self.llm_config.to_dict()
|
102 |
+
output['model_type'] = self.__class__.model_type
|
103 |
+
output['use_backbone_lora'] = self.use_backbone_lora
|
104 |
+
output['use_llm_lora'] = self.use_llm_lora
|
105 |
+
output['select_layer'] = self.select_layer
|
106 |
+
output['force_image_size'] = self.force_image_size
|
107 |
+
output['downsample_ratio'] = self.downsample_ratio
|
108 |
+
output['template'] = self.template
|
109 |
+
output['dynamic_image_size'] = self.dynamic_image_size
|
110 |
+
output['use_thumbnail'] = self.use_thumbnail
|
111 |
+
output['ps_version'] = self.ps_version
|
112 |
+
output['min_dynamic_patch'] = self.min_dynamic_patch
|
113 |
+
output['max_dynamic_patch'] = self.max_dynamic_patch
|
114 |
+
|
115 |
+
return output
|
conversation.py
ADDED
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Conversation prompt templates.
|
3 |
+
|
4 |
+
We kindly request that you import fastchat instead of copying this file if you wish to use it.
|
5 |
+
If you have changes in mind, please contribute back so the community can benefit collectively and continue to maintain these valuable templates.
|
6 |
+
|
7 |
+
Modified from https://github.com/lm-sys/FastChat/blob/main/fastchat/conversation.py
|
8 |
+
"""
|
9 |
+
|
10 |
+
import dataclasses
|
11 |
+
from enum import IntEnum, auto
|
12 |
+
from typing import Dict, List, Tuple, Union
|
13 |
+
|
14 |
+
|
15 |
+
class SeparatorStyle(IntEnum):
|
16 |
+
"""Separator styles."""
|
17 |
+
|
18 |
+
ADD_COLON_SINGLE = auto()
|
19 |
+
ADD_COLON_TWO = auto()
|
20 |
+
ADD_COLON_SPACE_SINGLE = auto()
|
21 |
+
NO_COLON_SINGLE = auto()
|
22 |
+
NO_COLON_TWO = auto()
|
23 |
+
ADD_NEW_LINE_SINGLE = auto()
|
24 |
+
LLAMA2 = auto()
|
25 |
+
CHATGLM = auto()
|
26 |
+
CHATML = auto()
|
27 |
+
CHATINTERN = auto()
|
28 |
+
DOLLY = auto()
|
29 |
+
RWKV = auto()
|
30 |
+
PHOENIX = auto()
|
31 |
+
ROBIN = auto()
|
32 |
+
FALCON_CHAT = auto()
|
33 |
+
CHATGLM3 = auto()
|
34 |
+
INTERNVL_ZH = auto()
|
35 |
+
MPT = auto()
|
36 |
+
|
37 |
+
|
38 |
+
@dataclasses.dataclass
|
39 |
+
class Conversation:
|
40 |
+
"""A class that manages prompt templates and keeps all conversation history."""
|
41 |
+
|
42 |
+
# The name of this template
|
43 |
+
name: str
|
44 |
+
# The template of the system prompt
|
45 |
+
system_template: str = '{system_message}'
|
46 |
+
# The system message
|
47 |
+
system_message: str = ''
|
48 |
+
# The names of two roles
|
49 |
+
roles: Tuple[str] = ('USER', 'ASSISTANT')
|
50 |
+
# All messages. Each item is (role, message).
|
51 |
+
messages: List[List[str]] = ()
|
52 |
+
# The number of few shot examples
|
53 |
+
offset: int = 0
|
54 |
+
# The separator style and configurations
|
55 |
+
sep_style: SeparatorStyle = SeparatorStyle.ADD_COLON_SINGLE
|
56 |
+
sep: str = '\n'
|
57 |
+
sep2: str = None
|
58 |
+
# Stop criteria (the default one is EOS token)
|
59 |
+
stop_str: Union[str, List[str]] = None
|
60 |
+
# Stops generation if meeting any token in this list
|
61 |
+
stop_token_ids: List[int] = None
|
62 |
+
|
63 |
+
def get_prompt(self) -> str:
|
64 |
+
"""Get the prompt for generation."""
|
65 |
+
system_prompt = self.system_template.format(system_message=self.system_message)
|
66 |
+
if self.sep_style == SeparatorStyle.ADD_COLON_SINGLE:
|
67 |
+
ret = system_prompt + self.sep
|
68 |
+
for role, message in self.messages:
|
69 |
+
if message:
|
70 |
+
ret += role + ': ' + message + self.sep
|
71 |
+
else:
|
72 |
+
ret += role + ':'
|
73 |
+
return ret
|
74 |
+
elif self.sep_style == SeparatorStyle.ADD_COLON_TWO:
|
75 |
+
seps = [self.sep, self.sep2]
|
76 |
+
ret = system_prompt + seps[0]
|
77 |
+
for i, (role, message) in enumerate(self.messages):
|
78 |
+
if message:
|
79 |
+
ret += role + ': ' + message + seps[i % 2]
|
80 |
+
else:
|
81 |
+
ret += role + ':'
|
82 |
+
return ret
|
83 |
+
elif self.sep_style == SeparatorStyle.ADD_COLON_SPACE_SINGLE:
|
84 |
+
ret = system_prompt + self.sep
|
85 |
+
for role, message in self.messages:
|
86 |
+
if message:
|
87 |
+
ret += role + ': ' + message + self.sep
|
88 |
+
else:
|
89 |
+
ret += role + ': ' # must be end with a space
|
90 |
+
return ret
|
91 |
+
elif self.sep_style == SeparatorStyle.ADD_NEW_LINE_SINGLE:
|
92 |
+
ret = '' if system_prompt == '' else system_prompt + self.sep
|
93 |
+
for role, message in self.messages:
|
94 |
+
if message:
|
95 |
+
ret += role + '\n' + message + self.sep
|
96 |
+
else:
|
97 |
+
ret += role + '\n'
|
98 |
+
return ret
|
99 |
+
elif self.sep_style == SeparatorStyle.NO_COLON_SINGLE:
|
100 |
+
ret = system_prompt
|
101 |
+
for role, message in self.messages:
|
102 |
+
if message:
|
103 |
+
ret += role + message + self.sep
|
104 |
+
else:
|
105 |
+
ret += role
|
106 |
+
return ret
|
107 |
+
elif self.sep_style == SeparatorStyle.NO_COLON_TWO:
|
108 |
+
seps = [self.sep, self.sep2]
|
109 |
+
ret = system_prompt
|
110 |
+
for i, (role, message) in enumerate(self.messages):
|
111 |
+
if message:
|
112 |
+
ret += role + message + seps[i % 2]
|
113 |
+
else:
|
114 |
+
ret += role
|
115 |
+
return ret
|
116 |
+
elif self.sep_style == SeparatorStyle.RWKV:
|
117 |
+
ret = system_prompt
|
118 |
+
for i, (role, message) in enumerate(self.messages):
|
119 |
+
if message:
|
120 |
+
ret += (
|
121 |
+
role
|
122 |
+
+ ': '
|
123 |
+
+ message.replace('\r\n', '\n').replace('\n\n', '\n')
|
124 |
+
)
|
125 |
+
ret += '\n\n'
|
126 |
+
else:
|
127 |
+
ret += role + ':'
|
128 |
+
return ret
|
129 |
+
elif self.sep_style == SeparatorStyle.LLAMA2:
|
130 |
+
seps = [self.sep, self.sep2]
|
131 |
+
if self.system_message:
|
132 |
+
ret = system_prompt
|
133 |
+
else:
|
134 |
+
ret = '[INST] '
|
135 |
+
for i, (role, message) in enumerate(self.messages):
|
136 |
+
tag = self.roles[i % 2]
|
137 |
+
if message:
|
138 |
+
if i == 0:
|
139 |
+
ret += message + ' '
|
140 |
+
else:
|
141 |
+
ret += tag + ' ' + message + seps[i % 2]
|
142 |
+
else:
|
143 |
+
ret += tag
|
144 |
+
return ret
|
145 |
+
elif self.sep_style == SeparatorStyle.CHATGLM:
|
146 |
+
# source: https://huggingface.co/THUDM/chatglm-6b/blob/1d240ba371910e9282298d4592532d7f0f3e9f3e/modeling_chatglm.py#L1302-L1308
|
147 |
+
# source2: https://huggingface.co/THUDM/chatglm2-6b/blob/e186c891cf64310ac66ef10a87e6635fa6c2a579/modeling_chatglm.py#L926
|
148 |
+
round_add_n = 1 if self.name == 'chatglm2' else 0
|
149 |
+
if system_prompt:
|
150 |
+
ret = system_prompt + self.sep
|
151 |
+
else:
|
152 |
+
ret = ''
|
153 |
+
|
154 |
+
for i, (role, message) in enumerate(self.messages):
|
155 |
+
if i % 2 == 0:
|
156 |
+
ret += f'[Round {i//2 + round_add_n}]{self.sep}'
|
157 |
+
|
158 |
+
if message:
|
159 |
+
ret += f'{role}:{message}{self.sep}'
|
160 |
+
else:
|
161 |
+
ret += f'{role}:'
|
162 |
+
return ret
|
163 |
+
elif self.sep_style == SeparatorStyle.CHATML:
|
164 |
+
ret = '' if system_prompt == '' else system_prompt + self.sep + '\n'
|
165 |
+
for role, message in self.messages:
|
166 |
+
if message:
|
167 |
+
ret += role + '\n' + message + self.sep + '\n'
|
168 |
+
else:
|
169 |
+
ret += role + '\n'
|
170 |
+
return ret
|
171 |
+
elif self.sep_style == SeparatorStyle.CHATGLM3:
|
172 |
+
ret = ''
|
173 |
+
if self.system_message:
|
174 |
+
ret += system_prompt
|
175 |
+
for role, message in self.messages:
|
176 |
+
if message:
|
177 |
+
ret += role + '\n' + ' ' + message
|
178 |
+
else:
|
179 |
+
ret += role
|
180 |
+
return ret
|
181 |
+
elif self.sep_style == SeparatorStyle.CHATINTERN:
|
182 |
+
# source: https://huggingface.co/internlm/internlm-chat-7b-8k/blob/bd546fa984b4b0b86958f56bf37f94aa75ab8831/modeling_internlm.py#L771
|
183 |
+
seps = [self.sep, self.sep2]
|
184 |
+
ret = system_prompt
|
185 |
+
for i, (role, message) in enumerate(self.messages):
|
186 |
+
# if i % 2 == 0:
|
187 |
+
# ret += "<s>"
|
188 |
+
if message:
|
189 |
+
ret += role + ':' + message + seps[i % 2] + '\n'
|
190 |
+
else:
|
191 |
+
ret += role + ':'
|
192 |
+
return ret
|
193 |
+
elif self.sep_style == SeparatorStyle.DOLLY:
|
194 |
+
seps = [self.sep, self.sep2]
|
195 |
+
ret = system_prompt
|
196 |
+
for i, (role, message) in enumerate(self.messages):
|
197 |
+
if message:
|
198 |
+
ret += role + ':\n' + message + seps[i % 2]
|
199 |
+
if i % 2 == 1:
|
200 |
+
ret += '\n\n'
|
201 |
+
else:
|
202 |
+
ret += role + ':\n'
|
203 |
+
return ret
|
204 |
+
elif self.sep_style == SeparatorStyle.PHOENIX:
|
205 |
+
ret = system_prompt
|
206 |
+
for role, message in self.messages:
|
207 |
+
if message:
|
208 |
+
ret += role + ': ' + '<s>' + message + '</s>'
|
209 |
+
else:
|
210 |
+
ret += role + ': ' + '<s>'
|
211 |
+
return ret
|
212 |
+
elif self.sep_style == SeparatorStyle.ROBIN:
|
213 |
+
ret = system_prompt + self.sep
|
214 |
+
for role, message in self.messages:
|
215 |
+
if message:
|
216 |
+
ret += role + ':\n' + message + self.sep
|
217 |
+
else:
|
218 |
+
ret += role + ':\n'
|
219 |
+
return ret
|
220 |
+
elif self.sep_style == SeparatorStyle.FALCON_CHAT:
|
221 |
+
ret = ''
|
222 |
+
if self.system_message:
|
223 |
+
ret += system_prompt + self.sep
|
224 |
+
for role, message in self.messages:
|
225 |
+
if message:
|
226 |
+
ret += role + ': ' + message + self.sep
|
227 |
+
else:
|
228 |
+
ret += role + ':'
|
229 |
+
|
230 |
+
return ret
|
231 |
+
elif self.sep_style == SeparatorStyle.INTERNVL_ZH:
|
232 |
+
seps = [self.sep, self.sep2]
|
233 |
+
ret = self.system_message + seps[0]
|
234 |
+
for i, (role, message) in enumerate(self.messages):
|
235 |
+
if message:
|
236 |
+
ret += role + ': ' + message + seps[i % 2]
|
237 |
+
else:
|
238 |
+
ret += role + ':'
|
239 |
+
return ret
|
240 |
+
elif self.sep_style == SeparatorStyle.MPT:
|
241 |
+
ret = system_prompt + self.sep
|
242 |
+
for role, message in self.messages:
|
243 |
+
if message:
|
244 |
+
if type(message) is tuple:
|
245 |
+
message, _, _ = message
|
246 |
+
ret += role + message + self.sep
|
247 |
+
else:
|
248 |
+
ret += role
|
249 |
+
return ret
|
250 |
+
else:
|
251 |
+
raise ValueError(f'Invalid style: {self.sep_style}')
|
252 |
+
|
253 |
+
def set_system_message(self, system_message: str):
|
254 |
+
"""Set the system message."""
|
255 |
+
self.system_message = system_message
|
256 |
+
|
257 |
+
def append_message(self, role: str, message: str):
|
258 |
+
"""Append a new message."""
|
259 |
+
self.messages.append([role, message])
|
260 |
+
|
261 |
+
def update_last_message(self, message: str):
|
262 |
+
"""Update the last output.
|
263 |
+
|
264 |
+
The last message is typically set to be None when constructing the prompt,
|
265 |
+
so we need to update it in-place after getting the response from a model.
|
266 |
+
"""
|
267 |
+
self.messages[-1][1] = message
|
268 |
+
|
269 |
+
def to_gradio_chatbot(self):
|
270 |
+
"""Convert the conversation to gradio chatbot format."""
|
271 |
+
ret = []
|
272 |
+
for i, (role, msg) in enumerate(self.messages[self.offset :]):
|
273 |
+
if i % 2 == 0:
|
274 |
+
ret.append([msg, None])
|
275 |
+
else:
|
276 |
+
ret[-1][-1] = msg
|
277 |
+
return ret
|
278 |
+
|
279 |
+
def to_openai_api_messages(self):
|
280 |
+
"""Convert the conversation to OpenAI chat completion format."""
|
281 |
+
ret = [{'role': 'system', 'content': self.system_message}]
|
282 |
+
|
283 |
+
for i, (_, msg) in enumerate(self.messages[self.offset :]):
|
284 |
+
if i % 2 == 0:
|
285 |
+
ret.append({'role': 'user', 'content': msg})
|
286 |
+
else:
|
287 |
+
if msg is not None:
|
288 |
+
ret.append({'role': 'assistant', 'content': msg})
|
289 |
+
return ret
|
290 |
+
|
291 |
+
def copy(self):
|
292 |
+
return Conversation(
|
293 |
+
name=self.name,
|
294 |
+
system_template=self.system_template,
|
295 |
+
system_message=self.system_message,
|
296 |
+
roles=self.roles,
|
297 |
+
messages=[[x, y] for x, y in self.messages],
|
298 |
+
offset=self.offset,
|
299 |
+
sep_style=self.sep_style,
|
300 |
+
sep=self.sep,
|
301 |
+
sep2=self.sep2,
|
302 |
+
stop_str=self.stop_str,
|
303 |
+
stop_token_ids=self.stop_token_ids,
|
304 |
+
)
|
305 |
+
|
306 |
+
def dict(self):
|
307 |
+
return {
|
308 |
+
'template_name': self.name,
|
309 |
+
'system_message': self.system_message,
|
310 |
+
'roles': self.roles,
|
311 |
+
'messages': self.messages,
|
312 |
+
'offset': self.offset,
|
313 |
+
}
|
314 |
+
|
315 |
+
|
316 |
+
# A global registry for all conversation templates
|
317 |
+
conv_templates: Dict[str, Conversation] = {}
|
318 |
+
|
319 |
+
|
320 |
+
def register_conv_template(template: Conversation, override: bool = False):
|
321 |
+
"""Register a new conversation template."""
|
322 |
+
if not override:
|
323 |
+
assert (
|
324 |
+
template.name not in conv_templates
|
325 |
+
), f'{template.name} has been registered.'
|
326 |
+
|
327 |
+
conv_templates[template.name] = template
|
328 |
+
|
329 |
+
|
330 |
+
def get_conv_template(name: str) -> Conversation:
|
331 |
+
"""Get a conversation template."""
|
332 |
+
return conv_templates[name].copy()
|
333 |
+
|
334 |
+
|
335 |
+
# Both Hermes-2 and internlm2-chat are chatml-format conversation templates. The difference
|
336 |
+
# is that during training, the preprocessing function for the Hermes-2 template doesn't add
|
337 |
+
# <s> at the beginning of the tokenized sequence, while the internlm2-chat template does.
|
338 |
+
# Therefore, they are completely equivalent during inference.
|
339 |
+
register_conv_template(
|
340 |
+
Conversation(
|
341 |
+
name='Hermes-2',
|
342 |
+
system_template='<|im_start|>system\n{system_message}',
|
343 |
+
# note: The new system prompt was not used here to avoid changes in benchmark performance.
|
344 |
+
# system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。',
|
345 |
+
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
346 |
+
roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
|
347 |
+
sep_style=SeparatorStyle.MPT,
|
348 |
+
sep='<|im_end|>',
|
349 |
+
stop_str='<|endoftext|>',
|
350 |
+
)
|
351 |
+
)
|
352 |
+
|
353 |
+
|
354 |
+
register_conv_template(
|
355 |
+
Conversation(
|
356 |
+
name='internlm2-chat',
|
357 |
+
system_template='<|im_start|>system\n{system_message}',
|
358 |
+
# note: The new system prompt was not used here to avoid changes in benchmark performance.
|
359 |
+
# system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。',
|
360 |
+
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
361 |
+
roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
|
362 |
+
sep_style=SeparatorStyle.MPT,
|
363 |
+
sep='<|im_end|>',
|
364 |
+
)
|
365 |
+
)
|
366 |
+
|
367 |
+
|
368 |
+
register_conv_template(
|
369 |
+
Conversation(
|
370 |
+
name='phi3-chat',
|
371 |
+
system_template='<|system|>\n{system_message}',
|
372 |
+
# note: The new system prompt was not used here to avoid changes in benchmark performance.
|
373 |
+
# system_message='我是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。',
|
374 |
+
system_message='你是由上海人工智能实验室联合商汤科技开发的书生多模态大模型,英文名叫InternVL, 是一个有用无害的人工智能助手。',
|
375 |
+
roles=('<|user|>\n', '<|assistant|>\n'),
|
376 |
+
sep_style=SeparatorStyle.MPT,
|
377 |
+
sep='<|end|>',
|
378 |
+
)
|
379 |
+
)
|
380 |
+
|
381 |
+
|
382 |
+
register_conv_template(
|
383 |
+
Conversation(
|
384 |
+
name='internvl2_5',
|
385 |
+
system_template='<|im_start|>system\n{system_message}',
|
386 |
+
system_message='你是书生·万象,英文名是InternVL,是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。',
|
387 |
+
roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),
|
388 |
+
sep_style=SeparatorStyle.MPT,
|
389 |
+
sep='<|im_end|>\n',
|
390 |
+
)
|
391 |
+
)
|
generation_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"transformers_version": "4.52.1"
|
4 |
+
}
|
layer-0-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ee66bf290e50e96e7f66c82c06d7a5de6ddb6af1e8efc0d13e12fc585c2b881c
|
3 |
+
size 1246294904
|
layer-1-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:18763acdaa84a7fca020396f6a35b9106c44872b04e61fff28e5e2b87d691a06
|
3 |
+
size 1246294904
|
layer-10-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c9af2fd1e5365f7af259e068339c2c77fc203a9421549e34c864ec52a068612
|
3 |
+
size 1246295296
|
layer-11-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1c7668095093560b6d7ac58fe81a7e857f14609e1157b971dcd78d5ef20fccf4
|
3 |
+
size 1246295296
|
layer-12-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:07c09d8d5a9df6db679e0ec0c2d8b9e44ae9a4cfcaabbe4982c3bd06412037ff
|
3 |
+
size 1246295296
|
layer-13-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:de88b37cb979c20e82467934b688bfebdf55ac04e71ea0b4337e03912df9d9c8
|
3 |
+
size 1246295296
|
layer-14-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:528165f83c4a80492059a3a693cb3011b3951ebcb935caf5588133f9f8bfcd53
|
3 |
+
size 1246295296
|
layer-15-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3cdc3b962ca3a6dd2b80ee1df00e54258d04943de7f7e178f2707573b46ea476
|
3 |
+
size 1246295296
|
layer-16-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e42614ecb82233ba9e43f2a8bef952d7478918ff97ddff8dd215d64670b4014e
|
3 |
+
size 1246295296
|
layer-17-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2bba280db670e68226315b85989b04468ab5209515f7a1bc397d9d4868621fae
|
3 |
+
size 1246295296
|
layer-18-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5c2ee34e0d53dd1fd129c785a7074a80ae6cbdd9fe11c32f893d46a2194de6c7
|
3 |
+
size 1246295296
|
layer-19-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8479b27b059802418482c2b6c42b83c449a45925e4b658052299dc260865a6c5
|
3 |
+
size 1246295296
|
layer-2-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a8558c196405c5cf19b62aed3cd643d917cf83e9ddcb0f71a200b03a9c77283d
|
3 |
+
size 1246294904
|
layer-20-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0efb373c5eb27591658fecd529cfc660b03a937f418fd20aced8cef0ddff91fc
|
3 |
+
size 1246295296
|
layer-21-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:77c723ba6a24a884ffcf20e6eb665ed9d15e40c3e5af9e8459b81c20e6445a90
|
3 |
+
size 1246295296
|
layer-22-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ffaebf9c9e6def0aca5238b76923a563a90375545c46d6ed5ce972eb31300400
|
3 |
+
size 1246295296
|
layer-23-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c32e024a08995a5407ec5d85877873e1b38a4b6c99f701617558c78d8bdf0ffc
|
3 |
+
size 1246295296
|
layer-24-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ad24c42beaaf802dffaefca03550a3798eaa1b0eff4ec73d837713dd85356e93
|
3 |
+
size 1246295296
|
layer-25-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dcb15b68e748ba4fb1d0843823b085c1a2e3ea38c0472db50a03d588d5c4f125
|
3 |
+
size 1246295296
|
layer-26-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:92def755e02936d20fbb99b467fe8f5f4cc19b266fadba3821326b01bc2bdd93
|
3 |
+
size 1246295296
|
layer-27-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5761832dc90f314674017c5ac787005f8057ae8e1dbcf87f767b203c91190968
|
3 |
+
size 1246295296
|
layer-28-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b5af3888674c071f91dce4fe3c0c9aa8e014c8dbdb1f2035b10ddacf553d2c28
|
3 |
+
size 1246295296
|
layer-29-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8c2da8ab7e1b7998257f1037f82bf9c89e58e3ba94212b83e3fcb1ffd71eb8f0
|
3 |
+
size 1246295296
|
layer-3-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c9c36808ab0a4dd709157d0d79a669bce7567cc9b6801f2504552bae88249478
|
3 |
+
size 1246294904
|
layer-30-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:565eeaaeed80829d0c1c26c183dda3361a41115ce1091c573fe374c30913d92e
|
3 |
+
size 1246295296
|
layer-31-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2aba5cf458c9b8838245cf477dbf0f63235a243ab990c3696c18ab54f6c2523f
|
3 |
+
size 1246295296
|
layer-32-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0517c816a838e658ede030d39aa36c52ddc7e0899aee3b09eae644e2ec59b242
|
3 |
+
size 1246295296
|
layer-33-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:024da2a7352e7154658e1ad47c8120ed0b560b868144be7b7a4e9c0e0ae8f1fb
|
3 |
+
size 1246295296
|
layer-34-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:13609c95962b118b7aea0c8dccae5e5c7932d482dc6a8979a45c47a5d115ce49
|
3 |
+
size 1246295296
|
layer-35-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:08f78c3aefd4bdea236d4198e846aca6a6b3e1972587a84ee6feba554658a3ca
|
3 |
+
size 1246295296
|
layer-36-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7a6630fff56e3a04bfa3bc7b7beeaea1892101338eb21c8f04a39fe51cef5f78
|
3 |
+
size 1246295296
|
layer-37-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:abbf1a0b06d10d663b26d152a7460f0b3c0d2ea2b00957bc9b1ae46f02c819ab
|
3 |
+
size 1246295296
|
layer-38-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9f88369ac6913eb579ab11c40eb48957d7036ddfd89c0364a6d59363a8ca36df
|
3 |
+
size 1246295296
|
layer-39-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:67b9f2760cf5c8d4318ecb985eacedcb46f452a26950201520bad64aad790da4
|
3 |
+
size 1246295296
|
layer-4-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a6066a242beceb42a9b11aa31db9e520472e63102a11ec0eebd67045bacb40f3
|
3 |
+
size 1246294904
|
layer-40-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:92f68f986e520f0cde6ccf5866100423b9c92dabe7adb0d66e1101745a880167
|
3 |
+
size 1246295296
|
layer-41-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f550598f6b9b082fd76fa93872fb73ae282e0953e71522a90a4b8477b06da66b
|
3 |
+
size 1246295296
|
layer-42-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b1cddc1c0e6dca07be703559836006456150b8140f422b2b1db31e5087f13f9a
|
3 |
+
size 1246295296
|
layer-43-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:711e18763782ff84e764e7dd59b32021ce29d8918255ed8c7c87d9d77aaeee9c
|
3 |
+
size 1246295296
|
layer-44-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8c7ad19a74a064bc241bad4e7006a9f4bb6ff7281d9c820632cbcdc64b97220c
|
3 |
+
size 1246295296
|
layer-45-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c2ad2e476b5aebbbb43f4fc1d92310034912b9551135da8754126628867c457f
|
3 |
+
size 1246295296
|
layer-46-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a951049b957492b4cfaa8b5eb1ff343145e9312e0e25b7e6f26c93adba9b0e67
|
3 |
+
size 1246295296
|
layer-47-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8519321dcfa38bf5790fef6dfed8d9feed67362ebd26737f1ca9435a4711f292
|
3 |
+
size 1246295296
|
layer-5-ep-0-of-1.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:44a8602760b3a7ea3d12a0c97912f58db520ada6a35789716bd4ca06a6c11a36
|
3 |
+
size 1246294904
|