Repository navigation
[executorch][native-ggml] Store off-graph KV as Q4_1, packed or emulated - #26081
digantdesai wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/26081
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 3 PendingAs of commit b885cc2 with merge base 4ce60cb ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review |
|
Claude finished @Gasoonjia's task in 3m 14s —— View job Summary: There are no CPU correctness bugs. The main concerns are that Detailed reviewPR Review: #26081SummaryThe PR adds per-layer KV storage types to Two problems need attention:
Several test gaps make packed-path regressions hard to catch. All 7 changed files were reviewed. API Design
Infrastructure
Testing
Code Quality
RecommendationNeeds Discussion. Before landing, settle the |
GgmlKvPool now takes one storage type per layer. With kv_quant_impl = auto a Q4_1 layer stores its blocks: set_rows quantizes rows once, and flash attention reads the blocks directly on a GPU and on the CPU below its tiled kernel's 64 query rows, converting them to F32 otherwise. With kv_quant_impl = emulated, rows are rounded through Q4_1 and stored in kv_dtype. Q4_GS32_ZPF16 is refused at cache creation. This gives the ggml engine an opt-in compressed KV cache for full-attention layers, matching the reference codec, with floating storage unchanged. Authored with assistance from Claude and Codex. ghstack-source-id: 453b2f8 ghstack-comment-id: 7422958303 Pull-Request: #26081
There was a problem hiding this comment.
🟡 Changes recommended
Tests do not cover preservation of populated Q4_1 storage across cache growth or GPU-suite validation of packed attention and emulated casts.
2 open issues
What changed in this PR
Adds opt-in, per-layer Q4_1 KV-cache storage to the native ggml backend while preserving floating storage.
Changes:
- Supports packed Q4_1 and emulated quantization.
- Converts packed caches to F32 when required by the attention mode.
- Adds codec-reference accuracy tests and rejection tests for unsupported storage.
| File | Description |
|---|---|
| backends/native/test/runtime/ggml/test_ggml_engine.cpp | Adds quantized-cache and codec compatibility tests. |
| backends/native/runtime/engine/ggml/GgmlLowerAttention.cpp | Implements quantized writes and attention conversions. |
| backends/native/runtime/engine/ggml/GgmlGraphBuilder.h | Adds emulation metadata to cache bindings. |
| backends/native/runtime/engine/ggml/GgmlExecutor.cpp | Forwards per-layer emulation settings. |
| backends/native/runtime/engine/ggml/GgmlEngine.h | Documents quantized-cache option behavior. |
| backends/native/runtime/engine/ggml/GgmlCache.h | Defines per-layer storage types. |
| backends/native/runtime/engine/ggml/GgmlCache.cpp | Selects, validates, and allocates layer storage. |
Review effort: Balanced
| *t = ggml_new_tensor_3d( | ||
| next->context.get(), | ||
| type_, | ||
| types_[i].storage, |
| kind, | ||
| {kv::KVStorage::Q4_1}, | ||
| c.impl); | ||
| auto host = GgmlEngineHost::create(c.options); |

GgmlKvPool now takes one storage type per layer. With kv_quant_impl = auto a
Q4_1 layer stores its blocks: set_rows quantizes rows once, and flash
attention reads the blocks directly on a GPU and on the CPU below its tiled
kernel's 64 query rows, converting them to F32 otherwise. With
kv_quant_impl = emulated, rows are rounded through Q4_1 and stored in
kv_dtype. Q4_GS32_ZPF16 is refused at cache creation.
This gives the ggml engine an opt-in compressed KV cache for full-attention
layers, matching the reference codec, with floating storage unchanged.
Authored with assistance from Claude and Codex.