wangli commited on
update project
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +32 -0
- README.md +171 -133
- config.json +27 -0
- fastvlm_ax650_context_1k_prefill_640_int4/model.embed_tokens.weight.npy +0 -3
- fastvlm_tokenizer/added_tokens.json +0 -6
- fastvlm_tokenizer/config.json +0 -79
- fastvlm_tokenizer/generation_config.json +0 -6
- fastvlm_tokenizer/merges.txt +0 -0
- fastvlm_tokenizer/special_tokens_map.json +0 -20
- fastvlm_tokenizer/tokenizer.json +0 -3
- fastvlm_tokenizer/tokenizer_config.json +0 -52
- fastvlm_tokenizer/trainer_state.json +0 -0
- fastvlm_tokenizer/vocab.json +0 -0
- images/image_1.jpg → image.png +2 -2
- fastvlm_ax650_context_1k_prefill_640_int4/image_encoder_1024x1024.axmodel → image_encoder_1024x1024.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/image_encoder_512x512.axmodel → image_encoder_512x512.axmodel +0 -0
- infer_axmodel.py +0 -130
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l0_together.axmodel → llava_qwen2_p128_l0_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l10_together.axmodel → llava_qwen2_p128_l10_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l11_together.axmodel → llava_qwen2_p128_l11_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l12_together.axmodel → llava_qwen2_p128_l12_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l13_together.axmodel → llava_qwen2_p128_l13_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l14_together.axmodel → llava_qwen2_p128_l14_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l15_together.axmodel → llava_qwen2_p128_l15_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l16_together.axmodel → llava_qwen2_p128_l16_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l17_together.axmodel → llava_qwen2_p128_l17_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l18_together.axmodel → llava_qwen2_p128_l18_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l19_together.axmodel → llava_qwen2_p128_l19_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l1_together.axmodel → llava_qwen2_p128_l1_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l20_together.axmodel → llava_qwen2_p128_l20_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l21_together.axmodel → llava_qwen2_p128_l21_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l22_together.axmodel → llava_qwen2_p128_l22_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l23_together.axmodel → llava_qwen2_p128_l23_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l24_together.axmodel → llava_qwen2_p128_l24_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l25_together.axmodel → llava_qwen2_p128_l25_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l26_together.axmodel → llava_qwen2_p128_l26_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l27_together.axmodel → llava_qwen2_p128_l27_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l2_together.axmodel → llava_qwen2_p128_l2_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l3_together.axmodel → llava_qwen2_p128_l3_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l4_together.axmodel → llava_qwen2_p128_l4_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l5_together.axmodel → llava_qwen2_p128_l5_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l6_together.axmodel → llava_qwen2_p128_l6_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l7_together.axmodel → llava_qwen2_p128_l7_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l8_together.axmodel → llava_qwen2_p128_l8_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l9_together.axmodel → llava_qwen2_p128_l9_together.axmodel +0 -0
- fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_post.axmodel → llava_qwen2_post.axmodel +0 -0
- main_axcl_x86 +0 -3
- main_axcl_x86_api +0 -3
- fastvlm_ax650_context_1k_prefill_640_int4/model.embed_tokens.weight.bfloat16.bin → model.embed_tokens.weight.bfloat16.bin +0 -0
- post_config.json +5 -5
.gitattributes
CHANGED
|
@@ -71,3 +71,35 @@ main_ax650 filter=lfs diff=lfs merge=lfs -text
|
|
| 71 |
main_ax650_api filter=lfs diff=lfs merge=lfs -text
|
| 72 |
main_axcl_x86 filter=lfs diff=lfs merge=lfs -text
|
| 73 |
main_axcl_x86_api filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
main_ax650_api filter=lfs diff=lfs merge=lfs -text
|
| 72 |
main_axcl_x86 filter=lfs diff=lfs merge=lfs -text
|
| 73 |
main_axcl_x86_api filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
image.png filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
image_encoder_1024x1024.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 76 |
+
image_encoder_512x512.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
llava_qwen2_p128_l0_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 78 |
+
llava_qwen2_p128_l10_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
llava_qwen2_p128_l11_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
llava_qwen2_p128_l12_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
llava_qwen2_p128_l13_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
llava_qwen2_p128_l14_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
llava_qwen2_p128_l15_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
llava_qwen2_p128_l16_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
llava_qwen2_p128_l17_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
llava_qwen2_p128_l18_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
llava_qwen2_p128_l19_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
llava_qwen2_p128_l1_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
llava_qwen2_p128_l20_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 90 |
+
llava_qwen2_p128_l21_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 91 |
+
llava_qwen2_p128_l22_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 92 |
+
llava_qwen2_p128_l23_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 93 |
+
llava_qwen2_p128_l24_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 94 |
+
llava_qwen2_p128_l25_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 95 |
+
llava_qwen2_p128_l26_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 96 |
+
llava_qwen2_p128_l27_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 97 |
+
llava_qwen2_p128_l2_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 98 |
+
llava_qwen2_p128_l3_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 99 |
+
llava_qwen2_p128_l4_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 100 |
+
llava_qwen2_p128_l5_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 101 |
+
llava_qwen2_p128_l6_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 102 |
+
llava_qwen2_p128_l7_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 103 |
+
llava_qwen2_p128_l8_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 104 |
+
llava_qwen2_p128_l9_together.axmodel filter=lfs diff=lfs merge=lfs -text
|
| 105 |
+
llava_qwen2_post.axmodel filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -40,160 +40,198 @@ How to Convert LLM from Huggingface to axmodel[TODO]
|
|
| 40 |
|AXCL x86| 233.93 ms (1024x1024)| 779.51 ms (286tokens)| 12.47 tokens/sec|1.4|
|
| 41 |
|AX650| 58.33 ms (512x512)| 128.92 ms (100tokens)| 19.87 tokens/sec|1.4|
|
| 42 |
|
| 43 |
-
|
| 44 |
## How to use
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
```
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|-- fastvlm_ax650_context_1k_prefill_640_int4
|
| 55 |
-
|-- fastvlm_tokenizer
|
| 56 |
-
|-- images
|
| 57 |
-
|-- infer_axmodel.py
|
| 58 |
-
|-- main_ax650
|
| 59 |
-
|-- main_ax650_api
|
| 60 |
-
|-- main_axcl_x86
|
| 61 |
-
|-- main_axcl_x86_api
|
| 62 |
-
|-- post_config.json
|
| 63 |
-
|-- requirements.txt
|
| 64 |
-
|-- run_ax650_1024.sh
|
| 65 |
-
|-- run_ax650_512.sh
|
| 66 |
-
|-- run_ax650_api.sh
|
| 67 |
-
|-- run_axcl_x86.sh
|
| 68 |
-
|-- run_axcl_x86_api.sh
|
| 69 |
-
`-- utils
|
| 70 |
-
|
| 71 |
-
4 directories, 15 files
|
| 72 |
```
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
|
|
|
|
|
|
|
|
|
| 76 |
```
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
```
|
| 79 |
|
| 80 |
-
##
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
```
|
| 85 |
-
root@ax650:~
|
| 86 |
-
[I][ Init][
|
| 87 |
-
tokenizer_type =
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
[I][ Init][
|
| 94 |
-
[I][ Init][
|
| 95 |
-
|
| 96 |
-
[I][ Init][
|
| 97 |
-
[I][ Init][
|
| 98 |
-
[I][ Init][
|
| 99 |
-
[
|
| 100 |
-
[I][ Init][ 335]: grp: 1, prefill_max_token_num : 1
|
| 101 |
-
[I][ Init][ 335]: grp: 2, prefill_max_token_num : 128
|
| 102 |
-
[I][ Init][ 335]: grp: 3, prefill_max_token_num : 256
|
| 103 |
-
[I][ Init][ 335]: grp: 4, prefill_max_token_num : 512
|
| 104 |
-
[I][ Init][ 335]: grp: 5, prefill_max_token_num : 640
|
| 105 |
-
[I][ Init][ 339]: prefill_max_token_num : 640
|
| 106 |
[I][ load_config][ 282]: load config:
|
| 107 |
{
|
| 108 |
"enable_repetition_penalty": false,
|
| 109 |
-
"enable_temperature":
|
| 110 |
-
"enable_top_k_sampling":
|
| 111 |
"enable_top_p_sampling": false,
|
| 112 |
-
"penalty_window":
|
| 113 |
-
"repetition_penalty": 2,
|
| 114 |
-
"temperature": 0.
|
| 115 |
"top_k": 10,
|
| 116 |
"top_p": 0.8
|
| 117 |
}
|
| 118 |
|
| 119 |
-
[I][ Init][
|
| 120 |
-
Type "q" to exit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
prompt >> who are you
|
| 122 |
-
|
| 123 |
-
[I][
|
| 124 |
-
[I][
|
| 125 |
-
[I][ Run][
|
| 126 |
-
[I][ Run][
|
| 127 |
-
|
| 128 |
-
I
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
prompt >> describe the image
|
| 133 |
-
image >> ./images/ssd_horse.jpg
|
| 134 |
-
[I][ Encode][ 442]: image encode time : 237.49 ms, size : 393216
|
| 135 |
-
[I][ Encode][ 496]: imgs_embed.size() : 1, media token size : 256
|
| 136 |
-
[I][ Run][ 604]: input token num : 291, prefill_split_num : 3
|
| 137 |
-
[I][ Run][ 619]: prefill grpid 4
|
| 138 |
-
[I][ Run][ 646]: input_num_token:128
|
| 139 |
-
[I][ Run][ 646]: input_num_token:128
|
| 140 |
-
[I][ Run][ 646]: input_num_token:35
|
| 141 |
-
[I][ Run][ 770]: ttft: 418.43 ms
|
| 142 |
-
The image depicts a scene in an outdoor setting, likely a farm or ranch, with a person riding a brown horse. The person is wearing a blue hoodie and jeans, and is seated on a saddle with a yellow blanket underneath. The horse has a white blaze on its face and is standing on a dirt ground. In front of the horse, there is a brown dog wearing a pink collar, looking up at the person on the horse. In the background, there is a silver pickup truck parked near a fence, and beyond the fence, there are trees and other people. The overall atmosphere of the image suggests a casual, outdoor activity, possibly involving horse riding and training.
|
| 143 |
-
|
| 144 |
-
[N][ Run][ 879]: hit eos,avg 19.85 token/s
|
| 145 |
|
|
|
|
|
|
|
|
|
|
| 146 |
prompt >> q
|
| 147 |
```
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
```
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
[
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
slice_indices: [0]
|
| 184 |
-
Slice prefill done: 0
|
| 185 |
-
answer >> I am an artificial intelligence language model developed by Apple Inc.
|
| 186 |
-
|
| 187 |
-
prompt<<./images/ssd_horse.jpg
|
| 188 |
-
slice_indices: [0]
|
| 189 |
-
Slice prefill done: 0
|
| 190 |
-
answer >> The image depicts a young man riding a brown horse in an outdoor setting. The horse is standing on a dirt ground, and the rider is wearing a blue jacket and jeans. The horse has a white blaze on its face and white markings on its legs. The rider is holding the reins and appears to be looking down at a brown dog standing on the ground next to the horse. The dog is wearing a collar and is looking up at the rider. In the background, there is a silver pickup truck parked on the grass, and a fence can be seen further back. The scene appears to be set in a rural or farm-like environment.
|
| 191 |
-
|
| 192 |
-
prompt<<./images/image_1.jpg
|
| 193 |
-
slice_indices: [0]
|
| 194 |
-
Slice prefill done: 0
|
| 195 |
-
answer >> The image depicts a panda bear in a natural setting. The panda is sitting on the ground, surrounded by greenery, including bamboo and other plants. The panda has a distinctive black and white fur pattern, with black fur around its eyes, ears, and limbs, and white fur on its face, chest, and legs. The panda is sitting on its hind legs, with its front paws resting on its chest. The background shows a forested area with trees and rocks, suggesting that the panda is in its natural habitat. The panda appears to be looking directly at the camera, giving the impression that it is aware of the photographer's presence. The overall scene is peaceful and serene, capturing the beauty of the panda in its natural environment.
|
| 196 |
-
|
| 197 |
-
prompt<<q
|
| 198 |
-
[INFO]: 对话结束,再见。
|
| 199 |
-
```
|
|
|
|
| 40 |
|AXCL x86| 233.93 ms (1024x1024)| 779.51 ms (286tokens)| 12.47 tokens/sec|1.4|
|
| 41 |
|AX650| 58.33 ms (512x512)| 128.92 ms (100tokens)| 19.87 tokens/sec|1.4|
|
| 42 |
|
|
|
|
| 43 |
## How to use
|
| 44 |
|
| 45 |
+
## 安装 axllm
|
| 46 |
+
方式一:克隆仓库后执行安装脚本:
|
| 47 |
|
| 48 |
+
```shell
|
| 49 |
+
git clone -b axllm https://github.com/AXERA-TECH/ax-llm.git
|
| 50 |
+
cd ax-llm
|
| 51 |
+
./install.sh
|
| 52 |
```
|
| 53 |
+
|
| 54 |
+
方式二:一行命令安装(默认分支 `axllm`):
|
| 55 |
+
|
| 56 |
+
```shell
|
| 57 |
+
curl -fsSL https://raw.githubusercontent.com/AXERA-TECH/ax-llm/axllm/install.sh | bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
```
|
| 59 |
|
| 60 |
+
方式三:下载Github Actions CI 导出的可执行程序(适合没有编译环境的用户):
|
| 61 |
+
|
| 62 |
+
如果没有编译环境,请到:
|
| 63 |
+
`https://github.com/AXERA-TECH/ax-llm/actions?query=branch%3Aaxllm`
|
| 64 |
+
下载 **最新 CI 导出的可执行程序**(`axllm`),然后:
|
| 65 |
|
| 66 |
+
```shell
|
| 67 |
+
chmod +x axllm
|
| 68 |
+
sudo mv axllm /usr/bin/axllm
|
| 69 |
```
|
| 70 |
+
|
| 71 |
+
## 模型下载(Hugging Face)
|
| 72 |
+
先创建模型目录并进入,然后下载到该目录:
|
| 73 |
+
|
| 74 |
+
```shell
|
| 75 |
+
mkdir -p AXERA-TECH/FastVLM-1.5B-GPTQ-Int4
|
| 76 |
+
cd AXERA-TECH/FastVLM-1.5B-GPTQ-Int4
|
| 77 |
+
hf download AXERA-TECH/FastVLM-1.5B-GPTQ-Int4 --local-dir .
|
| 78 |
+
|
| 79 |
+
# structure of the downloaded files
|
| 80 |
+
tree -L 3
|
| 81 |
+
.
|
| 82 |
+
└── AXERA-TECH
|
| 83 |
+
└── FastVLM-1.5B-GPTQ-Int4
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
2 directories, 34 files
|
| 88 |
```
|
| 89 |
|
| 90 |
+
## Inference with AX650 Host, such as M4N-Dock(爱芯派Pro) or AX650N DEMO Board
|
| 91 |
+
|
| 92 |
+
### 运行(CLI)
|
| 93 |
+
|
| 94 |
+
```shell
|
| 95 |
+
(base) root@ax650:~# axllm run AXERA-TECH/Qwen3-0.6B/
|
| 96 |
+
[I][ Init][ 127]: LLM init start
|
| 97 |
+
tokenizer_type = 1
|
| 98 |
+
96% | ███████████████████████████████ | 30 / 31 [2.35s<2.42s, 12.79 count/s] init post axmodel ok,remain_cmm(8662 MB)
|
| 99 |
+
[I][ Init][ 188]: max_token_len : 2559
|
| 100 |
+
[I][ Init][ 191]: kv_cache_size : 1024, kv_cache_num: 2559
|
| 101 |
+
[I][ Init][ 194]: prefill_token_num : 128
|
| 102 |
+
[I][ Init][ 198]: grp: 1, prefill_max_kv_cache_num : 1
|
| 103 |
+
[I][ Init][ 198]: grp: 2, prefill_max_kv_cache_num : 512
|
| 104 |
+
[I][ Init][ 198]: grp: 3, prefill_max_kv_cache_num : 1024
|
| 105 |
+
[I][ Init][ 198]: grp: 4, prefill_max_kv_cache_num : 1536
|
| 106 |
+
[I][ Init][ 198]: grp: 5, prefill_max_kv_cache_num : 2048
|
| 107 |
+
[I][ Init][ 203]: prefill_max_token_num : 2048
|
| 108 |
+
[I][ Init][ 27]: LLaMaEmbedSelector use mmap
|
| 109 |
+
100% | ████████████████████████████████ | 31 / 31 [2.35s<2.35s, 13.21 count/s] embed_selector init ok
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
[I][ load_config][ 282]: load config:
|
| 111 |
{
|
| 112 |
"enable_repetition_penalty": false,
|
| 113 |
+
"enable_temperature": false,
|
| 114 |
+
"enable_top_k_sampling": false,
|
| 115 |
"enable_top_p_sampling": false,
|
| 116 |
+
"penalty_window": 20,
|
| 117 |
+
"repetition_penalty": 1.2,
|
| 118 |
+
"temperature": 0.9,
|
| 119 |
"top_k": 10,
|
| 120 |
"top_p": 0.8
|
| 121 |
}
|
| 122 |
|
| 123 |
+
[I][ Init][ 224]: LLM init ok
|
| 124 |
+
Type "q" to exit
|
| 125 |
+
Ctrl+c to stop current running
|
| 126 |
+
"reset" to reset kvcache
|
| 127 |
+
"dd" to remove last conversation.
|
| 128 |
+
"pp" to print history.
|
| 129 |
+
----------------------------------------
|
| 130 |
prompt >> who are you
|
| 131 |
+
[I][ SetKVCache][ 357]: prefill_grpid:2 kv_cache_num:512 precompute_len:0 input_num_token:22
|
| 132 |
+
[I][ SetKVCache][ 359]: current prefill_max_token_num:2048
|
| 133 |
+
[I][ SetKVCache][ 360]: first run
|
| 134 |
+
[I][ Run][ 412]: input token num : 22, prefill_split_num : 1
|
| 135 |
+
[I][ Run][ 474]: ttft: 586.40 ms
|
| 136 |
+
<think>
|
| 137 |
+
Okay, the user asked, "Who are you?" I need to respond appropriately. Since I'm an AI assistant, I should acknowledge their question and explain my purpose. I should mention that I'm here to help and that I can assist with various tasks. I should keep the response friendly and open-ended to encourage further interaction. Let me make sure the language is clear and natural.
|
| 138 |
+
</think>
|
| 139 |
+
|
| 140 |
+
I'm an AI assistant designed to help you with a wide range of questions and tasks. How can I assist you today? 😊
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
+
[N][ Run][ 554]: hit eos,avg 15.63 token/s
|
| 143 |
+
|
| 144 |
+
[I][ GetKVCache][ 331]: precompute_len:130, remaining:1918
|
| 145 |
prompt >> q
|
| 146 |
```
|
| 147 |
|
| 148 |
+
### 启动服务(OpenAI 兼容)
|
| 149 |
+
|
| 150 |
+
```shell
|
| 151 |
+
(base) root@ax650:~# axllm serve AXERA-TECH/Qwen3-0.6B/
|
| 152 |
+
[I][ Init][ 127]: LLM init start
|
| 153 |
+
tokenizer_type = 1
|
| 154 |
+
96% | ███████████████████████████████ | 30 / 31 [2.06s<2.13s, 14.58 count/s] init post axmodel ok,remain_cmm(8662 MB)
|
| 155 |
+
[I][ Init][ 188]: max_token_len : 2559
|
| 156 |
+
[I][ Init][ 191]: kv_cache_size : 1024, kv_cache_num: 2559
|
| 157 |
+
[I][ Init][ 194]: prefill_token_num : 128
|
| 158 |
+
[I][ Init][ 198]: grp: 1, prefill_max_kv_cache_num : 1
|
| 159 |
+
[I][ Init][ 198]: grp: 2, prefill_max_kv_cache_num : 512
|
| 160 |
+
[I][ Init][ 198]: grp: 3, prefill_max_kv_cache_num : 1024
|
| 161 |
+
[I][ Init][ 198]: grp: 4, prefill_max_kv_cache_num : 1536
|
| 162 |
+
[I][ Init][ 198]: grp: 5, prefill_max_kv_cache_num : 2048
|
| 163 |
+
[I][ Init][ 203]: prefill_max_token_num : 2048
|
| 164 |
+
[I][ Init][ 27]: LLaMaEmbedSelector use mmap
|
| 165 |
+
100% | █████████████████████��██████████ | 31 / 31 [2.06s<2.06s, 15.07 count/s] embed_selector init ok
|
| 166 |
+
[I][ load_config][ 282]: load config:
|
| 167 |
+
{
|
| 168 |
+
"enable_repetition_penalty": false,
|
| 169 |
+
"enable_temperature": false,
|
| 170 |
+
"enable_top_k_sampling": false,
|
| 171 |
+
"enable_top_p_sampling": false,
|
| 172 |
+
"penalty_window": 20,
|
| 173 |
+
"repetition_penalty": 1.2,
|
| 174 |
+
"temperature": 0.9,
|
| 175 |
+
"top_k": 10,
|
| 176 |
+
"top_p": 0.8
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
[I][ Init][ 224]: LLM init ok
|
| 180 |
+
Starting server on port 8000 with model 'AXERA-TECH/Qwen3-0.6B'...
|
| 181 |
+
OpenAI API Server starting on http://0.0.0.0:8000
|
| 182 |
+
Max concurrency: 1
|
| 183 |
+
Models: AXERA-TECH/Qwen3-0.6B
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
### OpenAI 调用示例
|
| 187 |
+
|
| 188 |
+
```python
|
| 189 |
+
from openai import OpenAI
|
| 190 |
+
|
| 191 |
+
API_URL = "http://127.0.0.1:8000/v1"
|
| 192 |
+
MODEL = "AXERA-TECH/Qwen3-0.6B"
|
| 193 |
+
|
| 194 |
+
messages = [
|
| 195 |
+
{"role": "system", "content": [{"type": "text", "text": "you are a helpful assistant."}]},
|
| 196 |
+
{"role": "user", "content": "hello"},
|
| 197 |
+
]
|
| 198 |
+
|
| 199 |
+
client = OpenAI(api_key="not-needed", base_url=API_URL)
|
| 200 |
+
completion = client.chat.completions.create(
|
| 201 |
+
model=MODEL,
|
| 202 |
+
messages=messages,
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
print(completion.choices[0].message.content)
|
| 206 |
```
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
### OpenAI 流式调用示例
|
| 210 |
+
|
| 211 |
+
```python
|
| 212 |
+
from openai import OpenAI
|
| 213 |
+
|
| 214 |
+
API_URL = "http://127.0.0.1:8000/v1"
|
| 215 |
+
MODEL = "AXERA-TECH/Qwen3-0.6B"
|
| 216 |
+
|
| 217 |
+
messages = [
|
| 218 |
+
{"role": "system", "content": [{"type": "text", "text": "you are a helpful assistant."}]},
|
| 219 |
+
{"role": "user", "content": "hello"},
|
| 220 |
+
]
|
| 221 |
+
|
| 222 |
+
client = OpenAI(api_key="not-needed", base_url=API_URL)
|
| 223 |
+
stream = client.chat.completions.create(
|
| 224 |
+
model=MODEL,
|
| 225 |
+
messages=messages,
|
| 226 |
+
stream=True,
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
print("assistant:")
|
| 230 |
+
for ev in stream:
|
| 231 |
+
delta = getattr(ev.choices[0], "delta", None)
|
| 232 |
+
if delta and getattr(delta, "content", None):
|
| 233 |
+
print(delta.content, end="", flush=True)
|
| 234 |
+
print("
|
| 235 |
+
")
|
| 236 |
+
```
|
| 237 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"system_prompt": "you are a helpful assistant.",
|
| 3 |
+
"model_name": "AXERA-TECH/FastVLM-1.5B-GPTQ-Int4",
|
| 4 |
+
"url_tokenizer_model": "FastVLM_tokenizer.txt",
|
| 5 |
+
"tokenizer_type": "FastVLM",
|
| 6 |
+
"post_config_path": "post_config.json",
|
| 7 |
+
"template_filename_axmodel": "llava_qwen2_p128_l%d_together.axmodel",
|
| 8 |
+
"axmodel_num": 28,
|
| 9 |
+
"filename_post_axmodel": "llava_qwen2_post.axmodel",
|
| 10 |
+
"filename_tokens_embed": "model.embed_tokens.weight.bfloat16.bin",
|
| 11 |
+
"tokens_embed_num": 151647,
|
| 12 |
+
"tokens_embed_size": 1536,
|
| 13 |
+
"use_mmap_load_embed": true,
|
| 14 |
+
"vlm_type": "FastVLM",
|
| 15 |
+
"filename_image_encoder_axmodel": "image_encoder_1024x1024.axmodel",
|
| 16 |
+
"vision_patch_size": 14,
|
| 17 |
+
"vision_temporal_patch_size": 1,
|
| 18 |
+
"vision_spatial_merge_size": 1,
|
| 19 |
+
"vision_fps": 1,
|
| 20 |
+
"vision_tokens_per_second": 1,
|
| 21 |
+
"vision_cache_dir": "vision_cache",
|
| 22 |
+
"use_mmap_load_layer": true,
|
| 23 |
+
"devices": [
|
| 24 |
+
0,
|
| 25 |
+
1
|
| 26 |
+
]
|
| 27 |
+
}
|
fastvlm_ax650_context_1k_prefill_640_int4/model.embed_tokens.weight.npy
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:1045cc5b2298c3032c2f6a3f1b2f83bc4aa69d39f32476d9bfd7b68b9d380ccd
|
| 3 |
-
size 931719296
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_tokenizer/added_tokens.json
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"<image>": 151646,
|
| 3 |
-
"<|endoftext|>": 151643,
|
| 4 |
-
"<|im_end|>": 151645,
|
| 5 |
-
"<|im_start|>": 151644
|
| 6 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_tokenizer/config.json
DELETED
|
@@ -1,79 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"architectures": [
|
| 3 |
-
"LlavaQwen2ForCausalLM"
|
| 4 |
-
],
|
| 5 |
-
"attention_dropout": 0.0,
|
| 6 |
-
"auto_map": {
|
| 7 |
-
"AutoConfig": "llava_qwen.LlavaConfig",
|
| 8 |
-
"AutoModelForCausalLM": "llava_qwen.LlavaQwen2ForCausalLM"
|
| 9 |
-
},
|
| 10 |
-
"bos_token_id": 151643,
|
| 11 |
-
"dtype": "float32",
|
| 12 |
-
"eos_token_id": 151645,
|
| 13 |
-
"freeze_mm_mlp_adapter": false,
|
| 14 |
-
"hidden_act": "silu",
|
| 15 |
-
"hidden_size": 1536,
|
| 16 |
-
"image_aspect_ratio": "pad",
|
| 17 |
-
"image_grid_pinpoints": null,
|
| 18 |
-
"initializer_range": 0.02,
|
| 19 |
-
"intermediate_size": 8960,
|
| 20 |
-
"layer_types": [
|
| 21 |
-
"full_attention",
|
| 22 |
-
"full_attention",
|
| 23 |
-
"full_attention",
|
| 24 |
-
"full_attention",
|
| 25 |
-
"full_attention",
|
| 26 |
-
"full_attention",
|
| 27 |
-
"full_attention",
|
| 28 |
-
"full_attention",
|
| 29 |
-
"full_attention",
|
| 30 |
-
"full_attention",
|
| 31 |
-
"full_attention",
|
| 32 |
-
"full_attention",
|
| 33 |
-
"full_attention",
|
| 34 |
-
"full_attention",
|
| 35 |
-
"full_attention",
|
| 36 |
-
"full_attention",
|
| 37 |
-
"full_attention",
|
| 38 |
-
"full_attention",
|
| 39 |
-
"full_attention",
|
| 40 |
-
"full_attention",
|
| 41 |
-
"full_attention",
|
| 42 |
-
"full_attention",
|
| 43 |
-
"full_attention",
|
| 44 |
-
"full_attention",
|
| 45 |
-
"full_attention",
|
| 46 |
-
"full_attention",
|
| 47 |
-
"full_attention",
|
| 48 |
-
"full_attention"
|
| 49 |
-
],
|
| 50 |
-
"max_position_embeddings": 32768,
|
| 51 |
-
"max_window_layers": 28,
|
| 52 |
-
"mm_hidden_size": 3072,
|
| 53 |
-
"mm_patch_merge_type": "flat",
|
| 54 |
-
"mm_projector_lr": null,
|
| 55 |
-
"mm_projector_type": "mlp2x_gelu",
|
| 56 |
-
"mm_use_im_patch_token": false,
|
| 57 |
-
"mm_use_im_start_end": false,
|
| 58 |
-
"mm_vision_select_feature": "patch",
|
| 59 |
-
"mm_vision_select_layer": -2,
|
| 60 |
-
"mm_vision_tower": "mobileclip_l_1024",
|
| 61 |
-
"model_type": "llava_qwen2",
|
| 62 |
-
"num_attention_heads": 12,
|
| 63 |
-
"num_hidden_layers": 28,
|
| 64 |
-
"num_key_value_heads": 2,
|
| 65 |
-
"rms_norm_eps": 1e-06,
|
| 66 |
-
"rope_scaling": null,
|
| 67 |
-
"rope_theta": 1000000.0,
|
| 68 |
-
"sliding_window": null,
|
| 69 |
-
"tie_word_embeddings": true,
|
| 70 |
-
"tokenizer_model_max_length": 8192,
|
| 71 |
-
"tokenizer_padding_side": "right",
|
| 72 |
-
"transformers_version": "4.57.0",
|
| 73 |
-
"tune_mm_mlp_adapter": false,
|
| 74 |
-
"unfreeze_mm_vision_tower": true,
|
| 75 |
-
"use_cache": true,
|
| 76 |
-
"use_mm_proj": true,
|
| 77 |
-
"use_sliding_window": false,
|
| 78 |
-
"vocab_size": 151647
|
| 79 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_tokenizer/generation_config.json
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"do_sample": true,
|
| 3 |
-
"temperature": null,
|
| 4 |
-
"top_p": null,
|
| 5 |
-
"transformers_version": "4.57.0"
|
| 6 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_tokenizer/merges.txt
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
fastvlm_tokenizer/special_tokens_map.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"additional_special_tokens": [
|
| 3 |
-
"<|im_start|>",
|
| 4 |
-
"<|im_end|>"
|
| 5 |
-
],
|
| 6 |
-
"eos_token": {
|
| 7 |
-
"content": "<|im_end|>",
|
| 8 |
-
"lstrip": false,
|
| 9 |
-
"normalized": false,
|
| 10 |
-
"rstrip": false,
|
| 11 |
-
"single_word": false
|
| 12 |
-
},
|
| 13 |
-
"pad_token": {
|
| 14 |
-
"content": "<|endoftext|>",
|
| 15 |
-
"lstrip": false,
|
| 16 |
-
"normalized": false,
|
| 17 |
-
"rstrip": false,
|
| 18 |
-
"single_word": false
|
| 19 |
-
}
|
| 20 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_tokenizer/tokenizer.json
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:b187c9fe72f04a62ed1f592418d79751ed77f5eab6c3abded85349cf97f152ea
|
| 3 |
-
size 11413284
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_tokenizer/tokenizer_config.json
DELETED
|
@@ -1,52 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"add_prefix_space": false,
|
| 3 |
-
"added_tokens_decoder": {
|
| 4 |
-
"151643": {
|
| 5 |
-
"content": "<|endoftext|>",
|
| 6 |
-
"lstrip": false,
|
| 7 |
-
"normalized": false,
|
| 8 |
-
"rstrip": false,
|
| 9 |
-
"single_word": false,
|
| 10 |
-
"special": true
|
| 11 |
-
},
|
| 12 |
-
"151644": {
|
| 13 |
-
"content": "<|im_start|>",
|
| 14 |
-
"lstrip": false,
|
| 15 |
-
"normalized": false,
|
| 16 |
-
"rstrip": false,
|
| 17 |
-
"single_word": false,
|
| 18 |
-
"special": true
|
| 19 |
-
},
|
| 20 |
-
"151645": {
|
| 21 |
-
"content": "<|im_end|>",
|
| 22 |
-
"lstrip": false,
|
| 23 |
-
"normalized": false,
|
| 24 |
-
"rstrip": false,
|
| 25 |
-
"single_word": false,
|
| 26 |
-
"special": true
|
| 27 |
-
},
|
| 28 |
-
"151646": {
|
| 29 |
-
"content": "<image>",
|
| 30 |
-
"lstrip": false,
|
| 31 |
-
"normalized": true,
|
| 32 |
-
"rstrip": false,
|
| 33 |
-
"single_word": false,
|
| 34 |
-
"special": false
|
| 35 |
-
}
|
| 36 |
-
},
|
| 37 |
-
"additional_special_tokens": [
|
| 38 |
-
"<|im_start|>",
|
| 39 |
-
"<|im_end|>"
|
| 40 |
-
],
|
| 41 |
-
"bos_token": null,
|
| 42 |
-
"clean_up_tokenization_spaces": false,
|
| 43 |
-
"eos_token": "<|im_end|>",
|
| 44 |
-
"errors": "replace",
|
| 45 |
-
"extra_special_tokens": {},
|
| 46 |
-
"model_max_length": 8192,
|
| 47 |
-
"pad_token": "<|endoftext|>",
|
| 48 |
-
"padding_side": "right",
|
| 49 |
-
"split_special_tokens": false,
|
| 50 |
-
"tokenizer_class": "Qwen2Tokenizer",
|
| 51 |
-
"unk_token": null
|
| 52 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_tokenizer/trainer_state.json
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
fastvlm_tokenizer/vocab.json
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
images/image_1.jpg → image.png
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/image_encoder_1024x1024.axmodel → image_encoder_1024x1024.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/image_encoder_512x512.axmodel → image_encoder_512x512.axmodel
RENAMED
|
File without changes
|
infer_axmodel.py
DELETED
|
@@ -1,130 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import argparse
|
| 3 |
-
|
| 4 |
-
from PIL import Image
|
| 5 |
-
import numpy as np
|
| 6 |
-
from utils.llava_qwen import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, DEFAULT_IMAGE_PATCH_TOKEN
|
| 7 |
-
from utils.llava_qwen import tokenizer_image_token, expand2square
|
| 8 |
-
from utils.infer_func import InferManager
|
| 9 |
-
from transformers import AutoTokenizer, AutoConfig, CLIPImageProcessor
|
| 10 |
-
import axengine as ax
|
| 11 |
-
from ml_dtypes import bfloat16
|
| 12 |
-
import argparse
|
| 13 |
-
|
| 14 |
-
def load_model_and_tokenizer(model_path):
|
| 15 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 16 |
-
config = AutoConfig.from_pretrained(model_path)
|
| 17 |
-
|
| 18 |
-
mm_use_im_start_end = getattr(config, "mm_use_im_start_end", False)
|
| 19 |
-
mm_use_im_patch_token = getattr(config, "mm_use_im_patch_token", True)
|
| 20 |
-
if mm_use_im_patch_token:
|
| 21 |
-
tokenizer.add_tokens([DEFAULT_IMAGE_PATCH_TOKEN], special_tokens=True)
|
| 22 |
-
if mm_use_im_start_end:
|
| 23 |
-
tokenizer.add_tokens([DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN], special_tokens=True)
|
| 24 |
-
|
| 25 |
-
return config, tokenizer
|
| 26 |
-
|
| 27 |
-
def vision_encoder(image_path, ax_session, args):
|
| 28 |
-
|
| 29 |
-
image_processor = CLIPImageProcessor(size={"shortest_edge": int(args.input_size)}, # CLIP 支持 336x336
|
| 30 |
-
crop_size={"height": int(args.input_size), "width": int(args.input_size)},
|
| 31 |
-
image_mean=[0, 0, 0],
|
| 32 |
-
image_std=[1/255, 1/255, 1/255]
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
-
image = Image.open(image_path).convert('RGB')
|
| 36 |
-
|
| 37 |
-
image = expand2square(image, tuple(int(x*255) for x in image_processor.image_mean))
|
| 38 |
-
input_image = image_processor.preprocess(image, return_tensors='pt')['pixel_values'][0]
|
| 39 |
-
input_image = input_image.unsqueeze(0) # add batch dimension
|
| 40 |
-
|
| 41 |
-
input_image = input_image.numpy().astype(np.uint8).transpose((0, 2, 3, 1)) # NHWC to NCHW
|
| 42 |
-
vit_output = ax_session.run(None, {"images": input_image})[0]
|
| 43 |
-
|
| 44 |
-
return vit_output
|
| 45 |
-
|
| 46 |
-
def llm_infer(image_features, llm_path, config, tokenizer, imer, get_input, token_length, embeds):
|
| 47 |
-
|
| 48 |
-
prompt = "<|im_start|>system\nYou are a helpful assistant, created by apple company.<|im_end|>\n"
|
| 49 |
-
question = get_input
|
| 50 |
-
prompt += "<|im_start|>user\n" + question
|
| 51 |
-
|
| 52 |
-
if image_features is not None:
|
| 53 |
-
# # for idx in range(len(image_features)):
|
| 54 |
-
prompt += "\n" + "<image>"*token_length + "\n"
|
| 55 |
-
prompt += "<|im_end|>\n<|im_start|>assistant\n"
|
| 56 |
-
|
| 57 |
-
token_ids = tokenizer.encode(prompt)
|
| 58 |
-
|
| 59 |
-
# 图像理解
|
| 60 |
-
prefill_data = np.take(embeds, token_ids, axis=0)
|
| 61 |
-
prefill_data = prefill_data.astype(bfloat16)
|
| 62 |
-
token_len = len(token_ids)
|
| 63 |
-
|
| 64 |
-
if image_features is not None:
|
| 65 |
-
image_start_index = np.where(np.array(token_ids) == 151646)[0][0] # <image> tag 151646
|
| 66 |
-
image_insert_index = image_start_index + 1
|
| 67 |
-
prefill_data[image_insert_index : image_insert_index + token_length] = image_features[0, :, :]
|
| 68 |
-
|
| 69 |
-
eos_token_id = None
|
| 70 |
-
if isinstance(config.eos_token_id, list) and len(config.eos_token_id) > 1:
|
| 71 |
-
eos_token_id = config.eos_token_id
|
| 72 |
-
|
| 73 |
-
slice_len = 128
|
| 74 |
-
# prefill_max_len = 640
|
| 75 |
-
max_seq_len = 1024 # prefill + decode max length
|
| 76 |
-
|
| 77 |
-
# imer = InferManager(config, llm_path, max_seq_len=max_seq_len) # prefill + decode max length
|
| 78 |
-
|
| 79 |
-
token_ids = imer.prefill(tokenizer, token_ids, prefill_data, slice_len=slice_len)
|
| 80 |
-
imer.decode(tokenizer, token_ids, embeds, slice_len=slice_len, eos_token_id=eos_token_id)
|
| 81 |
-
print("\n")
|
| 82 |
-
|
| 83 |
-
if __name__ == "__main__":
|
| 84 |
-
|
| 85 |
-
args = argparse.ArgumentParser()
|
| 86 |
-
args.add_argument("--vision_model", "-v", type=str, default="./fastvlm_ax650_context_1k_prefill_640_int4/image_encoder_1024x1024.axmodel", help="Path to the vision axmodel.")
|
| 87 |
-
args.add_argument("--model_path", "-m", type=str, default="./fastvlm_ax650_context_1k_prefill_640_int4", help="Path to the llm axmodel.")
|
| 88 |
-
args.add_argument("--tokenizer_path", "-t", type=str, default="./fastvlm_tokenizer", help="Path to the tokenizer.")
|
| 89 |
-
args.add_argument("--input_size", "-i", type=str, default="1024", help="Input size of the vision encoder model.")
|
| 90 |
-
# args.add_argument("--question", type=str, default="介绍一下你自己", help="The question to ask the model.")
|
| 91 |
-
|
| 92 |
-
args = args.parse_args()
|
| 93 |
-
|
| 94 |
-
token_len_map = {"2048": 1280,
|
| 95 |
-
"1024": 256,
|
| 96 |
-
"768": 144,
|
| 97 |
-
"512": 64,
|
| 98 |
-
"256": 16}
|
| 99 |
-
|
| 100 |
-
token_length = token_len_map[args.input_size]
|
| 101 |
-
|
| 102 |
-
print("Loading config, tokenizer and init model.")
|
| 103 |
-
config, tokenizer = load_model_and_tokenizer(model_path=args.tokenizer_path)
|
| 104 |
-
|
| 105 |
-
slice_len = 128
|
| 106 |
-
# prefill_max_len = 640
|
| 107 |
-
max_seq_len = 1024 # prefill + decode max length
|
| 108 |
-
|
| 109 |
-
imer = InferManager(config, args.model_path, max_seq_len=max_seq_len) # prefill + decode max length
|
| 110 |
-
ax_session = ax.InferenceSession(args.vision_model)
|
| 111 |
-
embeds = np.load(os.path.join(args.model_path, "model.embed_tokens.weight.npy"))
|
| 112 |
-
|
| 113 |
-
print(f"[INFO]: 输入文本进��对话,或者输入图片路径进行图片理解, 或者输入q退出对话。")
|
| 114 |
-
while True:
|
| 115 |
-
prompt = input("prompt<<")
|
| 116 |
-
if prompt.strip() == "q":
|
| 117 |
-
print(f"[INFO]: 对话结束,再见。")
|
| 118 |
-
break
|
| 119 |
-
else:
|
| 120 |
-
get_input = prompt.strip()
|
| 121 |
-
if get_input.lower().endswith(("jpg", "jpeg", "png")):
|
| 122 |
-
if not os.path.isfile(get_input):
|
| 123 |
-
print("[INFO]: 输入错误,请检查图片输入路径。")
|
| 124 |
-
continue
|
| 125 |
-
image_features = vision_encoder(get_input, ax_session, args)
|
| 126 |
-
get_input = "Describe the image in detail."
|
| 127 |
-
llm_infer(image_features, args.model_path, config, tokenizer, imer, get_input, token_length, embeds)
|
| 128 |
-
else:
|
| 129 |
-
image_features = None
|
| 130 |
-
llm_infer(image_features, args.model_path, config, tokenizer, imer, get_input, token_length, embeds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l0_together.axmodel → llava_qwen2_p128_l0_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l10_together.axmodel → llava_qwen2_p128_l10_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l11_together.axmodel → llava_qwen2_p128_l11_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l12_together.axmodel → llava_qwen2_p128_l12_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l13_together.axmodel → llava_qwen2_p128_l13_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l14_together.axmodel → llava_qwen2_p128_l14_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l15_together.axmodel → llava_qwen2_p128_l15_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l16_together.axmodel → llava_qwen2_p128_l16_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l17_together.axmodel → llava_qwen2_p128_l17_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l18_together.axmodel → llava_qwen2_p128_l18_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l19_together.axmodel → llava_qwen2_p128_l19_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l1_together.axmodel → llava_qwen2_p128_l1_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l20_together.axmodel → llava_qwen2_p128_l20_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l21_together.axmodel → llava_qwen2_p128_l21_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l22_together.axmodel → llava_qwen2_p128_l22_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l23_together.axmodel → llava_qwen2_p128_l23_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l24_together.axmodel → llava_qwen2_p128_l24_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l25_together.axmodel → llava_qwen2_p128_l25_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l26_together.axmodel → llava_qwen2_p128_l26_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l27_together.axmodel → llava_qwen2_p128_l27_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l2_together.axmodel → llava_qwen2_p128_l2_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l3_together.axmodel → llava_qwen2_p128_l3_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l4_together.axmodel → llava_qwen2_p128_l4_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l5_together.axmodel → llava_qwen2_p128_l5_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l6_together.axmodel → llava_qwen2_p128_l6_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l7_together.axmodel → llava_qwen2_p128_l7_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l8_together.axmodel → llava_qwen2_p128_l8_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_p128_l9_together.axmodel → llava_qwen2_p128_l9_together.axmodel
RENAMED
|
File without changes
|
fastvlm_ax650_context_1k_prefill_640_int4/llava_qwen2_post.axmodel → llava_qwen2_post.axmodel
RENAMED
|
File without changes
|
main_axcl_x86
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:7205b7ade7c5efaeef89fb3e458b6da11508e6d9fe992cfb92eefe0094c4a8b5
|
| 3 |
-
size 7009480
|
|
|
|
|
|
|
|
|
|
|
|
main_axcl_x86_api
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:3c6c2dd57d2679f349a22279a4f4b92f941ec62314b58b38052228552ff0bd70
|
| 3 |
-
size 7128832
|
|
|
|
|
|
|
|
|
|
|
|
fastvlm_ax650_context_1k_prefill_640_int4/model.embed_tokens.weight.bfloat16.bin → model.embed_tokens.weight.bfloat16.bin
RENAMED
|
File without changes
|
post_config.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
{
|
| 2 |
-
"enable_temperature" :
|
| 3 |
-
"temperature" : 0.
|
| 4 |
|
| 5 |
"enable_repetition_penalty" : false,
|
| 6 |
-
"repetition_penalty" : 2,
|
| 7 |
-
"penalty_window" :
|
| 8 |
|
| 9 |
"enable_top_p_sampling" : false,
|
| 10 |
"top_p" : 0.8,
|
| 11 |
|
| 12 |
-
"enable_top_k_sampling" :
|
| 13 |
"top_k" : 10
|
| 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 |
}
|