Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vllm_ascend/core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def _check_watermark_for_prefill(self,
self.block_size)
req_blocks = self.kv_cache_manager.coordinator.get_blocks(
request.request_id)
num_new_blocks = (num_required_blocks - len(req_blocks) -
num_new_blocks = (num_required_blocks - len(req_blocks[0]) -
len(computed_blocks))
Comment on lines 445 to 448
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The change from len(req_blocks) to len(req_blocks[0]) is conceptually correct for getting the number of allocated blocks. However, the current implementation is not robust and can lead to runtime errors:

  1. self.kv_cache_manager.coordinator.get_blocks(request.request_id) will raise a KeyError if a request has no blocks allocated yet, which is the case for new requests from the waiting queue.
  2. If get_blocks were to return an empty list for a new request, req_blocks[0] would then raise an IndexError.

This can cause the scheduler to crash. The implementation should be updated to handle these cases gracefully.

        req_blocks = self.kv_cache_manager.coordinator.req_to_blocks.get(
            request.request_id, [])
        num_allocated_blocks = len(req_blocks[0]) if req_blocks else 0
        num_new_blocks = (num_required_blocks - num_allocated_blocks -
                          len(computed_blocks))

num_evictable_computed_blocks = sum(1 for blk in computed_blocks
if blk.ref_cnt == 0)
Expand Down
Loading