Skip to content
Merged
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
4 changes: 4 additions & 0 deletions python/sglang/srt/mem_cache/chunk_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def __init__(
self.req_to_token_pool = req_to_token_pool
self.token_to_kv_pool_allocator = token_to_kv_pool_allocator
self.page_size = page_size
if self.token_to_kv_pool_allocator:
self.device = self.token_to_kv_pool_allocator.device
else:
self.device = torch.device("cpu")
Comment on lines +30 to +33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This logic implies that token_to_kv_pool_allocator can be None. However, the type hint in the __init__ signature (BaseTokenToKVPoolAllocator) suggests it's non-nullable. This is inconsistent.

If token_to_kv_pool_allocator can be None, then cache_finished_req will raise an AttributeError at line 59, as it accesses self.token_to_kv_pool_allocator.free(...) without a check. Please ensure all usages of token_to_kv_pool_allocator are safe if it can be None, and consider updating the type hint to Optional[BaseTokenToKVPoolAllocator].

If token_to_kv_pool_allocator is never None (as the type hint suggests), this conditional logic is unnecessary and can be simplified.

        self.device = self.token_to_kv_pool_allocator.device


# NOTE (csy): this is to determine if a cache has prefix matching feature.
# Chunk cache always return True to indicate no prefix matching.
Expand Down
Loading