@@ -170,31 +170,34 @@ Run a binary with `--help` for its model-specific arguments.
170170
171171## Serve
172172
173+ The following instructions use the regular worker built above. For off-graph
174+ exports, use [ the batching server] ( #start-the-batching-server ) below instead.
175+
173176Install the shared server dependencies:
174177
175178``` bash
176- pip install -r examples/llm_server/python/requirements.txt
179+ pip install -r /path/to/executorch/ examples/llm_server/python/requirements.txt
177180```
178181
179- Serve a CUDA target export:
182+ Serve a CUDA target export, replacing the example paths with your local paths :
180183
181184``` bash
182185python -m executorch.examples.models.muse_glimmer.serving.serve \
183- --model-path exports/solo/model.pte \
184- --data-path exports/solo/aoti_cuda_blob.ptd \
185- --tokenizer-path assets/hf/tokenizer.json \
186- --hf-tokenizer assets/hf \
187- --worker-bin cmake-out/examples/models/muse-glimmer/muse_glimmer_worker \
186+ --model-path /path/to/ exports/solo/model.pte \
187+ --data-path /path/to/ exports/solo/aoti_cuda_blob.ptd \
188+ --tokenizer-path /path/to/ assets/hf/tokenizer.json \
189+ --hf-tokenizer /path/to/ assets/hf \
190+ --worker-bin /path/to/executorch/ cmake-out/examples/models/muse-glimmer/muse_glimmer_worker \
188191 --model-id muse-glimmer-30B \
189192 --tool-parser atem \
190193 --host 127.0.0.1 \
191194 --port 8000
192195```
193196
194- For MLX, use the MLX ` model.pte ` and omit ` --data-path ` . For DFlash, replace
195- ` exports/solo ` with ` exports/dflash ` in both artifact paths; the server detects
196- the exported method contract. For vision, also pass
197- ` --pos-embed-path < export-dir>/pos_embed.bin ` .
197+ For MLX, use the MLX export and omit ` --data-path ` . For DFlash, use the matching
198+ DFlash export paths; the server detects the exported method contract. For
199+ vision, also pass ` --pos-embed-path /path/to/exports/solo/pos_embed.bin ` , using
200+ the matching export directory .
198201
199202Smoke test:
200203
@@ -206,13 +209,143 @@ curl http://127.0.0.1:8000/v1/chat/completions \
206209
207210Tool calling is supported with ` --tool-parser atem ` . The canonical Hugging Face
208211template renders tool definitions, and the server converts Muse Glimmer 30B ATEM
209- output into OpenAI-compatible ` tool_calls ` . See
210- [ ` serving/tool_parsers/atem.py ` ] ( serving/tool_parsers/atem.py ) and
211- [ ` tests/test_atem_tool_parser.py ` ] ( tests/test_atem_tool_parser.py ) .
212+ output into OpenAI-compatible ` tool_calls ` .
213+
214+ ## Off-graph KV cache and batching
215+
216+ The off-graph path keeps KV cache state in the runtime rather than inside the
217+ exported model graph. It supports packed multi-session batching, runtime-managed
218+ cache growth, and optional prefix snapshots for reuse across requests.
219+ Batching supports both text-only and vision-enabled exports, with or without
220+ DFlash.
221+
222+ It uses separate batching runners and workers. Regular runner artifacts and
223+ workers are not interchangeable with batching artifacts and workers.
224+
225+ The commands below use MLX as an example. Select the backend matching your
226+ hardware, export, and worker build.
227+
228+ ### Export
229+
230+ Export with ` --use-offgraph-kv-cache ` . For example, using MLX and the checkpoint
231+ variables from [ Model assets] ( #model-assets ) , export a text-only target:
232+
233+ ``` bash
234+ python -m executorch.examples.models.muse_glimmer.export.export_solo \
235+ --backend mlx \
236+ --gguf " $TARGET " \
237+ --use-offgraph-kv-cache \
238+ --activation-dtype float16 \
239+ --max-prefill-chunk 512 \
240+ --output-dir /path/to/exports/mg-offgraph
241+ ```
242+
243+ Or export the target and drafter for DFlash:
244+
245+ ``` bash
246+ python -m executorch.examples.models.muse_glimmer.export.export_dflash \
247+ --backend mlx \
248+ --target-gguf " $TARGET " \
249+ --draft-gguf " $DRAFT " \
250+ --use-offgraph-kv-cache \
251+ --activation-dtype float16 \
252+ --output-dir /path/to/exports/mg-offgraph-dflash
253+ ```
254+
255+ For CUDA exports, use ` --backend cuda ` and ` --activation-dtype bfloat16 ` instead.
256+
257+ To enable image input, add ` --mmproj "$MMPROJ" ` to either export command above.
258+ This includes the vision encoder and writes its position-embedding data alongside
259+ the model. The resulting export can serve both text-only and image requests;
260+ a separate text-only export is not required.
261+
262+ The server's ` --max-context ` sets the per-session runtime limit and must not
263+ exceed the exported limit. Runtime cache allocation is separate from that limit.
264+ For MLX, off-graph exports use the checkpoint's native context limit rather than
265+ ` --max-seq-len ` , and KV storage grows as needed instead of allocating the full
266+ context up front.
267+
268+ ### Set up the batching runtime
269+
270+ After the general [ environment setup] ( #supported-backends ) , use the Make target
271+ for your backend to build and install ExecuTorch and build the batching runner
272+ and worker. For MLX:
273+
274+ ``` bash
275+ cd /path/to/executorch
276+ make muse-glimmer-batching-mlx
277+ pip install -r /path/to/executorch/examples/llm_server/python/requirements.txt
278+ ```
212279
213- ### Use from pi
280+ The Make target builds the native dependencies and both batching executables;
281+ it does not export a model or start the server. Use a batching build target,
282+ not a regular runner target.
283+
284+ ### Start the batching server
285+
286+ Replace the absolute example paths below with your checkout, export, and
287+ tokenizer locations. Select the backend matching the export and worker build.
288+ This MLX example uses four concurrent sessions, a 128K (131072-token) context
289+ limit, and up to 32 prefix snapshots:
290+
291+ ``` bash
292+ python -m executorch.examples.models.muse_glimmer.serving.serve_batching \
293+ --worker-bin /path/to/executorch/cmake-out/examples/models/muse-glimmer-batching/muse_glimmer_batching_worker \
294+ --model-path /path/to/exports/mg-offgraph/model.pte \
295+ --tokenizer-path /path/to/assets/hf/tokenizer.json \
296+ --hf-tokenizer /path/to/assets/hf \
297+ --backend mlx \
298+ --model-id muse-glimmer-30B \
299+ --max-context 131072 \
300+ --max-sessions 4 \
301+ --max-decode-sequences 4 \
302+ --max-inflight-requests 4 \
303+ --prefix-cache-entries 32 \
304+ --tool-parser atem \
305+ --host 127.0.0.1 \
306+ --port 8000
307+ ```
214308
215- Point pi at the server via ` ~/.pi/agent/models.json ` :
309+ For DFlash, use ` /path/to/exports/mg-offgraph-dflash/model.pte ` and add
310+ ` --dflash --dflash-n-draft 3 ` to the launch command. ` --dflash-n-draft ` is a
311+ runtime server option controlling the number of proposals per verification step
312+ (N). Set it when starting the server; changing N does not require re-exporting.
313+ N must be smaller than the exported drafter block size (D). Omitting the option,
314+ or setting it to zero, uses N = D - 1.
315+
316+ On CUDA, D is fixed at export time from the drafter checkpoint configuration and
317+ cannot be changed at runtime. The exporter currently has no separate block-size
318+ override option. To use a different D, export a new artifact with the corresponding
319+ drafter configuration. Changing N does not change D: a D = 16 export still
320+ evaluates 16 drafter rows per session when N = 3, and its default is N = 15.
321+
322+ Choose concurrency and prefix-cache limits to fit available memory. Prefix
323+ snapshots are disabled by default; omit ` --prefix-cache-entries ` to disable them.
324+ If the export stores weights separately, also pass ` --data-path ` with its data
325+ file.
326+
327+ For a vision-enabled export, add
328+ ` --pos-embed-path /path/to/exports/mg-offgraph/pos_embed.bin ` to the server command,
329+ using the matching export directory. Send images as OpenAI ` image_url ` content
330+ parts containing inline base64 JPEG or PNG data URLs. The batching server accepts
331+ one image across each submitted conversation; remote image URLs and local image
332+ paths are not supported.
333+
334+ The endpoint is ` http://127.0.0.1:8000/v1/chat/completions ` ; the smoke request in
335+ [ Serve] ( #serve ) and the [ Pi configuration] ( #use-from-pi ) below work with this
336+ server too. See the
337+ [ batching serving guide] ( BATCHING_SERVING.md ) for image support, session behavior,
338+ and detailed limits.
339+
340+ ## Use from Pi
341+
342+ This configuration works with both the regular server and the off-graph
343+ batching server. Batching and DFlash are server-side choices; Pi uses the same
344+ OpenAI-compatible endpoint for either path. Enable ` --tool-parser atem ` on the
345+ server for tool calling.
346+
347+ Point Pi at the server via ` /path/to/home/.pi/agent/models.json ` , replacing
348+ ` /path/to/home ` with your home directory:
216349
217350``` json
218351{
0 commit comments