[Bugfix][KV Offload] Emit self-describing CPU events at KV-group block granularity (#51614)

Signed-off-by: Ziqi Fan <ziqif@nvidia.com>
This commit is contained in:
Ziqi Fan
2026-08-12 20:28:15 -07:00
committed by GitHub
parent f9a0f629bd
commit 15227b934a
2 changed files with 59 additions and 16 deletions
@@ -81,13 +81,18 @@ def _group_config(
group_idx: int = 0,
block_size: int = 4,
blocks_per_chunk: int = 1,
tokens_per_hash: int | None = None,
sliding_window_size_in_chunks: int | None = None,
) -> GroupOffloadConfig:
if tokens_per_hash is None:
tokens_per_hash = block_size
tokens_per_chunk = block_size * blocks_per_chunk
assert tokens_per_chunk % tokens_per_hash == 0
return GroupOffloadConfig(
group_idx=group_idx,
tokens_per_block=block_size,
tokens_per_chunk=block_size * blocks_per_chunk,
hashes_per_chunk=blocks_per_chunk,
tokens_per_chunk=tokens_per_chunk,
hashes_per_chunk=tokens_per_chunk // tokens_per_hash,
sliding_window_size_in_chunks=sliding_window_size_in_chunks,
kv_event_group_spec=_FULL_ATTENTION_EVENT_SPEC,
)
@@ -334,6 +339,36 @@ def test_promotion_emits_full_cpu_stored_event():
assert event.kv_cache_spec_sliding_window is None
@pytest.mark.parametrize(
("blocks_per_chunk", "expected_hash_indices"),
[(1, [63]), (2, [63, 127])],
)
def test_event_hashes_use_group_block_size(
blocks_per_chunk: int, expected_hash_indices: list[int]
):
tokens_per_hash = 4
block_size = 256
hashes_per_block = block_size // tokens_per_hash
tracker = _tracker()
group_config = _group_config(
block_size=block_size,
blocks_per_chunk=blocks_per_chunk,
tokens_per_hash=tokens_per_hash,
)
req = _request(
block_hashes=[_hash(i) for i in range(hashes_per_block * blocks_per_chunk)],
token_count=block_size * blocks_per_chunk,
)
[key] = _record_chunks(tracker, req, group_config, num_chunks=1)
[event] = tracker.take_events([_stored_event([key])])
assert isinstance(event, BlockStored)
assert event.block_hashes == [_wire_hash(_hash(i)) for i in expected_hash_indices]
assert event.block_size == block_size
assert len(event.token_ids) == block_size * blocks_per_chunk
def test_lookup_promotion_factor_gt_1_store_and_remove():
block_size = 4
blocks_per_chunk = 2