alex-spacemit commited on
Commit
7abc3c4
·
verified ·
1 Parent(s): ede559c

upload README.md

Browse files
Files changed (1) hide show
  1. README.md +289 -0
README.md ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apple-amlr
3
+ pipeline_tag: image-to-text
4
+ library_name: llama.cpp
5
+ tags:
6
+ - fastvlm
7
+ - spacemit
8
+ - k1
9
+ - k3
10
+ - gguf
11
+ - onnxruntime
12
+ ---
13
+
14
+ # FastVLM-0.5B for SpacemiT K1/K3
15
+
16
+ This repository contains a SpacemiT edge-deployment version of
17
+ [apple/FastVLM-0.5B](https://huggingface.co/apple/FastVLM-0.5B). The FastVLM
18
+ vision encoder is exported as an ONNX model and runs through the SpacemiT
19
+ Execution Provider, while the Qwen2-based 0.5B text decoder is stored as a
20
+ Q4_1 GGUF model and runs through the SpacemiT `llama.cpp` backend.
21
+
22
+ ## Model origin and acknowledgement
23
+
24
+ FastVLM was introduced by Apple in
25
+ [FastVLM: Efficient Vision Encoding for Vision Language Models](https://arxiv.org/abs/2412.13303),
26
+ published at CVPR 2025. It is a vision-language model for understanding and
27
+ describing images. The key FastViTHD encoder is designed to produce fewer
28
+ visual tokens and reduce vision encoding latency, while retaining useful image
29
+ understanding quality. The FastVLM-0.5B variant is the compact model in the
30
+ released family.
31
+
32
+ This repository is a deployment conversion, not a new base model. We thank the
33
+ Apple Machine Learning Research team for releasing the FastVLM model, paper,
34
+ and source code:
35
+
36
+ - [FastVLM paper](https://arxiv.org/abs/2412.13303)
37
+ - [Official FastVLM repository](https://github.com/apple/ml-fastvlm)
38
+ - [Official FastVLM-0.5B model](https://huggingface.co/apple/FastVLM-0.5B)
39
+
40
+ The current SpacemiT package exposes offline image understanding through the
41
+ OpenAI-compatible `llama-server` chat completions API. The bundled
42
+ `humanspeech.jpg` sample has been validated on both K1 and K3.
43
+
44
+ ## Files
45
+
46
+ ```text
47
+ FastVLM-0.5B-SpacemiT/
48
+ ├── fastvlm-text-0.5B-Q4_1.gguf
49
+ ├── fastvlm_vision.f16.onnx
50
+ ├── configs/
51
+ │ ├── K1/config.json
52
+ │ └── K3/config.json
53
+ ├── humanspeech.jpg
54
+ └── README.md
55
+ ```
56
+
57
+ The included `humanspeech.jpg` shows a woman speaking at a podium and is used
58
+ by the board smoke example below. `fastvlm_vision.f16.onnx` is the vision encoder;
59
+ `fastvlm-text-0.5B-Q4_1.gguf` is the text decoder.
60
+
61
+ ## Supported platforms
62
+
63
+ | Platform | Accelerated cores | SMT config | `llama-server` threads |
64
+ |---|---:|---|---:|
65
+ | SpacemiT K1 / X60 | `0,1,2,3` | `configs/K1` | `-t 4` |
66
+ | SpacemiT K3 / A100 | `8,9,10,11,12,13,14,15` | `configs/K3` | `-t 8` |
67
+
68
+ The platform-specific `config.json` controls the ONNX vision encoder's
69
+ SpaceMIT EP thread count and affinity. The `-t` argument controls the GGUF
70
+ text decoder. Do not use the K3 config on K1: K1 has four accelerated cores at
71
+ IDs `0-3`, whereas K3 has eight accelerated cores at IDs `8-15`.
72
+
73
+ The SpacemiT `llama.cpp` runtime automatically detects the accelerated CPU
74
+ cores. Normal runs do not require manually setting
75
+ `SPACEMIT_PERFER_CORE_ARCH`, `SPACEMIT_PERFER_CORE_ID`, or
76
+ `SPACEMIT_MEM_BACKEND`.
77
+
78
+ ## Prerequisites
79
+
80
+ Two runtime components are required:
81
+
82
+ 1. A SpacemiT ONNX Runtime package containing `libonnxruntime` and the
83
+ SpacemiT Execution Provider:
84
+ [spacemit-com/onnxruntime releases](https://github.com/spacemit-com/onnxruntime/releases)
85
+ 2. An SMT-enabled SpacemiT `llama.cpp` build containing `llama-server`:
86
+ [spacemit-com/llama.cpp](https://github.com/spacemit-com/llama.cpp)
87
+
88
+ The validation below used SpacemiT ORT `2.0.6` and a RISC-V
89
+ `llama-server` built from the SpacemiT fork.
90
+
91
+ ### Option A: use prebuilt packages
92
+
93
+ Download and unpack the current RISC-V glibc releases:
94
+
95
+ ```bash
96
+ wget https://github.com/spacemit-com/onnxruntime/releases/download/2.0.6/spacemit-ort.riscv64.2.0.6.tar.gz
97
+ tar -xf spacemit-ort.riscv64.2.0.6.tar.gz
98
+
99
+ wget https://github.com/spacemit-com/llama.cpp/releases/download/v0.1.7/spacemit-llama.cpp.riscv64.0.1.7.tar.gz
100
+ tar -xf spacemit-llama.cpp.riscv64.0.1.7.tar.gz
101
+ ```
102
+
103
+ Check the release pages for newer mutually compatible packages when deploying
104
+ this model in another software image.
105
+
106
+ ### Option B: build llama.cpp from source
107
+
108
+ Cross-compilation also requires a SpacemiT RISC-V toolchain:
109
+
110
+ ```bash
111
+ git clone --recursive https://github.com/spacemit-com/llama.cpp.git
112
+ cd llama.cpp
113
+
114
+ export RISCV_ROOT_PATH=/path/to/spacemit-riscv-toolchain
115
+ export SPACEMIT_ORT_DIR=/path/to/spacemit-ort.riscv64.2.0.6
116
+
117
+ bash build_spacemit.sh glibc
118
+ ```
119
+
120
+ The installed runtime is generated under `build/installed/`. An equivalent
121
+ manual CMake build must enable at least `GGML_CPU_RISCV64_SPACEMIT=ON` and
122
+ `LLAMA_SERVER_SMT_MTMD=ON`, and pass `SPACEMIT_ORT_DIR` to CMake.
123
+
124
+ ## Run on a K1 or K3 board
125
+
126
+ Copy this model folder, the unpacked ORT package, and the prebuilt or locally
127
+ built `llama.cpp` installation to the board. Set the following paths to match
128
+ their actual locations:
129
+
130
+ ```bash
131
+ export MODEL_DIR=/path/to/FastVLM-0.5B-SpacemiT
132
+ export ORT_DIR=/path/to/spacemit-ort.riscv64.2.0.6
133
+ export LLAMA_DIR=/path/to/spacemit-llama.cpp.riscv64.0.1.7
134
+
135
+ export LD_LIBRARY_PATH="${LLAMA_DIR}/lib:${ORT_DIR}/lib:${LD_LIBRARY_PATH:-}"
136
+ ```
137
+
138
+ ### K1
139
+
140
+ K1 uses four accelerated cores, `0-3`:
141
+
142
+ ```bash
143
+ "${LLAMA_DIR}/bin/llama-server" \
144
+ -m "${MODEL_DIR}/fastvlm-text-0.5B-Q4_1.gguf" \
145
+ --media-backend smt \
146
+ --smt-config-dir "${MODEL_DIR}/configs/K1" \
147
+ -t 4 \
148
+ --host 0.0.0.0 \
149
+ --port 8080 \
150
+ --warmup
151
+ ```
152
+
153
+ The K1 vision config applies:
154
+
155
+ ```json
156
+ "ep_config": {
157
+ "SPACEMIT_EP_INTRA_THREAD_NUM": "4",
158
+ "SPACEMIT_EP_INTER_THREAD_NUM": "1",
159
+ "SPACEMIT_EP_INTRA_THREAD_AFFINITY": "0;1;2;3"
160
+ }
161
+ ```
162
+
163
+ ### K3
164
+
165
+ K3 uses eight accelerated cores, `8-15`:
166
+
167
+ ```bash
168
+ "${LLAMA_DIR}/bin/llama-server" \
169
+ -m "${MODEL_DIR}/fastvlm-text-0.5B-Q4_1.gguf" \
170
+ --media-backend smt \
171
+ --smt-config-dir "${MODEL_DIR}/configs/K3" \
172
+ -t 8 \
173
+ --host 0.0.0.0 \
174
+ --port 8080 \
175
+ --warmup
176
+ ```
177
+
178
+ The K3 vision config applies:
179
+
180
+ ```json
181
+ "ep_config": {
182
+ "SPACEMIT_EP_INTRA_THREAD_NUM": "8",
183
+ "SPACEMIT_EP_INTER_THREAD_NUM": "1",
184
+ "SPACEMIT_EP_INTRA_THREAD_AFFINITY": "8;9;10;11;12;13;14;15"
185
+ }
186
+ ```
187
+
188
+ Wait until the server prints a line similar to:
189
+
190
+ ```text
191
+ llama_server: listening on http://0.0.0.0:8080
192
+ ```
193
+
194
+ If the service is reachable outside a trusted local network, configure an API
195
+ key and suitable network access controls instead of exposing an unauthenticated
196
+ `0.0.0.0` endpoint.
197
+
198
+ ## Send an image understanding request
199
+
200
+ The request can be sent from the board itself or another machine that can
201
+ reach the board. Set `SERVER_URL=http://127.0.0.1:8080` when testing locally,
202
+ or replace `BOARD_IP` when testing remotely.
203
+
204
+ ```bash
205
+ export SERVER_URL=http://127.0.0.1:8080
206
+
207
+ base64 < "${MODEL_DIR}/humanspeech.jpg" | tr -d '\n' | jq -Rs '{
208
+ messages: [
209
+ {
210
+ role: "user",
211
+ content: [
212
+ {
213
+ type: "image_url",
214
+ image_url: {
215
+ url: ("data:image/jpeg;base64," + .)
216
+ }
217
+ },
218
+ {
219
+ type: "text",
220
+ text: "Describe the image content."
221
+ }
222
+ ]
223
+ }
224
+ ],
225
+ max_tokens: 64,
226
+ temperature: 0,
227
+ stream: false,
228
+ chat_template_kwargs: {
229
+ enable_thinking: false
230
+ }
231
+ }' | curl "${SERVER_URL}/v1/chat/completions" \
232
+ -H "Content-Type: application/json" \
233
+ --data-binary @-
234
+ ```
235
+
236
+ The generated description is returned in `choices[0].message.content`. Replace
237
+ `humanspeech.jpg` with another JPEG/PNG image to describe your own image.
238
+
239
+ ## Verified example
240
+
241
+ The bundled `humanspeech.jpg` was tested on 2026-08-10 with `--warmup` enabled.
242
+ Both boards returned HTTP 200 and generated a description of the speaker,
243
+ podium, microphone, clothing, and background banner. With `max_tokens=64`,
244
+ the responses were truncated at the requested token limit.
245
+
246
+ K1 example content:
247
+
248
+ ```text
249
+ The image depicts a woman standing at a podium, delivering a speech or presentation. She is positioned at the center of the frame, with her right hand raised, holding a microphone close to her mouth, suggesting she is speaking. She is dressed in a patterned top and dark pants. Behind her, there is a banner
250
+ ```
251
+
252
+ K3 example content:
253
+
254
+ ```text
255
+ The image depicts a woman standing at a podium, delivering a speech or presentation. She is positioned at the center of the frame, with her right hand raised, holding a microphone close to her mouth, suggesting she is actively speaking. She is dressed in a patterned top and dark pants. Behind her, there is a
256
+ ```
257
+
258
+ Observed single-request wall time after server warmup:
259
+
260
+ | Board | HTTP status | Wall time |
261
+ |---|---:|---:|
262
+ | K1 (`0-3`, `-t 4`) | 200 | 9.79 s |
263
+ | K3 (`8-15`, `-t 8`) | 200 | 1.91 s |
264
+
265
+ These are functional smoke-test observations rather than a formal benchmark.
266
+ Startup and first-request time can be longer while the GGUF model is loaded and
267
+ the ONNX graph is compiled.
268
+
269
+ ## Citation
270
+
271
+ Please cite the original FastVLM work when using this converted model:
272
+
273
+ ```bibtex
274
+ @InProceedings{fastvlm2025,
275
+ author = {Pavan Kumar Anasosalu Vasu and Fartash Faghri and Chun-Liang Li and Cem Koc and Nate True and Albert Antony and Gokul Santhanam and James Gabriel and Peter Grasch and Oncel Tuzel and Hadi Pouransari},
276
+ title = {FastVLM: Efficient Vision Encoding for Vision Language Models},
277
+ booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
278
+ month = {June},
279
+ year = {2025},
280
+ }
281
+ ```
282
+
283
+ ## License
284
+
285
+ The original FastVLM model is released under Apple's AMLR model license. See
286
+ the [official model card](https://huggingface.co/apple/FastVLM-0.5B) and the
287
+ official repository's `LICENSE_MODEL` for the terms that apply to the model.
288
+ The SpacemiT `llama.cpp` and ONNX Runtime packages are separate dependencies
289
+ and remain subject to their respective repository licenses.