Upload 11 files
Browse files- .gitattributes +4 -0
- config.json +0 -0
- main_api +3 -0
- main_ax650 +3 -0
- main_axcl_aarch64 +3 -0
- main_axcl_x86 +3 -0
- post_config.json +14 -0
- qwen2.5_tokenizer/tokenizer.json +0 -0
- qwen2.5_tokenizer/tokenizer_config.json +207 -0
- qwen2.5_tokenizer_uid.py +189 -0
- run_qwen2.5_7b_ctx_ax650.sh +16 -0
- run_qwen2.5_7b_ctx_int4_ax650.sh +16 -0
.gitattributes
CHANGED
@@ -34,3 +34,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
*.axmodel filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
*.axmodel filter=lfs diff=lfs merge=lfs -text
|
37 |
+
main_api filter=lfs diff=lfs merge=lfs -text
|
38 |
+
main_ax650 filter=lfs diff=lfs merge=lfs -text
|
39 |
+
main_axcl_aarch64 filter=lfs diff=lfs merge=lfs -text
|
40 |
+
main_axcl_x86 filter=lfs diff=lfs merge=lfs -text
|
config.json
ADDED
File without changes
|
main_api
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:62b7513d89f85942737d80db99a839a9f65b3ed9380ecd45381ec15656dc17b2
|
3 |
+
size 1064648
|
main_ax650
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:870254b83b53d8f1909a03d2e73b0049fd5541e848579fc530888d07c28a48a2
|
3 |
+
size 989368
|
main_axcl_aarch64
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:03012513d42b834360fac6e61aa8b7387deb4f5ecd9f9c86d0b208e608b8c991
|
3 |
+
size 1724632
|
main_axcl_x86
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5f872d9f2238ec7db7ce3a075d52a673bac7b5a7e18455a81852b80223037ae3
|
3 |
+
size 1839824
|
post_config.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"enable_temperature" : false,
|
3 |
+
"temperature" : 0.9,
|
4 |
+
|
5 |
+
"enable_repetition_penalty" : false,
|
6 |
+
"repetition_penalty" : 1.2,
|
7 |
+
"penalty_window" : 20,
|
8 |
+
|
9 |
+
"enable_top_p_sampling" : false,
|
10 |
+
"top_p" : 0.8,
|
11 |
+
|
12 |
+
"enable_top_k_sampling" : false,
|
13 |
+
"top_k" : 10
|
14 |
+
}
|
qwen2.5_tokenizer/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
qwen2.5_tokenizer/tokenizer_config.json
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_bos_token": false,
|
3 |
+
"add_prefix_space": false,
|
4 |
+
"added_tokens_decoder": {
|
5 |
+
"151643": {
|
6 |
+
"content": "<|endoftext|>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false,
|
11 |
+
"special": true
|
12 |
+
},
|
13 |
+
"151644": {
|
14 |
+
"content": "<|im_start|>",
|
15 |
+
"lstrip": false,
|
16 |
+
"normalized": false,
|
17 |
+
"rstrip": false,
|
18 |
+
"single_word": false,
|
19 |
+
"special": true
|
20 |
+
},
|
21 |
+
"151645": {
|
22 |
+
"content": "<|im_end|>",
|
23 |
+
"lstrip": false,
|
24 |
+
"normalized": false,
|
25 |
+
"rstrip": false,
|
26 |
+
"single_word": false,
|
27 |
+
"special": true
|
28 |
+
},
|
29 |
+
"151646": {
|
30 |
+
"content": "<|object_ref_start|>",
|
31 |
+
"lstrip": false,
|
32 |
+
"normalized": false,
|
33 |
+
"rstrip": false,
|
34 |
+
"single_word": false,
|
35 |
+
"special": true
|
36 |
+
},
|
37 |
+
"151647": {
|
38 |
+
"content": "<|object_ref_end|>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false,
|
43 |
+
"special": true
|
44 |
+
},
|
45 |
+
"151648": {
|
46 |
+
"content": "<|box_start|>",
|
47 |
+
"lstrip": false,
|
48 |
+
"normalized": false,
|
49 |
+
"rstrip": false,
|
50 |
+
"single_word": false,
|
51 |
+
"special": true
|
52 |
+
},
|
53 |
+
"151649": {
|
54 |
+
"content": "<|box_end|>",
|
55 |
+
"lstrip": false,
|
56 |
+
"normalized": false,
|
57 |
+
"rstrip": false,
|
58 |
+
"single_word": false,
|
59 |
+
"special": true
|
60 |
+
},
|
61 |
+
"151650": {
|
62 |
+
"content": "<|quad_start|>",
|
63 |
+
"lstrip": false,
|
64 |
+
"normalized": false,
|
65 |
+
"rstrip": false,
|
66 |
+
"single_word": false,
|
67 |
+
"special": true
|
68 |
+
},
|
69 |
+
"151651": {
|
70 |
+
"content": "<|quad_end|>",
|
71 |
+
"lstrip": false,
|
72 |
+
"normalized": false,
|
73 |
+
"rstrip": false,
|
74 |
+
"single_word": false,
|
75 |
+
"special": true
|
76 |
+
},
|
77 |
+
"151652": {
|
78 |
+
"content": "<|vision_start|>",
|
79 |
+
"lstrip": false,
|
80 |
+
"normalized": false,
|
81 |
+
"rstrip": false,
|
82 |
+
"single_word": false,
|
83 |
+
"special": true
|
84 |
+
},
|
85 |
+
"151653": {
|
86 |
+
"content": "<|vision_end|>",
|
87 |
+
"lstrip": false,
|
88 |
+
"normalized": false,
|
89 |
+
"rstrip": false,
|
90 |
+
"single_word": false,
|
91 |
+
"special": true
|
92 |
+
},
|
93 |
+
"151654": {
|
94 |
+
"content": "<|vision_pad|>",
|
95 |
+
"lstrip": false,
|
96 |
+
"normalized": false,
|
97 |
+
"rstrip": false,
|
98 |
+
"single_word": false,
|
99 |
+
"special": true
|
100 |
+
},
|
101 |
+
"151655": {
|
102 |
+
"content": "<|image_pad|>",
|
103 |
+
"lstrip": false,
|
104 |
+
"normalized": false,
|
105 |
+
"rstrip": false,
|
106 |
+
"single_word": false,
|
107 |
+
"special": true
|
108 |
+
},
|
109 |
+
"151656": {
|
110 |
+
"content": "<|video_pad|>",
|
111 |
+
"lstrip": false,
|
112 |
+
"normalized": false,
|
113 |
+
"rstrip": false,
|
114 |
+
"single_word": false,
|
115 |
+
"special": true
|
116 |
+
},
|
117 |
+
"151657": {
|
118 |
+
"content": "<tool_call>",
|
119 |
+
"lstrip": false,
|
120 |
+
"normalized": false,
|
121 |
+
"rstrip": false,
|
122 |
+
"single_word": false,
|
123 |
+
"special": false
|
124 |
+
},
|
125 |
+
"151658": {
|
126 |
+
"content": "</tool_call>",
|
127 |
+
"lstrip": false,
|
128 |
+
"normalized": false,
|
129 |
+
"rstrip": false,
|
130 |
+
"single_word": false,
|
131 |
+
"special": false
|
132 |
+
},
|
133 |
+
"151659": {
|
134 |
+
"content": "<|fim_prefix|>",
|
135 |
+
"lstrip": false,
|
136 |
+
"normalized": false,
|
137 |
+
"rstrip": false,
|
138 |
+
"single_word": false,
|
139 |
+
"special": false
|
140 |
+
},
|
141 |
+
"151660": {
|
142 |
+
"content": "<|fim_middle|>",
|
143 |
+
"lstrip": false,
|
144 |
+
"normalized": false,
|
145 |
+
"rstrip": false,
|
146 |
+
"single_word": false,
|
147 |
+
"special": false
|
148 |
+
},
|
149 |
+
"151661": {
|
150 |
+
"content": "<|fim_suffix|>",
|
151 |
+
"lstrip": false,
|
152 |
+
"normalized": false,
|
153 |
+
"rstrip": false,
|
154 |
+
"single_word": false,
|
155 |
+
"special": false
|
156 |
+
},
|
157 |
+
"151662": {
|
158 |
+
"content": "<|fim_pad|>",
|
159 |
+
"lstrip": false,
|
160 |
+
"normalized": false,
|
161 |
+
"rstrip": false,
|
162 |
+
"single_word": false,
|
163 |
+
"special": false
|
164 |
+
},
|
165 |
+
"151663": {
|
166 |
+
"content": "<|repo_name|>",
|
167 |
+
"lstrip": false,
|
168 |
+
"normalized": false,
|
169 |
+
"rstrip": false,
|
170 |
+
"single_word": false,
|
171 |
+
"special": false
|
172 |
+
},
|
173 |
+
"151664": {
|
174 |
+
"content": "<|file_sep|>",
|
175 |
+
"lstrip": false,
|
176 |
+
"normalized": false,
|
177 |
+
"rstrip": false,
|
178 |
+
"single_word": false,
|
179 |
+
"special": false
|
180 |
+
}
|
181 |
+
},
|
182 |
+
"additional_special_tokens": [
|
183 |
+
"<|im_start|>",
|
184 |
+
"<|im_end|>",
|
185 |
+
"<|object_ref_start|>",
|
186 |
+
"<|object_ref_end|>",
|
187 |
+
"<|box_start|>",
|
188 |
+
"<|box_end|>",
|
189 |
+
"<|quad_start|>",
|
190 |
+
"<|quad_end|>",
|
191 |
+
"<|vision_start|>",
|
192 |
+
"<|vision_end|>",
|
193 |
+
"<|vision_pad|>",
|
194 |
+
"<|image_pad|>",
|
195 |
+
"<|video_pad|>"
|
196 |
+
],
|
197 |
+
"bos_token": null,
|
198 |
+
"chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n",
|
199 |
+
"clean_up_tokenization_spaces": false,
|
200 |
+
"eos_token": "<|im_end|>",
|
201 |
+
"errors": "replace",
|
202 |
+
"model_max_length": 131072,
|
203 |
+
"pad_token": "<|endoftext|>",
|
204 |
+
"split_special_tokens": false,
|
205 |
+
"tokenizer_class": "Qwen2Tokenizer",
|
206 |
+
"unk_token": null
|
207 |
+
}
|
qwen2.5_tokenizer_uid.py
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, PreTrainedTokenizerFast
|
2 |
+
from http.server import HTTPServer, BaseHTTPRequestHandler
|
3 |
+
import json
|
4 |
+
import argparse
|
5 |
+
import uuid
|
6 |
+
|
7 |
+
# 全局字典:存储 uid 到 Tokenizer_Http 实例的映射
|
8 |
+
tokenizers = {}
|
9 |
+
|
10 |
+
class Tokenizer_Http():
|
11 |
+
def __init__(self):
|
12 |
+
model_id = "qwen2.5_tokenizer"
|
13 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_id)
|
14 |
+
self.messages = [
|
15 |
+
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
|
16 |
+
]
|
17 |
+
self.token_ids = []
|
18 |
+
|
19 |
+
def encode(self, prompt, last_reply=None):
|
20 |
+
if last_reply is not None:
|
21 |
+
self.messages.append({"role": "assistant", "content": last_reply})
|
22 |
+
text = self.tokenizer.apply_chat_template(
|
23 |
+
self.messages,
|
24 |
+
tokenize=False,
|
25 |
+
add_generation_prompt=True
|
26 |
+
)
|
27 |
+
# print("生成的文本:\n============\n", text, "============\n")
|
28 |
+
self.token_ids = self.tokenizer.encode(text)[:-3]
|
29 |
+
self.messages.append({"role": "user", "content": prompt})
|
30 |
+
|
31 |
+
text = self.tokenizer.apply_chat_template(
|
32 |
+
self.messages,
|
33 |
+
tokenize=False,
|
34 |
+
add_generation_prompt=True
|
35 |
+
)
|
36 |
+
print("生成的文本:\n============\n", text, "============\n")
|
37 |
+
token_ids = self.tokenizer.encode(text)
|
38 |
+
# 找出新增部分
|
39 |
+
diff = token_ids[len(self.token_ids):]
|
40 |
+
self.token_ids = token_ids
|
41 |
+
print(self.decode(diff))
|
42 |
+
return token_ids, diff
|
43 |
+
|
44 |
+
def decode(self, token_ids):
|
45 |
+
return self.tokenizer.decode(token_ids)
|
46 |
+
|
47 |
+
@property
|
48 |
+
def bos_id(self):
|
49 |
+
return self.tokenizer.bos_token_id
|
50 |
+
|
51 |
+
@property
|
52 |
+
def eos_id(self):
|
53 |
+
return self.tokenizer.eos_token_id
|
54 |
+
|
55 |
+
@property
|
56 |
+
def bos_token(self):
|
57 |
+
return self.tokenizer.bos_token
|
58 |
+
|
59 |
+
@property
|
60 |
+
def eos_token(self):
|
61 |
+
return self.tokenizer.eos_token
|
62 |
+
|
63 |
+
def reset(self, system_prompt="You are Qwen, created by Alibaba Cloud. You are a helpful assistant."):
|
64 |
+
self.messages = [
|
65 |
+
{"role": "system", "content": system_prompt},
|
66 |
+
]
|
67 |
+
text = self.tokenizer.apply_chat_template(
|
68 |
+
self.messages,
|
69 |
+
tokenize=False,
|
70 |
+
add_generation_prompt=True
|
71 |
+
)
|
72 |
+
token_ids = self.tokenizer.encode(text)[:-3]
|
73 |
+
self.token_ids = token_ids
|
74 |
+
print(self.decode(token_ids))
|
75 |
+
return token_ids
|
76 |
+
|
77 |
+
|
78 |
+
class Request(BaseHTTPRequestHandler):
|
79 |
+
timeout = 5
|
80 |
+
server_version = 'Apache'
|
81 |
+
|
82 |
+
def do_GET(self):
|
83 |
+
print("GET 请求路径:", self.path)
|
84 |
+
self.send_response(200)
|
85 |
+
self.send_header("Content-Type", "application/json")
|
86 |
+
self.end_headers()
|
87 |
+
|
88 |
+
# 新增接口:获取 uid
|
89 |
+
if '/get_uid' in self.path:
|
90 |
+
new_uid = str(uuid.uuid4())
|
91 |
+
print("新 uid:", new_uid)
|
92 |
+
# 为该 uid 创建一个新的 Tokenizer_Http 实例
|
93 |
+
tokenizers[new_uid] = Tokenizer_Http()
|
94 |
+
msg = json.dumps({'uid': new_uid})
|
95 |
+
elif '/bos_id' in self.path:
|
96 |
+
# 获取 uid 参数(例如 ?uid=xxx)
|
97 |
+
uid = self.get_query_param("uid")
|
98 |
+
instance: Tokenizer_Http = tokenizers.get(uid)
|
99 |
+
if instance is None:
|
100 |
+
msg = json.dumps({'error': 'Invalid uid'})
|
101 |
+
else:
|
102 |
+
bos_id = instance.bos_id
|
103 |
+
msg = json.dumps({'bos_id': bos_id if bos_id is not None else -1})
|
104 |
+
elif '/eos_id' in self.path:
|
105 |
+
uid = self.get_query_param("uid")
|
106 |
+
instance: Tokenizer_Http = tokenizers.get(uid)
|
107 |
+
if instance is None:
|
108 |
+
msg = json.dumps({'error': 'Invalid uid'})
|
109 |
+
else:
|
110 |
+
eos_id = instance.eos_id
|
111 |
+
msg = json.dumps({'eos_id': eos_id if eos_id is not None else -1})
|
112 |
+
else:
|
113 |
+
msg = json.dumps({'error': 'Invalid GET endpoint'})
|
114 |
+
|
115 |
+
print("响应消息:", msg)
|
116 |
+
self.wfile.write(msg.encode())
|
117 |
+
|
118 |
+
def do_POST(self):
|
119 |
+
content_length = int(self.headers.get('content-length', 0))
|
120 |
+
data = self.rfile.read(content_length).decode()
|
121 |
+
print("POST 请求路径:", self.path)
|
122 |
+
print("接收到的数据:", data)
|
123 |
+
req = json.loads(data)
|
124 |
+
|
125 |
+
self.send_response(200)
|
126 |
+
self.send_header("Content-Type", "application/json")
|
127 |
+
self.end_headers()
|
128 |
+
|
129 |
+
if '/encode' in self.path:
|
130 |
+
# 请求数据中必须包含 uid, text, 和可选的 last_reply
|
131 |
+
uid = req.get('uid')
|
132 |
+
prompt = req.get('text')
|
133 |
+
last_reply = req.get('last_reply')
|
134 |
+
instance: Tokenizer_Http = tokenizers.get(uid)
|
135 |
+
if instance is None:
|
136 |
+
msg = json.dumps({'error': 'Invalid uid'})
|
137 |
+
else:
|
138 |
+
token_ids, diff = instance.encode(prompt, last_reply)
|
139 |
+
msg = json.dumps({'token_ids': token_ids, 'diff': diff})
|
140 |
+
elif '/decode' in self.path:
|
141 |
+
uid = req.get('uid')
|
142 |
+
token_ids = req.get('token_ids')
|
143 |
+
instance: Tokenizer_Http = tokenizers.get(uid)
|
144 |
+
if instance is None:
|
145 |
+
msg = json.dumps({'error': 'Invalid uid'})
|
146 |
+
else:
|
147 |
+
text = instance.decode(token_ids)
|
148 |
+
msg = json.dumps({'text': text})
|
149 |
+
elif '/reset' in self.path:
|
150 |
+
uid = req.get("uid")
|
151 |
+
system_prompt = req.get("system_prompt")
|
152 |
+
instance: Tokenizer_Http = tokenizers.get(uid)
|
153 |
+
if instance is None:
|
154 |
+
msg = json.dumps({'error': 'Invalid uid'})
|
155 |
+
else:
|
156 |
+
if system_prompt is not None:
|
157 |
+
print("system_prompt:", system_prompt)
|
158 |
+
token_ids = instance.reset(system_prompt)
|
159 |
+
msg = json.dumps({'token_ids': token_ids})
|
160 |
+
else:
|
161 |
+
token_ids = instance.reset()
|
162 |
+
msg = json.dumps({'token_ids': token_ids})
|
163 |
+
else:
|
164 |
+
msg = json.dumps({'error': 'Invalid POST endpoint'})
|
165 |
+
|
166 |
+
print("响应消息:", msg)
|
167 |
+
self.wfile.write(msg.encode())
|
168 |
+
|
169 |
+
def get_query_param(self, key):
|
170 |
+
"""
|
171 |
+
辅助函数:从 GET 请求的 URL 中获取查询参数的值
|
172 |
+
例如:/bos_id?uid=xxx
|
173 |
+
"""
|
174 |
+
from urllib.parse import urlparse, parse_qs
|
175 |
+
query = urlparse(self.path).query
|
176 |
+
params = parse_qs(query)
|
177 |
+
values = params.get(key)
|
178 |
+
return values[0] if values else None
|
179 |
+
|
180 |
+
if __name__ == "__main__":
|
181 |
+
parser = argparse.ArgumentParser()
|
182 |
+
parser.add_argument('--host', type=str, default='0.0.0.0')
|
183 |
+
parser.add_argument('--port', type=int, default=12345)
|
184 |
+
args = parser.parse_args()
|
185 |
+
|
186 |
+
host = (args.host, args.port)
|
187 |
+
print('Server running at http://%s:%s' % host)
|
188 |
+
server = HTTPServer(host, Request)
|
189 |
+
server.serve_forever()
|
run_qwen2.5_7b_ctx_ax650.sh
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
./main_ax650 \
|
2 |
+
--template_filename_axmodel "qwen2.5-7b-ctx-ax650/qwen2_p128_l%d_together.axmodel" \
|
3 |
+
--axmodel_num 28 \
|
4 |
+
--tokenizer_type 2 \
|
5 |
+
--url_tokenizer_model "http://0.0.0.0:12345" \
|
6 |
+
--filename_post_axmodel "qwen2.5-7b-ctx-ax650/qwen2_post.axmodel" \
|
7 |
+
--filename_tokens_embed "qwen2.5-7b-ctx-ax650/model.embed_tokens.weight.bfloat16.bin" \
|
8 |
+
--tokens_embed_num 152064 \
|
9 |
+
--tokens_embed_size 3584 \
|
10 |
+
--use_mmap_load_embed 1 \
|
11 |
+
--live_print 1
|
12 |
+
|
13 |
+
|
14 |
+
#--system_prompt "你的名字叫小智(allen),你是一个人畜无害的AI助手。深圳市今天(4月1日)阴天,愚人节,气温在14°C至19°C之间,微风。" \
|
15 |
+
#--kvcache_path "./kvcache" \
|
16 |
+
|
run_qwen2.5_7b_ctx_int4_ax650.sh
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
./main_ax650 \
|
2 |
+
--template_filename_axmodel "qwen2.5-7b-ctx-int4-ax650/qwen2_p128_l%d_together.axmodel" \
|
3 |
+
--axmodel_num 28 \
|
4 |
+
--tokenizer_type 2 \
|
5 |
+
--url_tokenizer_model "http://0.0.0.0:12345" \
|
6 |
+
--filename_post_axmodel "qwen2.5-7b-ctx-int4-ax650/qwen2_post.axmodel" \
|
7 |
+
--filename_tokens_embed "qwen2.5-7b-ctx-ax650/model.embed_tokens.weight.bfloat16.bin" \
|
8 |
+
--tokens_embed_num 152064 \
|
9 |
+
--tokens_embed_size 3584 \
|
10 |
+
--use_mmap_load_embed 1 \
|
11 |
+
--live_print 1
|
12 |
+
|
13 |
+
|
14 |
+
#--system_prompt "你的名字叫小智(allen),你是一个人畜无害的AI助手。深圳市今天(4月1日)阴天,愚人节,气温在14°C至19°C之间,微风。" \
|
15 |
+
#--kvcache_path "./kvcache" \
|
16 |
+
|