wli1995 commited on
Commit
e61f34a
·
verified ·
1 Parent(s): e504ae1

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +32 -0
  2. README.md +218 -3
  3. fastvlm_ax650_context_1k_prefill_640/image_encoder_1024x1024.axmodel +3 -0
  4. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l0_together.axmodel +3 -0
  5. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l10_together.axmodel +3 -0
  6. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l11_together.axmodel +3 -0
  7. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l12_together.axmodel +3 -0
  8. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l13_together.axmodel +3 -0
  9. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l14_together.axmodel +3 -0
  10. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l15_together.axmodel +3 -0
  11. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l16_together.axmodel +3 -0
  12. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l17_together.axmodel +3 -0
  13. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l18_together.axmodel +3 -0
  14. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l19_together.axmodel +3 -0
  15. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l1_together.axmodel +3 -0
  16. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l20_together.axmodel +3 -0
  17. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l21_together.axmodel +3 -0
  18. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l22_together.axmodel +3 -0
  19. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l23_together.axmodel +3 -0
  20. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l24_together.axmodel +3 -0
  21. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l25_together.axmodel +3 -0
  22. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l26_together.axmodel +3 -0
  23. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l27_together.axmodel +3 -0
  24. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l2_together.axmodel +3 -0
  25. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l3_together.axmodel +3 -0
  26. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l4_together.axmodel +3 -0
  27. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l5_together.axmodel +3 -0
  28. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l6_together.axmodel +3 -0
  29. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l7_together.axmodel +3 -0
  30. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l8_together.axmodel +3 -0
  31. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l9_together.axmodel +3 -0
  32. fastvlm_ax650_context_1k_prefill_640/llava_qwen2_post.axmodel +3 -0
  33. fastvlm_ax650_context_1k_prefill_640/model.embed_tokens.weight.bfloat16.bin +3 -0
  34. fastvlm_ax650_context_1k_prefill_640/model.embed_tokens.weight.npy +3 -0
  35. fastvlm_tokenizer/added_tokens.json +5 -0
  36. fastvlm_tokenizer/config.json +49 -0
  37. fastvlm_tokenizer/generation_config.json +6 -0
  38. fastvlm_tokenizer/merges.txt +0 -0
  39. fastvlm_tokenizer/special_tokens_map.json +20 -0
  40. fastvlm_tokenizer/tokenizer_config.json +44 -0
  41. fastvlm_tokenizer/trainer_state.json +0 -0
  42. fastvlm_tokenizer/vocab.json +0 -0
  43. images/image_1.jpg +3 -0
  44. images/ssd_horse.jpg +3 -0
  45. infer_axmodel.py +123 -0
  46. requirements.txt +3 -0
  47. utils/__pycache__/conversation.cpython-313.pyc +0 -0
  48. utils/__pycache__/infer_func.cpython-313.pyc +0 -0
  49. utils/__pycache__/llava_qwen.cpython-312.pyc +0 -0
  50. utils/__pycache__/llava_qwen.cpython-313.pyc +0 -0
.gitattributes CHANGED
@@ -33,3 +33,35 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  *.zip 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
+ fastvlm_ax650_context_1k_prefill_640/image_encoder_1024x1024.axmodel filter=lfs diff=lfs merge=lfs -text
37
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l0_together.axmodel filter=lfs diff=lfs merge=lfs -text
38
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l10_together.axmodel filter=lfs diff=lfs merge=lfs -text
39
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l11_together.axmodel filter=lfs diff=lfs merge=lfs -text
40
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l12_together.axmodel filter=lfs diff=lfs merge=lfs -text
41
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l13_together.axmodel filter=lfs diff=lfs merge=lfs -text
42
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l14_together.axmodel filter=lfs diff=lfs merge=lfs -text
43
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l15_together.axmodel filter=lfs diff=lfs merge=lfs -text
44
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l16_together.axmodel filter=lfs diff=lfs merge=lfs -text
45
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l17_together.axmodel filter=lfs diff=lfs merge=lfs -text
46
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l18_together.axmodel filter=lfs diff=lfs merge=lfs -text
47
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l19_together.axmodel filter=lfs diff=lfs merge=lfs -text
48
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l1_together.axmodel filter=lfs diff=lfs merge=lfs -text
49
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l20_together.axmodel filter=lfs diff=lfs merge=lfs -text
50
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l21_together.axmodel filter=lfs diff=lfs merge=lfs -text
51
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l22_together.axmodel filter=lfs diff=lfs merge=lfs -text
52
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l23_together.axmodel filter=lfs diff=lfs merge=lfs -text
53
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l24_together.axmodel filter=lfs diff=lfs merge=lfs -text
54
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l25_together.axmodel filter=lfs diff=lfs merge=lfs -text
55
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l26_together.axmodel filter=lfs diff=lfs merge=lfs -text
56
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l27_together.axmodel filter=lfs diff=lfs merge=lfs -text
57
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l2_together.axmodel filter=lfs diff=lfs merge=lfs -text
58
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l3_together.axmodel filter=lfs diff=lfs merge=lfs -text
59
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l4_together.axmodel filter=lfs diff=lfs merge=lfs -text
60
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l5_together.axmodel filter=lfs diff=lfs merge=lfs -text
61
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l6_together.axmodel filter=lfs diff=lfs merge=lfs -text
62
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l7_together.axmodel filter=lfs diff=lfs merge=lfs -text
63
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l8_together.axmodel filter=lfs diff=lfs merge=lfs -text
64
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l9_together.axmodel filter=lfs diff=lfs merge=lfs -text
65
+ fastvlm_ax650_context_1k_prefill_640/llava_qwen2_post.axmodel filter=lfs diff=lfs merge=lfs -text
66
+ images/image_1.jpg filter=lfs diff=lfs merge=lfs -text
67
+ images/ssd_horse.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,218 @@
1
- ---
2
- license: bsd-3-clause
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FastVLM-1.5B
2
+
3
+ This version of FastVLM-1.5B has been converted to run on the Axera NPU using **w8a16** quantization.
4
+
5
+ This model has been optimized with the following LoRA:
6
+
7
+ Compatible with Pulsar2 version: 5.1-patch1.
8
+
9
+ Please note that the context of the model is 1k and the maximum prefill length is 640 tokens.
10
+
11
+ ## Convert tools links:
12
+
13
+ For those who are interested in model conversion, you can try to export axmodel through the original repo:
14
+
15
+ https://huggingface.co/apple/FastVLM-1.5B
16
+
17
+ How to Convert LLM from Huggingface to axmodel[TODO]
18
+
19
+ ## Support Platform
20
+
21
+ - AX650
22
+ - AX650N DEMO Board
23
+ - [M4N-Dock(爱芯派Pro)](https://wiki.sipeed.com/hardware/zh/maixIV/m4ndock/m4ndock.html)
24
+ - [M.2 Accelerator card](https://axcl-docs.readthedocs.io/zh-cn/latest/doc_guide_hardware.html)
25
+
26
+ |Chips|image encoder 1024|ttft(291tokens)|w8a16|
27
+ |--|--|--|--|
28
+ |AX650| 216.257 ms | 861.213 ms | 13.88 tokens/sec|
29
+
30
+
31
+ ## How to use
32
+
33
+ Download all files from this repository to the device
34
+
35
+ ```
36
+ $ tree -L 1
37
+ .
38
+ ├── fastvlm_ax650_context_1k_prefill_640
39
+ ├── fastvlm_tokenizer
40
+ ├── images
41
+ ├── infer_axmodel.py
42
+ ├── README.md
43
+ └── utils
44
+
45
+ 5 directories, 2 files
46
+
47
+ ```
48
+
49
+ #### Install transformer
50
+
51
+ ```
52
+ pip install -r requirements.txt
53
+ ```
54
+
55
+ #### Inference with AX650 Host, such as M4N-Dock(爱芯派Pro) or AX650 DEMO Board
56
+
57
+ Run the following command on the Axera board to start a chat conversation:
58
+
59
+ ```sh
60
+ $ python infer_axmodel.py -v ./fastvlm_ax650_context_1k_prefill_640/image_encoder_1024x1024.axmodel -m ./fastvlm_ax650_context_1k_prefill_640 -t ./fastvlm_tokenizer/
61
+ ```
62
+ output:
63
+
64
+ ```bash
65
+ [INFO] Available providers: ['AXCLRTExecutionProvider']
66
+ Loading config, tokenizer and init model.
67
+ Detected prefixes: ['llava_qwen2'], chosen: llava_qwen2, layers: 28
68
+ Init InferenceSession: 0%| | 0/28 [00:00<?, ?it/s][INFO] Using provider: AXCLRTExecutionProvider
69
+ [INFO] SOC Name: AX650N
70
+ [INFO] VNPU type: VNPUType.DISABLED
71
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
72
+ Init InferenceSession: 4%|████ | 1/28 [00:01<00:28, 1.05s/it][INFO] Using provider: AXCLRTExecutionProvider
73
+ [INFO] SOC Name: AX650N
74
+ [INFO] VNPU type: VNPUType.DISABLED
75
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
76
+ Init InferenceSession: 7%|████████▏ | 2/28 [00:01<00:21, 1.20it/s][INFO] Using provider: AXCLRTExecutionProvider
77
+ [INFO] SOC Name: AX650N
78
+ [INFO] VNPU type: VNPUType.DISABLED
79
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
80
+ Init InferenceSession: 11%|████████████▏ | 3/28 [00:02<00:19, 1.30it/s][INFO] Using provider: AXCLRTExecutionProvider
81
+ [INFO] SOC Name: AX650N
82
+ [INFO] VNPU type: VNPUType.DISABLED
83
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
84
+ Init InferenceSession: 14%|████████████████▎ | 4/28 [00:03<00:17, 1.36it/s][INFO] Using provider: AXCLRTExecutionProvider
85
+ [INFO] SOC Name: AX650N
86
+ [INFO] VNPU type: VNPUType.DISABLED
87
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
88
+ Init InferenceSession: 18%|████████████████████▎ | 5/28 [00:03<00:16, 1.40it/s][INFO] Using provider: AXCLRTExecutionProvider
89
+ [INFO] SOC Name: AX650N
90
+ [INFO] VNPU type: VNPUType.DISABLED
91
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
92
+ Init InferenceSession: 21%|████████████████████████▍ | 6/28 [00:04<00:15, 1.42it/s][INFO] Using provider: AXCLRTExecutionProvider
93
+ [INFO] SOC Name: AX650N
94
+ [INFO] VNPU type: VNPUType.DISABLED
95
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
96
+ Init InferenceSession: 25%|████████████████████████████▌ | 7/28 [00:05<00:14, 1.43it/s][INFO] Using provider: AXCLRTExecutionProvider
97
+ [INFO] SOC Name: AX650N
98
+ [INFO] VNPU type: VNPUType.DISABLED
99
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
100
+ Init InferenceSession: 29%|████████████████████████████████▌ | 8/28 [00:05<00:13, 1.44it/s][INFO] Using provider: AXCLRTExecutionProvider
101
+ [INFO] SOC Name: AX650N
102
+ [INFO] VNPU type: VNPUType.DISABLED
103
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
104
+ Init InferenceSession: 32%|████████████████████████████████████▋ | 9/28 [00:06<00:13, 1.44it/s][INFO] Using provider: AXCLRTExecutionProvider
105
+ [INFO] SOC Name: AX650N
106
+ [INFO] VNPU type: VNPUType.DISABLED
107
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
108
+ Init InferenceSession: 36%|████████████████████████████████████████▎ | 10/28 [00:07<00:12, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
109
+ [INFO] SOC Name: AX650N
110
+ [INFO] VNPU type: VNPUType.DISABLED
111
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
112
+ Init InferenceSession: 39%|████████████████████████████████████████████▍ | 11/28 [00:07<00:11, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
113
+ [INFO] SOC Name: AX650N
114
+ [INFO] VNPU type: VNPUType.DISABLED
115
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
116
+ Init InferenceSession: 43%|████████████████████████████████████████████████▍ | 12/28 [00:08<00:11, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
117
+ [INFO] SOC Name: AX650N
118
+ [INFO] VNPU type: VNPUType.DISABLED
119
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
120
+ Init InferenceSession: 46%|████████████████████████████████████████████████████▍ | 13/28 [00:09<00:10, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
121
+ [INFO] SOC Name: AX650N
122
+ [INFO] VNPU type: VNPUType.DISABLED
123
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
124
+ Init InferenceSession: 50%|████████████████████████████████████████████████████████▌ | 14/28 [00:09<00:09, 1.46it/s][INFO] Using provider: AXCLRTExecutionProvider
125
+ [INFO] SOC Name: AX650N
126
+ [INFO] VNPU type: VNPUType.DISABLED
127
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
128
+ Init InferenceSession: 54%|████████████████████████████████████████████████████████████▌ | 15/28 [00:10<00:08, 1.46it/s][INFO] Using provider: AXCLRTExecutionProvider
129
+ [INFO] SOC Name: AX650N
130
+ [INFO] VNPU type: VNPUType.DISABLED
131
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
132
+ Init InferenceSession: 57%|████████████████████████████████████████████████████████████████▌ | 16/28 [00:11<00:08, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
133
+ [INFO] SOC Name: AX650N
134
+ [INFO] VNPU type: VNPUType.DISABLED
135
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
136
+ Init InferenceSession: 61%|████████████████████████████████████████████████████████████████████▌ | 17/28 [00:12<00:07, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
137
+ [INFO] SOC Name: AX650N
138
+ [INFO] VNPU type: VNPUType.DISABLED
139
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
140
+ Init InferenceSession: 64%|████████████████████████████████████████████████████████████████████████▋ | 18/28 [00:12<00:06, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
141
+ [INFO] SOC Name: AX650N
142
+ [INFO] VNPU type: VNPUType.DISABLED
143
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
144
+ Init InferenceSession: 68%|████████████████████████████████████████████████████████████████████████████▋ | 19/28 [00:13<00:06, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
145
+ [INFO] SOC Name: AX650N
146
+ [INFO] VNPU type: VNPUType.DISABLED
147
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
148
+ Init InferenceSession: 71%|████████████████████████████████████████████████████████████████████████████████▋ | 20/28 [00:14<00:05, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
149
+ [INFO] SOC Name: AX650N
150
+ [INFO] VNPU type: VNPUType.DISABLED
151
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
152
+ Init InferenceSession: 75%|████████████████████████████████████████████████████████████████████████████████████▊ | 21/28 [00:14<00:04, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
153
+ [INFO] SOC Name: AX650N
154
+ [INFO] VNPU type: VNPUType.DISABLED
155
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
156
+ Init InferenceSession: 79%|████████████████████████████████████████████████████████████████████████████████████████▊ | 22/28 [00:15<00:04, 1.46it/s][INFO] Using provider: AXCLRTExecutionProvider
157
+ [INFO] SOC Name: AX650N
158
+ [INFO] VNPU type: VNPUType.DISABLED
159
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
160
+ Init InferenceSession: 82%|████████████████████████████████████████████████████████████████████████████████████████████▊ | 23/28 [00:16<00:03, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
161
+ [INFO] SOC Name: AX650N
162
+ [INFO] VNPU type: VNPUType.DISABLED
163
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
164
+ Init InferenceSession: 86%|████████████████████████████████████████████████████████████████████████████████████████████████▊ | 24/28 [00:16<00:02, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
165
+ [INFO] SOC Name: AX650N
166
+ [INFO] VNPU type: VNPUType.DISABLED
167
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
168
+ Init InferenceSession: 89%|████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 25/28 [00:17<00:02, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
169
+ [INFO] SOC Name: AX650N
170
+ [INFO] VNPU type: VNPUType.DISABLED
171
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
172
+ Init InferenceSession: 93%|████████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 26/28 [00:18<00:01, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
173
+ [INFO] SOC Name: AX650N
174
+ [INFO] VNPU type: VNPUType.DISABLED
175
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
176
+ Init InferenceSession: 96%|████████████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 27/28 [00:18<00:00, 1.45it/s][INFO] Using provider: AXCLRTExecutionProvider
177
+ [INFO] SOC Name: AX650N
178
+ [INFO] VNPU type: VNPUType.DISABLED
179
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
180
+ Init InferenceSession: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:19<00:00, 1.43it/s]
181
+ [INFO] Using provider: AXCLRTExecutionProvider
182
+ [INFO] SOC Name: AX650N
183
+ [INFO] VNPU type: VNPUType.DISABLED
184
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
185
+ Model loaded successfully!
186
+ [INFO] Using provider: AXCLRTExecutionProvider
187
+ [INFO] SOC Name: AX650N
188
+ [INFO] VNPU type: VNPUType.DISABLED
189
+ [INFO] Compiler version: 5.1-patch1-dirty 140e8d4a-dirty
190
+ [INFO]: 输入文本进行对话,或者输入图片路径进行图片理解, ���者输入q退出对话。
191
+ prompt<<who are you
192
+ slice_indices: [0]
193
+ Slice prefill done: 0
194
+ answer >> I am an artificial intelligence designed and developed by Apple Inc. I am a natural language processing model that can understand and respond to user input in a conversational manner. I can answer questions, provide information, and engage in discussions on a wide range of topics. I am designed to be helpful, informative, and friendly, and I am constantly learning and improving to provide the best possible experience for users.
195
+
196
+ prompt<<./images/ssd_horse.jpg
197
+ slice_indices: [0, 1, 2]
198
+ Slice prefill done: 0
199
+ Slice prefill done: 1
200
+ Slice prefill done: 2
201
+ answer >> The image depicts a serene outdoor scene featuring a person riding a brown horse with a white blaze on its face. The rider, who has short brown hair, is wearing a blue hoodie, blue jeans, and black boots. The horse is equipped with a saddle and a bridle, and it stands on a dirt ground.
202
+
203
+ In the foreground, a brown dog with a pink collar is sitting on the ground, looking up at the rider with its mouth open, possibly in anticipation or excitement.
204
+
205
+ In the background, there is a silver pickup truck parked near a fence, and beyond the fence, there are trees and a few people sitting on a bench. The sky is overcast, suggesting a cloudy day. The overall atmosphere of the image is calm and peaceful, capturing a moment of connection between the rider, the horse, and the dog.
206
+
207
+ prompt<<./images/image_1.jpg
208
+ slice_indices: [0, 1, 2]
209
+ Slice prefill done: 0
210
+ Slice prefill done: 1
211
+ Slice prefill done: 2
212
+ answer >> The image depicts a panda bear in a natural setting. The panda is sitting on the ground, surrounded by green bamboo leaves and plants. The panda has a distinctive black and white fur pattern, with black patches around its eyes, ears, and limbs, and a white face and body. The panda appears to be holding a bamboo leaf in its mouth, which is a common food source for pandas. The background includes a wooden structure, possibly a part of a bamboo enclosure, and some rocks. The overall scene suggests that the panda is in a zoo or a wildlife sanctuary.
213
+
214
+ prompt<<q
215
+ [INFO]: 对话结束,再见。
216
+ ```
217
+ ![ssd_horse.jpg](./images/ssd_horse.jpg)
218
+ ![iamge_1.jpg](./images/image_1.jpg)
fastvlm_ax650_context_1k_prefill_640/image_encoder_1024x1024.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c8cc3fd059d4f3e81b943c729328cd79e8cade9aebfc3bad550a1153e591a062
3
+ size 178882992
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l0_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:79696a151261bf94bde60edb042f9083c9d975aa48ebba0d616e8362e96e6677
3
+ size 54742139
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l10_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:218abf9720bbdd58a994ece53839a1afe3328cbbeb526dcc0bff8792cc437fb3
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l11_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f56e5a974e959a7a773c5f95cbfb325216028c8d2ffda9e366420f6524e2d109
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l12_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:047045d2052d76f156a3992e05aff0d5f06ccedf4b851a447d6c369a97968fe9
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l13_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d69e5193c31fc635938166618e0a23e09d518fd6e8b5518e586624a783aedf07
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l14_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f339540b2c7bbf7a6657aeb9a7fc5b883497fd166907050daa890788071619e6
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l15_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c7b213a799f7b37bc2c3e329e60c981448e0efb2d9391fbf9041471494a9c3d
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l16_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4bdca39e1a218791828a45b6c95c42a491bbacec7de5a6d026c25cbf67f46df9
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l17_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f64f203200d16325c4d47c09dfa11c1c41e23263b597f7bc463251a8602170bd
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l18_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d2c71776cb616b73c03e92dfef1ceb91603ef2791b1706eb3c0cdc268e19fecd
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l19_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce61b20723c850b40b6d40474738d3c57f689dc4688df020d7022c37eca39f8a
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l1_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88cd3291c4ea1acf28edd8dae72f78a668bece58b4567921da1946bb2648b8db
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l20_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c1483294d9013d065f24ff958149818cf924d8d644241a220e117ac065d38b4
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l21_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9b8d0fed2dcd88ad150a99c0c487c936d9449878379e8fe8ea6861ea3f63465
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l22_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3647b94d63f9b2792bebfb4c3d952704e40608751c4555c72ea495773e15a86
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l23_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be4dbc1650ca7dcd98a9968a56cc246a67246797e13472a54c3e5356ebd8f9f8
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l24_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:024a7592c0b6034ab1cca8ec24f57ed789a199de0a0fdf5405a285fa524ab239
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l25_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3576ea7ce42236ef8869555fd67dda93a693f853e7dc876fb98ebe75d28b6c11
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l26_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4328d9bde2f1306c75d6b8450b544e3a6ae8a6056ff475c6eb7a08f8b8eaedec
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l27_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35e9ecf6f4d4bf88694e55f8cf8811ac7b4a728c91bef123c274d1f96db63c86
3
+ size 54741955
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l2_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e64be5c1a4a0c23f7c43cbbc6042452901f4f8f373d79fa9b54e92445e54774f
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l3_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f09a880164e78740ad72fa083b3caaaa2a905a4f18f695d681e10d3b23c5b235
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l4_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3657f3c8591e91a3ddc9b3f3587fa82086c4b30344fee5dc970d184c7ef80369
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l5_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ddfd9b0d314c69b544161026bf3486ab83274089b19092bbbf20e5d95b401f07
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l6_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3c7c471c660e8ff249a8063748a43b6d763c7828d883d903dd1c57f5e32417f7
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l7_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d2c164e9c6a01638c376932fcf56e62c61e57c0d5760b09cda3d9c2c45b74a8a
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l8_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:60f4f3c8852374019e3e9f7e762bc0da44bfb9f030e75ee3fab005267a2ee786
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_p128_l9_together.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:66901cd9f53f6122239a5841c1f282adf25fee8e6cfe8890785e5c267f4b7fd3
3
+ size 54741947
fastvlm_ax650_context_1k_prefill_640/llava_qwen2_post.axmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a1e249b71dee1ec8ed185efbf8edb77fea423977927eca4a57801595f28e9dd
3
+ size 254826994
fastvlm_ax650_context_1k_prefill_640/model.embed_tokens.weight.bfloat16.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e01aea64483c11c7de1dbfb8fac8b07860ad669718deb5cf35b8eb71a0dbe593
3
+ size 466747392
fastvlm_ax650_context_1k_prefill_640/model.embed_tokens.weight.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f682683aa248b48679ed39eb816e4066c7c4a9f53f7b94bad2aef079a63a6d3
3
+ size 933494912
fastvlm_tokenizer/added_tokens.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "<|endoftext|>": 151643,
3
+ "<|im_end|>": 151645,
4
+ "<|im_start|>": 151644
5
+ }
fastvlm_tokenizer/config.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./llava-v1.5-13b",
3
+ "architectures": [
4
+ "LlavaQwen2ForCausalLM"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "llava_qwen.LlavaConfig",
8
+ "AutoModelForCausalLM": "llava_qwen.LlavaQwen2ForCausalLM"
9
+ },
10
+ "attention_dropout": 0.0,
11
+ "bos_token_id": 151643,
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
+ "max_position_embeddings": 32768,
21
+ "max_window_layers": 28,
22
+ "mm_hidden_size": 3072,
23
+ "mm_patch_merge_type": "flat",
24
+ "mm_projector_lr": null,
25
+ "mm_projector_type": "mlp2x_gelu",
26
+ "mm_use_im_patch_token": false,
27
+ "mm_use_im_start_end": false,
28
+ "mm_vision_select_feature": "patch",
29
+ "mm_vision_select_layer": -2,
30
+ "mm_vision_tower": "mobileclip_l_1024",
31
+ "model_type": "llava_qwen2",
32
+ "num_attention_heads": 12,
33
+ "num_hidden_layers": 28,
34
+ "num_key_value_heads": 2,
35
+ "rms_norm_eps": 1e-06,
36
+ "rope_theta": 1000000.0,
37
+ "sliding_window": 32768,
38
+ "tie_word_embeddings": true,
39
+ "tokenizer_model_max_length": 8192,
40
+ "tokenizer_padding_side": "right",
41
+ "torch_dtype": "bfloat16",
42
+ "transformers_version": "4.39.3",
43
+ "tune_mm_mlp_adapter": false,
44
+ "unfreeze_mm_vision_tower": true,
45
+ "use_cache": true,
46
+ "use_mm_proj": true,
47
+ "use_sliding_window": false,
48
+ "vocab_size": 151936
49
+ }
fastvlm_tokenizer/generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "do_sample": true,
3
+ "temperature": null,
4
+ "top_p": null,
5
+ "transformers_version": "4.39.3"
6
+ }
fastvlm_tokenizer/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
fastvlm_tokenizer/special_tokens_map.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ },
29
+ "additional_special_tokens": [
30
+ "<|im_start|>",
31
+ "<|im_end|>"
32
+ ],
33
+ "bos_token": null,
34
+ "chat_template": "{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}{% endif %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
35
+ "clean_up_tokenization_spaces": false,
36
+ "eos_token": "<|im_end|>",
37
+ "errors": "replace",
38
+ "model_max_length": 8192,
39
+ "pad_token": "<|endoftext|>",
40
+ "padding_side": "right",
41
+ "split_special_tokens": false,
42
+ "tokenizer_class": "Qwen2Tokenizer",
43
+ "unk_token": null
44
+ }
fastvlm_tokenizer/trainer_state.json ADDED
The diff for this file is too large to render. See raw diff
 
fastvlm_tokenizer/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
images/image_1.jpg ADDED

Git LFS Details

  • SHA256: 08487494b8dc08d44bc36491adf3ab89ff30d13a3122da86f3cd67cad89eeee8
  • Pointer size: 131 Bytes
  • Size of remote file: 126 kB
images/ssd_horse.jpg ADDED

Git LFS Details

  • SHA256: ed22f6b4c8c33e50e391e089ede14e8fa9402c623b09dbcf010e804770698fbb
  • Pointer size: 131 Bytes
  • Size of remote file: 123 kB
infer_axmodel.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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):
28
+
29
+ image_processor = CLIPImageProcessor(size={"shortest_edge": 1024}, # CLIP 支持 336x336
30
+ crop_size={"height": 1024, "width": 1024},
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):
47
+
48
+ embeds = np.load(os.path.join(llm_path, "model.embed_tokens.weight.npy"))
49
+
50
+ prompt = "<|im_start|>system\nYou are a helpful assistant, created by apple company.<|im_end|>\n"
51
+ question = get_input
52
+ prompt += "<|im_start|>user\n" + question
53
+
54
+ if image_features is not None:
55
+ # # for idx in range(len(image_features)):
56
+ prompt += "\n<img>" + "<image>"*256 + "</img>\n"
57
+ prompt += "<|im_end|>\n<|im_start|>assistant\n"
58
+
59
+ token_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX)
60
+
61
+ # 图像理解
62
+ prefill_data = np.take(embeds, token_ids, axis=0)
63
+ prefill_data = prefill_data.astype(bfloat16)
64
+ token_len = len(token_ids)
65
+
66
+ if image_features is not None:
67
+ image_start_index = np.where(np.array(token_ids) == -200)[0][0] # <image> tag 151646
68
+ image_insert_index = image_start_index + 1
69
+ prefill_data[image_insert_index : image_insert_index + 256] = image_features[0, :, :]
70
+
71
+ eos_token_id = None
72
+ if isinstance(config.eos_token_id, list) and len(config.eos_token_id) > 1:
73
+ eos_token_id = config.eos_token_id
74
+
75
+ slice_len = 128
76
+ # prefill_max_len = 640
77
+ max_seq_len = 1024 # prefill + decode max length
78
+
79
+ # imer = InferManager(config, llm_path, max_seq_len=max_seq_len) # prefill + decode max length
80
+
81
+ token_ids = imer.prefill(tokenizer, token_ids, prefill_data, slice_len=slice_len)
82
+ imer.decode(tokenizer, token_ids, embeds, slice_len=slice_len, eos_token_id=eos_token_id)
83
+ print("\n")
84
+
85
+ if __name__ == "__main__":
86
+
87
+ args = argparse.ArgumentParser()
88
+ args.add_argument("--vision_model", "-v", type=str, default="./fastvlm_ax650_context_1k_prefill_640/image_encoder_1024x1024.axmodel", help="Path to the vision axmodel.")
89
+ args.add_argument("--model_path", "-m", type=str, default="./fastvlm_ax650_context_1k_prefill_640", help="Path to the llm axmodel.")
90
+ args.add_argument("--tokenizer_path", "-t", type=str, default="./fastvlm_tokenizer", help="Path to the tokenizer.")
91
+ # args.add_argument("--images", type=str, default=None, help="Paths to the input images.")
92
+ # args.add_argument("--question", type=str, default="介绍一下你自己", help="The question to ask the model.")
93
+
94
+ args = args.parse_args()
95
+
96
+ print("Loading config, tokenizer and init model.")
97
+ config, tokenizer = load_model_and_tokenizer(model_path=args.tokenizer_path)
98
+
99
+ slice_len = 128
100
+ # prefill_max_len = 640
101
+ max_seq_len = 1024 # prefill + decode max length
102
+
103
+ imer = InferManager(config, args.model_path, max_seq_len=max_seq_len) # prefill + decode max length
104
+ ax_session = ax.InferenceSession(args.vision_model)
105
+
106
+ print(f"[INFO]: 输入文本进行对话,或者输入图片路径进行图片理解, 或者输入q退出对话。")
107
+ while True:
108
+ prompt = input("prompt<<")
109
+ if prompt.strip() == "q":
110
+ print(f"[INFO]: 对话结束,再见。")
111
+ break
112
+ else:
113
+ get_input = prompt.strip()
114
+ if get_input.lower().endswith(("jpg", "jpeg", "png")):
115
+ if not os.path.isfile(get_input):
116
+ print("[INFO]: 输入错误,请检查图片输入路径。")
117
+ continue
118
+ image_features = vision_encoder(get_input, ax_session)
119
+ get_input = "Describe the image in detail."
120
+ llm_infer(image_features, args.model_path, config, tokenizer, imer, get_input)
121
+ else:
122
+ image_features = None
123
+ llm_infer(image_features, args.model_path, config, tokenizer, imer, get_input)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ numpy
2
+ tqdm
3
+ transformers
utils/__pycache__/conversation.cpython-313.pyc ADDED
Binary file (17.1 kB). View file
 
utils/__pycache__/infer_func.cpython-313.pyc ADDED
Binary file (14 kB). View file
 
utils/__pycache__/llava_qwen.cpython-312.pyc ADDED
Binary file (99.9 kB). View file
 
utils/__pycache__/llava_qwen.cpython-313.pyc ADDED
Binary file (28.7 kB). View file