Merged
Conversation
Greptile OverviewGreptile SummaryThis PR implements HSTU KVCacheManager V2 with asynchronous operations, moving Python-based KV cache management to optimized C++ implementations with compression support. Key Changes
Issues Found
ArchitectureThe new design uses a producer-consumer pattern with three main threads: metadata preparation, onload worker, and offload worker. Each layer synchronizes independently using CUDA events and condition variables, allowing inference to proceed as soon as each layer's cache is ready. Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as Python Client
participant AsyncMgr as AsyncHSTUKVCacheManager
participant MetadataThread as Metadata Thread
participant OnloadThread as Onload Thread
participant GPUMgr as GPUKVCacheMangerImpl (C++)
participant OffloadThread as Offload Thread
participant HostStorage as HostKVStorageImpl (C++)
Client->>AsyncMgr: prepare_kvcache_async()
AsyncMgr->>MetadataThread: submit(prepare_kvcache)
AsyncMgr->>OnloadThread: submit(onload_kvcache)
AsyncMgr->>Client: return futures
par Parallel Execution
MetadataThread->>GPUMgr: prepare_kvcache()
GPUMgr->>GPUMgr: alloc pages
GPUMgr->>GPUMgr: create metadata
MetadataThread->>AsyncMgr: complete
and
OnloadThread->>HostStorage: get_kvdata()
OnloadThread->>GPUMgr: decompress + D2H transfer
OnloadThread->>GPUMgr: complete_host(layer_idx)
OnloadThread->>AsyncMgr: complete
end
Client->>AsyncMgr: prepare_kvcache_wait()
AsyncMgr->>MetadataThread: metadata_fut.result()
AsyncMgr->>Client: return KVCacheMetadata
Client->>Client: forward through layers
loop For each layer
Client->>GPUMgr: wait_host(layer_idx)
Note over GPUMgr: Wait for onload completion
Client->>Client: process layer with KV cache
Client->>GPUMgr: mark_ready(layer_idx)
end
Client->>AsyncMgr: offload_kvcache()
AsyncMgr->>GPUMgr: offload_kvcache()
GPUMgr->>OffloadThread: queue offload task
par Async Offload
loop For each layer
OffloadThread->>OffloadThread: wait for mark_ready()
OffloadThread->>GPUMgr: gather pages from GPU
OffloadThread->>GPUMgr: compress (if enabled)
OffloadThread->>HostStorage: append_kvdata()
end
end
|
17b117f to
ab48756
Compare
Collaborator
Author
shijieliu
reviewed
Feb 11, 2026
Collaborator
Author
|
CI passed. |
shijieliu
approved these changes
Feb 13, 2026
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.
Implement HSTU KVCacheManager V2: