env: add SGLANG_RADIX_FORCE_MISS to force radix prefix-cache miss (#24726)

Co-authored-by: sihan-zzz <228612289+sihan-zzz@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cheng Wan
2026-05-08 17:46:38 -07:00
committed by GitHub
co-authored by sihan-zzz Claude Opus 4.7
parent 560829a171
commit d1c5937428
5 changed files with 133 additions and 1 deletions
+1
View File
@@ -254,6 +254,7 @@ class Envs:
SGLANG_DISABLE_CONSECUTIVE_PREFILL_OVERLAP = EnvBool(False)
SGLANG_SCHEDULER_MAX_RECV_PER_POLL = EnvInt(-1)
SGLANG_EXPERIMENTAL_CPP_RADIX_TREE = EnvBool(False)
SGLANG_RADIX_FORCE_MISS = EnvBool(False)
SGLANG_DYNAMIC_CHUNKING_SMOOTH_FACTOR = EnvFloat(0.75)
SGLANG_SCHEDULER_SKIP_ALL_GATHER = EnvBool(False)
SGLANG_SCHEDULER_DECREASE_PREFILL_IDLE = EnvBool(False)
+7 -1
View File
@@ -61,7 +61,11 @@ from sglang.srt.environ import envs
from sglang.srt.layers.attention.fla.chunk_delta_h import CHUNK_SIZE as FLA_CHUNK_SIZE
from sglang.srt.managers.embed_types import PositionalEmbeds
from sglang.srt.mem_cache.allocator import BaseTokenToKVPoolAllocator
from sglang.srt.mem_cache.base_prefix_cache import BasePrefixCache, MatchPrefixParams
from sglang.srt.mem_cache.base_prefix_cache import (
BasePrefixCache,
MatchPrefixParams,
zero_match_result,
)
from sglang.srt.mem_cache.common import (
alloc_for_decode,
alloc_for_extend,
@@ -1029,6 +1033,8 @@ class Req(ReqDllmMixin):
cow_mamba=cow_mamba,
)
)
if envs.SGLANG_RADIX_FORCE_MISS.get():
match_result = zero_match_result(tree_cache, match_result)
(
self.prefix_indices,
self.last_node,
@@ -2,6 +2,7 @@ from __future__ import annotations
import logging
from sglang.srt.environ import envs
from sglang.srt.managers.prefill_delayer import PrefillDelayerSinglePassExecutor
from sglang.srt.mem_cache.base_prefix_cache import DecLockRefParams
from sglang.srt.utils import get_bool_env_var
@@ -42,6 +43,7 @@ from sglang.srt.mem_cache.base_prefix_cache import (
InitLoadBackParams,
InsertParams,
MatchPrefixParams,
zero_match_result,
)
from sglang.srt.mem_cache.hisparse_memory_pool import (
DeepSeekV4HiSparseTokenToKVPoolAllocator,
@@ -98,6 +100,8 @@ def match_prefix_for_req(
req=req if include_req else None,
)
)
if envs.SGLANG_RADIX_FORCE_MISS.get():
match_result = zero_match_result(tree_cache, match_result)
(
req.prefix_indices,
req.last_node,
@@ -249,6 +253,10 @@ class SchedulePolicy:
key=RadixKey(token_ids=prefix_ids, extra_key=extra_key)
)
)
if envs.SGLANG_RADIX_FORCE_MISS.get():
match_result = zero_match_result(
self.waiting_queue_radix_tree, match_result
)
in_batch_matching_prefixes = match_result.device_indices
if (
len(in_batch_matching_prefixes)
@@ -151,6 +151,24 @@ class MatchResult(NamedTuple):
cache_protected_len: Optional[int] = None
def zero_match_result(tree_cache, match_result: "MatchResult") -> "MatchResult":
root = getattr(tree_cache, "root_node", None)
if root is None:
raise RuntimeError(
f"SGLANG_RADIX_FORCE_MISS is not supported by {type(tree_cache).__name__} "
"(no `root_node` attribute). Disable the flag or use a cache backend "
"that exposes a tree root."
)
return match_result._replace(
# [:0] keeps dtype and device of the original tensor (e.g. CUDA int64)
# without allocating a fresh empty tensor.
device_indices=match_result.device_indices[:0],
last_device_node=root,
last_host_node=root,
host_hit_length=0,
)
class BasePrefixCache(ABC, PrefixCacheTrait):
"""Cache can be indexed by either rid or key."""