qqc1989 commited on
Commit
8c48ab0
·
verified ·
1 Parent(s): dec033e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +203 -3
README.md CHANGED
@@ -1,3 +1,203 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - zh
5
+ - en
6
+ base_model:
7
+ - Qwen/Qwen2.5-7B-Instruct-GPTQ-INT8
8
+ - Qwen/Qwen2.5-7B-Instruct-GPTQ-INT4
9
+ pipeline_tag: text-generation
10
+ library_name: transformers
11
+ tags:
12
+ - Context
13
+ - Qwen2.5-7B-Instruct-GPTQ-INT8
14
+ - Qwen2.5-7B-Instruct-GPTQ-INT4
15
+ ---
16
+
17
+ # Qwen2.5-7B-Instruct
18
+
19
+ This version of Qwen2.5-7B-Instruct has been converted to run on the Axera NPU using **w8a16** and **w4a16** quantization.
20
+
21
+ This model has been optimized with the following LoRA:
22
+
23
+ Compatible with Pulsar2 version: 4.1
24
+
25
+ ## Feature
26
+
27
+ - Support for longer contexts, in this sample it's 2k
28
+ - Support context dialogue
29
+ - System prompt kvcache is supported
30
+
31
+ ## Convert tools links:
32
+
33
+ For those who are interested in model conversion, you can try to export axmodel through:
34
+
35
+ [Pulsar2 Link, How to Convert LLM from Huggingface to axmodel](https://pulsar2-docs.readthedocs.io/en/latest/appendix/build_llm.html)
36
+
37
+ [AXera NPU AXEngine LLM Runtime](https://github.com/AXERA-TECH/ax-llm/tree/ax-context)
38
+
39
+ [AXera NPU AXCL LLM Runtime](https://github.com/AXERA-TECH/ax-llm/tree/axcl-context)
40
+
41
+ ### Convert script
42
+
43
+ The follow show how to convert Qwen2.5-7B-Instruct-GPTQ-Int4
44
+
45
+ ```
46
+ pulsar2 llm_build --input_path Qwen/Qwen2.5-7B-Instruct-GPTQ-Int4 \
47
+ --output_path Qwen/Qwen2.5-7B-Instruct-GPTQ-Int4-ctx-ax650 \
48
+ --hidden_state_type bf16 --kv_cache_len 2047 --prefill_len 128 \
49
+ --last_kv_cache_len 128 \
50
+ --last_kv_cache_len 256 \
51
+ --last_kv_cache_len 384 \
52
+ --last_kv_cache_len 512 \
53
+ --last_kv_cache_len 640 \
54
+ --last_kv_cache_len 768 \
55
+ --last_kv_cache_len 896 \
56
+ --last_kv_cache_len 1024 \
57
+ --chip AX650 -c 1 --parallel 8
58
+ ```
59
+
60
+ ## Support Platform
61
+
62
+ - AX650
63
+ - AX650N DEMO Board
64
+ - [M4N-Dock(爱芯派Pro)](https://wiki.sipeed.com/hardware/zh/maixIV/m4ndock/m4ndock.html)
65
+ - [M4N-HAT](https://wiki.sipeed.com/hardware/zh/maixIV/m4nhat/intro.html)
66
+ - [M.2 Accelerator card](https://axcl-docs.readthedocs.io/zh-cn/latest/doc_guide_hardware.html)
67
+
68
+
69
+ |Chips|w8a16|w4a16| DDR(w8) | Flash(w8) | DDR(w4) | Flash(w4) |
70
+ |--|--|--|--|--|--|--|
71
+ |AX650| 2.8 tokens/sec| 5.0 tokens/sec | | | 5.2GB | 5.7GB |
72
+
73
+ ## How to use
74
+
75
+ Download all files from this repository to the device
76
+
77
+ ```
78
+ (base) axera@raspberrypi:~/samples/AXERA-TECH/Qwen2.5-7B-Instruct $ tree -L 1
79
+ .
80
+ ├── config.json
81
+ ├── main_api
82
+ ├── main_api_ax650
83
+ ├── main_api_axcl_aarch64
84
+ ├── main_api_axcl_x86
85
+ ├── main_ax650
86
+ ├── main_axcl_aarch64
87
+ ├── main_axcl_x86
88
+ ├── post_config.json
89
+ ├── qwen2.5-7b-ctx-int4-ax650
90
+ ├── qwen2.5_tokenizer
91
+ ├── qwen2.5_tokenizer_uid.py
92
+ ├── README.md
93
+ ├── run_qwen2.5_7b_ctx_ax650.sh
94
+ ├── run_qwen2.5_7b_ctx_int4_ax650.sh
95
+ ├── run_qwen2.5_7b_ctx_int4_axcl_aarch64.sh
96
+ └── run_qwen2.5_7b_ctx_int4_axcl_x86.sh
97
+
98
+ 3 directories, 15 files
99
+ ```
100
+
101
+ #### Start the Tokenizer service
102
+
103
+ ```
104
+ (axcl) axera@raspberrypi:~/samples/AXERA-TECH/Qwen2.5-7B-Instruct $ python qwen2.5_tokenizer_uid.py
105
+ None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
106
+ Server running at http://0.0.0.0:12345
107
+ ```
108
+
109
+ #### System prompt cache
110
+
111
+ - The System prompt can be preset through the configuration file from `--system_prompt`
112
+ - The System prompt can be cached in the form of kv cache to a specified folder for quick loading at the next run time from `--kvcache_path`
113
+ - This folder needs to be created manually before running, for example `mkdir kvcache`
114
+
115
+ ```
116
+ (base) axera@raspberrypi:~/samples/AXERA-TECH/Qwen2.5-7B-Instruct $ cat run_qwen2.5_7b_ctx_int4_axcl_aarch64.sh
117
+ ./main_axcl_aarch64 \
118
+ --template_filename_axmodel "qwen2.5-7b-ctx-int4-ax650/qwen2_p128_l%d_together.axmodel" \
119
+ --axmodel_num 28 \
120
+ --url_tokenizer_model "http://0.0.0.0:12345" \
121
+ --filename_post_axmodel "qwen2.5-7b-ctx-int4-ax650/qwen2_post.axmodel" \
122
+ --filename_tokens_embed "qwen2.5-7b-ctx-int4-ax650/model.embed_tokens.weight.bfloat16.bin" \
123
+ --tokens_embed_num 152064 \
124
+ --tokens_embed_size 3584 \
125
+ --use_mmap_load_embed 1 \
126
+ --live_print 1 \
127
+ --devices 0
128
+
129
+
130
+ #--system_prompt "你的名字叫小智(allen),你是一个人畜无害的AI助手。深圳市今天(4月1日)阴天,愚人节,气温在14°C至19°C之间,微风。" \
131
+ #--kvcache_path "./kvcache" \
132
+ ```
133
+
134
+ #### Inference with AX650 Host, such as M4N-Dock(爱芯派Pro) or AX650N DEMO Board
135
+
136
+ TODO
137
+
138
+ #### Inference with M.2 Accelerator card
139
+
140
+ [What is M.2 Accelerator card?](https://axcl-docs.readthedocs.io/zh-cn/latest/doc_guide_hardware.html), Show this DEMO based on Raspberry PI 5.
141
+
142
+ ```
143
+ (base) axera@raspberrypi:~/samples/AXERA-TECH/Qwen2.5-7B-Instruct $ ./run_qwen2.5_7b_ctx_int4_axcl_aarch64.sh
144
+ [I][ Init][ 130]: LLM init start
145
+ [I][ Init][ 34]: connect http://0.0.0.0:12345 ok
146
+ [I][ Init][ 57]: uid: ae9adea5-c64e-47df-92ca-29cbcc5a865f
147
+ bos_id: -1, eos_id: 151645
148
+ 3% | ██ | 1 / 31 [0.49s<15.16s, 2.04 count/s] tokenizer init ok[I][ Init][ 45]: LLaMaEmbedSelector use mmap
149
+ 6% | ███ | 2 / 31 [0.49s<7.59s, 4.08 count/s] embed_selector init ok
150
+ [I][ run][ 30]: AXCLWorker start with devid 0
151
+ 54% | ████████████████████████████ █ █ █ ██ ██ | 17 / 31 [39.92s<77.35s, 0.40 count/s] init 24 axmodel ok,devid(0) remain_cmm(-1 MB) | 16 / 31 [39.92s<77.35s,100% | ████████████████████████████████ | 31 / 31 [80.60s<83.29s, 0.37 count/s] init post axmodel ok,remain_cmm(1324 MB)1891 MB)
152
+ [I][ Init][ 221]: max_token_len : 2047
153
+ [I][ Init][ 224]: kv_cache_size : 512, kv_cache_num: 2047
154
+ [I][ Init][ 232]: prefill_token_num : 128
155
+ [I][ Init][ 236]: grp: 1, prefill_max_token_num : 1
156
+ [I][ Init][ 236]: grp: 2, prefill_max_token_num : 128
157
+ [I][ Init][ 236]: grp: 3, prefill_max_token_num : 256
158
+ [I][ Init][ 236]: grp: 4, prefill_max_token_num : 384
159
+ [I][ Init][ 236]: grp: 5, prefill_max_token_num : 512
160
+ [I][ Init][ 236]: grp: 6, prefill_max_token_num : 640
161
+ [I][ Init][ 236]: grp: 7, prefill_max_token_num : 768
162
+ [I][ Init][ 236]: grp: 8, prefill_max_token_num : 896
163
+ [I][ Init][ 236]: grp: 9, prefill_max_token_num : 1024
164
+ [I][ Init][ 240]: prefill_max_token_num : 1024
165
+ ________________________
166
+ | ID| remain cmm(MB)|
167
+ ========================
168
+ | 0| 1324|
169
+ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
170
+ [I][ load_config][ 282]: load config:
171
+ {
172
+ "enable_repetition_penalty": false,
173
+ "enable_temperature": true,
174
+ "enable_top_k_sampling": true,
175
+ "enable_top_p_sampling": false,
176
+ "penalty_window": 20,
177
+ "repetition_penalty": 1.2,
178
+ "temperature": 0.9,
179
+ "top_k": 10,
180
+ "top_p": 0.8
181
+ }
182
+
183
+ [I][ Init][ 263]: LLM init ok
184
+ Type "q" to exit, Ctrl+c to stop current running
185
+ [I][ GenerateKVCachePrefill][ 324]: input token num : 21, prefill_split_num : 1 prefill_grpid : 2
186
+ [I][ GenerateKVCachePrefill][ 367]: input_num_token:21
187
+ [I][ main][ 234]: precompute_len: 21
188
+ [I][ main][ 235]: system_prompt: You are Qwen, created by Alibaba Cloud. You are a helpful assistant.
189
+ prompt >> nice
190
+ [I][ SetKVCache][ 614]: prefill_grpid:2 kv_cache_num:128 precompute_len:21 input_num_token:9
191
+ [I][ SetKVCache][ 617]: current prefill_max_token_num:896
192
+ [I][ Run][ 855]: input token num : 9, prefill_split_num : 1
193
+ [I][ Run][ 887]: input_num_token:9
194
+ [I][ Run][1016]: ttft: 928.08 ms
195
+ Nice to meet you! If you have any questions or need some help, feel free to ask.
196
+
197
+ [N][ Run][1168]: hit eos,avg 4.36 token/s
198
+
199
+ [I][ GetKVCache][ 583]: precompute_len:50, remaining:974
200
+ prompt >> q
201
+ [I][ run][ 80]: AXCLWorker exit with devid 0
202
+ (base) axera@raspberrypi:~/samples/AXERA-TECH/Qwen2.5-7B-Instruct $
203
+ ```