[Bugfix] get_num_blocks_to_allocate with null_block (#19031)
Signed-off-by: Chen Zhang <zhangch99@outlook.com>
This commit is contained in:
@@ -144,3 +144,26 @@ def test_sliding_window_remove_skipped_blocks():
|
||||
# of removed blocks should be [1003, 1002].
|
||||
manager.remove_skipped_blocks("test", 11)
|
||||
assert_block_id(block_table, [null_block_id] * 4 + original_block_ids[4:])
|
||||
|
||||
|
||||
def test_get_num_blocks_to_allocate():
|
||||
block_size = 2
|
||||
sliding_window_spec = SlidingWindowSpec(
|
||||
block_size=block_size,
|
||||
num_kv_heads=1,
|
||||
head_size=1,
|
||||
dtype=torch.float32,
|
||||
sliding_window=4, # Placeholder value, not related to test result
|
||||
use_mla=False,
|
||||
)
|
||||
|
||||
block_pool = BlockPool(num_gpu_blocks=100, enable_caching=True)
|
||||
manager = get_sliding_window_manager(sliding_window_spec, block_pool)
|
||||
cached_blocks_1 = [KVCacheBlock(i + 1) for i in range(10)]
|
||||
cached_blocks_2 = [block_pool.null_block for _ in range(5)
|
||||
] + [KVCacheBlock(i + 1) for i in range(5)]
|
||||
|
||||
assert manager.get_num_blocks_to_allocate("1", 20 * block_size,
|
||||
cached_blocks_1) == 20
|
||||
assert manager.get_num_blocks_to_allocate("2", 20 * block_size,
|
||||
cached_blocks_2) == 15
|
||||
|
||||
Reference in New Issue
Block a user