sgl-project/sglang · error · NotImplementedError
protected_size() is not implemented; use full_protected_size
Error message
protected_size() is not implemented; use full_protected_size() and swa_protected_size() instead
What it means
Symmetric to evictable_size: SWARadixCache splits protected sizes into full and SWA domains, so protected_size() raises NotImplementedError by design. Use full_protected_size() and swa_protected_size().
Source
Thrown at python/sglang/srt/mem_cache/swa_radix_cache.py:865
node = node.parent
def sanity_check(self):
self.full_lru_list.sanity_check(self)
self.swa_lru_list.sanity_check(self)
def evictable_size(self) -> Tuple[int, int]:
# Note: use full_evictable_size() and swa_evictable_size() instead.
raise NotImplementedError
def full_evictable_size(self) -> int:
return self.full_evictable_size_
def swa_evictable_size(self) -> int:
return self.swa_evictable_size_
def protected_size(self) -> Tuple[int, int]:
# Note: use full_protected_size() and swa_protected_size() instead.
raise NotImplementedError
def full_protected_size(self) -> int:
# protected size refers to the size of the full cache that is locked
return self.full_protected_size_
def swa_protected_size(self) -> int:
# protected size refers to the size of the swa cache that is locked
return self.swa_protected_size_
def all_values_flatten(self) -> torch.Tensor:
values = []
def _dfs_helper(node: TreeNode):
for _, child in node.children.items():
values.append(child.value)
_dfs_helper(child)
_dfs_helper(self.root_node)View on GitHub (pinned to 0132848349)
Solutions
- Use full_protected_size() and swa_protected_size()
- Guard with hasattr/try when supporting both SWA and non-SWA caches
Example fix
# before prot = tree.protected_size() # after prot_full = tree.full_protected_size() prot_swa = tree.swa_protected_size()
Defensive patterns
Strategy: validation
Validate before calling
if hasattr(tree, 'swa_protected_size'):
prot = (tree.full_protected_size(), tree.swa_protected_size()) Type guard
def has_split_protected_sizes(tree) -> bool:
return hasattr(tree, 'full_protected_size') and hasattr(tree, 'swa_protected_size') Prevention
- Never call protected_size() unconditionally; feature-detect split accessors
- Write shared helpers returning (full, swa) tuples for SWA-aware caches
When it happens
Trigger: Calling protected_size() on SWARadixCache from generic cache accounting code.
Common situations: Scheduler/metrics code ported from the non-SWA RadixCache path that queries protected_size.
Related errors
- evictable_size() is not implemented; use full_evictable_size
- {self.__class__.__name__}.apply should not be called.
- Use get_key_buffer instead.
- Host cache is not supported yet
- SWA Radix tree sanity check failed, ping @hanming-lu: {e}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/d041f811511a0057.
Report an issue: GitHub.