88from vllm .v1 .kv_cache_interface import SlidingWindowSpec
99
1010
11+ def get_sliding_window_manager (sliding_window_spec , block_pool ):
12+ return SlidingWindowManager (sliding_window_spec ,
13+ block_pool ,
14+ use_eagle = False ,
15+ num_kv_cache_groups = 1 ,
16+ caching_hash_fn = lambda x : x )
17+
18+
1119def test_sliding_window_possible_cached_prefix ():
1220 sliding_window_spec = SlidingWindowSpec (
1321 block_size = 2 ,
@@ -19,9 +27,7 @@ def test_sliding_window_possible_cached_prefix():
1927 )
2028
2129 block_pool = BlockPool (num_gpu_blocks = 100 , enable_caching = True )
22- manager = SlidingWindowManager (sliding_window_spec ,
23- block_pool ,
24- use_eagle = False )
30+ manager = get_sliding_window_manager (sliding_window_spec , block_pool )
2531
2632 def run_one_case (block_is_cached , expect_length ):
2733 block_hash_list = [
@@ -81,9 +87,7 @@ def test_sliding_window_remove_skipped_blocks():
8187
8288 block_pool = BlockPool (num_gpu_blocks = 2000 , enable_caching = True )
8389
84- manager = SlidingWindowManager (sliding_window_spec ,
85- block_pool ,
86- use_eagle = False )
90+ manager = get_sliding_window_manager (sliding_window_spec , block_pool )
8791
8892 null_block_id = block_pool .null_block .block_id
8993
@@ -104,39 +108,35 @@ def assert_block_id(block_table, ids):
104108 1000 , 1001 , 1002 , 1003 , 1004 , 1005 , 1006 , 1007 , 1008 , 1009 , 1010
105109 ]
106110 block_table = id_to_block_table (original_block_ids )
107- removed = manager .remove_skipped_blocks (block_table , 0 )
108- assert_block_id (removed , [])
111+ manager .req_to_blocks ["test" ] = block_table
112+
113+ manager .remove_skipped_blocks ("test" , 0 )
109114 assert_block_id (block_table , original_block_ids )
110115
111116 # 4 tokens are computed. Only token 0 is out of the sliding window. As
112117 # block 1000 also contains token 1 that is in the sliding window, block 1000
113118 # cannot be removed.
114- removed = manager .remove_skipped_blocks (block_table , 4 )
115- assert_block_id (removed , [])
119+ manager .remove_skipped_blocks ("test" , 4 )
116120 assert_block_id (block_table , original_block_ids )
117121
118122 # 5 tokens are computed. Token 0 & 1 are out of the sliding window.
119123 # Block 1000 can be removed.
120- removed = manager .remove_skipped_blocks (block_table , 5 )
121- assert_block_id (removed , [original_block_ids [0 ]])
124+ manager .remove_skipped_blocks ("test" , 5 )
122125 assert_block_id (block_table , [null_block_id ] + original_block_ids [1 :])
123126
124127 # 6 tokens are computed. Token 0-2 are out of the sliding window.
125128 # Cannot remove new block as the block 1001 is still used by token 3.
126- removed = manager .remove_skipped_blocks (block_table , 6 )
127- assert_block_id (removed , [])
129+ manager .remove_skipped_blocks ("test" , 6 )
128130 assert_block_id (block_table , [null_block_id ] + original_block_ids [1 :])
129131
130132 # 7 tokens are computed. Token 0-3 are out of the sliding window.
131133 # Block 1001 can be removed and block 1000 is already removed.
132- removed = manager .remove_skipped_blocks (block_table , 7 )
133- assert_block_id (removed , [original_block_ids [1 ]])
134+ manager .remove_skipped_blocks ("test" , 7 )
134135 assert_block_id (block_table , [null_block_id ] * 2 + original_block_ids [2 :])
135136
136137 # 11 tokens are computed. Token 0-7 are out of the sliding window.
137138 # Block 1002 & 1003 can be removed now. Block 1003 represents a longer
138139 # sequence, and is expected to be evicted earlier than 1002, so the order
139140 # of removed blocks should be [1003, 1002].
140- removed = manager .remove_skipped_blocks (block_table , 11 )
141- assert_block_id (removed , [original_block_ids [3 ], original_block_ids [2 ]])
141+ manager .remove_skipped_blocks ("test" , 11 )
142142 assert_block_id (block_table , [null_block_id ] * 4 + original_block_ids [4 :])
0 commit comments