[MLX] C++ runner for HF LLMs with the off-graph KV cache - #21683
[MLX] C++ runner for HF LLMs with the off-graph KV cache#21683kiymetakdemir wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21683
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit fed3f79 with merge base 14326d9 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
Can you add something to the readme about this? |
|
@claude review this code |
|
Claude finished @metascroy's task in 6m 49s —— View job Code review — MLX C++ runner for off-graph KV cacheRead 1. Missing
|
| // Usage: | ||
| // run_llm_hf --pte <model.pte> --tokenizer <tokenizer.json> \ | ||
| // [--kv-max-capacity N] [--kv-storage-dtype bf16|fp16|fp32] \ | ||
| // [--kv-initial-capacity N] [--kv-max-write N] \ |
There was a problem hiding this comment.
Why is kv-max-write a param?
Isn't it deriable from prefill-chunk-size?
| } // namespace | ||
|
|
||
| int main(int argc, char** argv) { | ||
| const std::string pte = arg(argc, argv, "--pte", ""); |
| } | ||
|
|
||
| if (off_graph) { | ||
| cache::CacheConfig cfg{}; |
There was a problem hiding this comment.
It's just a demo, but can we extract some of this cache config construction from pte metadata into a helper?
Summary
This runner builds an MLXSequenceCache, installs it, and passes the cache key, so it's the run path for .pte files exported with --use-offgraph-cache. The cache's shape is read from the .pte metadata. The flags left are policy the model can't imply: --kv-max-capacity, --kv-storage-dtype, --kv-initial-capacity, --kv-max-write, --kv-windows.
Depends on #21680; the new CI job fails until that lands.
Files
Test
CI builds the runner, then for llama-1b, gemma3-1b and gemma4-e2b exports off-graph and asserts the same "Paris" answer test-mlx-llm checks.