Repository navigation
Recsys KVCache Manager refactored into standalone package - #387
Conversation
Greptile SummaryThis PR refactors the
Confidence Score: 4/5Safe to merge the core library; the test file has two bugs that will cause incorrect behaviour when batch_size > 1. The core recsys_kvcache_manager package and updated HSTU example modules look correct after many rounds of fixes. The two issues are confined to test_paged_hstu_layer.py: HostKVTaskHandle objects created without is_layerwise=True make stream_wait_layer a no-op, silently removing the CUDA-event barrier between the side-stream data copy and the default-stream attention kernel; and a stray no-op expression leaves the static metadata buffer sized for a single sequence rather than the full batch, causing an out-of-bounds write in copy_kvcache_metadata when max_batch_size > 1. examples/hstu/test/test_paged_hstu_layer.py — both HostKVTaskHandle constructions and the get_kvcache_metadata_buffer call for the static buffer need attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant KVCacheManager
participant GPUKVCacheManager
participant HostKVStorageManager
participant HSTUAttention
Caller->>KVCacheManager: lookup_kvcache(user_ids, seq_lengths)
KVCacheManager->>GPUKVCacheManager: lookup(user_ids)
KVCacheManager->>HostKVStorageManager: build_index_meta + lookup_kvcache
KVCacheManager-->>Caller: (index_meta, lookup_result)
Caller->>KVCacheManager: allocate_kvcache(index_meta, lookup_result)
KVCacheManager->>GPUKVCacheManager: allocate(...)
KVCacheManager-->>Caller: kvcache_metadata
Caller->>KVCacheManager: onboard_launch(index_meta, lookup_result, kvcache_metadata)
KVCacheManager->>HostKVStorageManager: onboard_kvcache_launch(...)
Note over HostKVStorageManager: Async host-to-GPU transfer begins
KVCacheManager-->>Caller: task_handle stored in kvcache_metadata.kv_onload_handle
Note over Caller: Overlap: embedding lookup
Caller->>HSTUAttention: forward(..., kvcache_metadata)
loop Per layer
HSTUAttention->>HSTUAttention: stream_wait_layer(layer_idx)
Note over HSTUAttention: Waits for layer KV data via CUDA event
HSTUAttention->>HSTUAttention: hstu_attn_varlen_func(kv_seqlen_offsets)
end
Caller->>KVCacheManager: offload_try_wait()
Caller->>KVCacheManager: offload_launch(index_meta, kvcache_metadata)
KVCacheManager->>HostKVStorageManager: offload_kvcache_launch(...)
Note over HostKVStorageManager: Async GPU-to-host transfer begins
Reviews (16): Last reviewed commit: "Add FlexKV as a third_party library" | Re-trigger Greptile |
96d6f42 to
54c9efc
Compare
e198f03 to
132b992
Compare
…turns ready, and add test_flexkv.py
e83fb8e to
4d390c8
Compare
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
AsyncKVCacheManagerinto standalone Recsys KVCache Manager package.Contains: