feat(M87): Automatic KV Cache Export from vLLM#187
Merged
Conversation
Add capture_kv module with: - CaptureConfig, CaptureResult, LayerCapture dataclasses - vLLM KV cache capture (mock mode for testing) - TP shard reconstruction via reconstruct_tp_shards() - save/load .npz with layer/head/position metadata - capture-kv CLI subcommand with --url, --prompt, --output, --layers, --capture-points, --tp-size, --max-tokens, --mock, --json flags - 26 tests covering config validation, capture logic, shard reconstruction, npz round-trip, layer filtering, mock capture, CLI integration Closes #186
hlin99-Review-Bot
approved these changes
Apr 6, 2026
hlin99-Review-Bot
left a comment
There was a problem hiding this comment.
✅ Approved by hlin99-Review-Bot
Idea Value: Good — KV cache export is a natural complement to the existing check-kv command, and the mock-first approach is pragmatic given vLLM version-specific hooks.
Code Quality:
- Clean dataclass design (CaptureConfig, CaptureResult, LayerCapture)
- TP shard reconstruction with proper shape validation
- npz round-trip with metadata — compatible with existing format
- 26 tests covering config validation, capture, shard reconstruction, I/O, CLI
- CI all green (lint + tests on 3.10/3.11/3.12)
docs/iterations/current.mdupdated
No issues found. LGTM.
hlin99-Review-BotX
approved these changes
Apr 6, 2026
hlin99-Review-BotX
left a comment
There was a problem hiding this comment.
✅ Approved by hlin99-Review-BotX
Idea Value: Good — KV cache export is a natural extension of the existing check-kv workflow. Mock-first approach is pragmatic.
Code Quality:
- Clean dataclass design with proper validation
- TP shard reconstruction with shape validation before concat
- npz round-trip compatible with existing format
- 26 comprehensive tests
- CI all green (lint + tests 3.10/3.11/3.12)
docs/iterations/current.mdupdated
Second approval — should trigger auto-merge. LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
capture-kvCLI command andcapture_kvmodule for automatic KV cache extraction from vLLM endpoints.What's included:
CaptureConfig: validated configuration (url, prompt, layers, capture points, TP size)CaptureResult/LayerCapture: structured result with serializationreconstruct_tp_shards(): reconstruct full tensors from TP-sharded arrayssave_capture()/load_capture(): .npz round-trip with metadatacapture_kv_mock(): mock capture for testing without a live vLLM instancecapture-kv:--url,--prompt,--output,--layers,--capture-points,--tp-size,--max-tokens,--mock,--jsonDesign decisions:
.npzformat compatible withcheck-kvcommandCloses #186