cherry-pick 上游 #42716(运行时部分):encoder SWA bounded replay 下放行 host 层前缀命中——request_window 形态的 SWA 不进树,校验门不应拦截 host-only 节点;rust adapter/test 两处 hunk 与本树结构不符未合(默认 python 树芯用不到)
build-sglang-image / build (push) Failing after 1s

This commit is contained in:
2026-10-10 01:02:33 +08:00
parent 2b2ede8211
commit 99c317b131
2 changed files with 17 additions and 5 deletions
@@ -866,3 +866,15 @@ class PureSWATokenToKVPoolAllocator(SWATokenToKVPoolAllocator):
def is_swa_req_ring(allocator) -> bool:
return isinstance(allocator, SWATokenToKVPoolAllocator) and allocator.swa_req_ring
def swa_kept_out_of_tree(allocator) -> bool:
"""Whether radix-tree nodes do not own the SWA state: a per-request SWA ring,
or the DeepSeek-V4.1 encoder-replay request window, which replay rebuilds on a
prefix hit. SWA bookkeeping must not gate prefix matching for either."""
if not isinstance(allocator, SWATokenToKVPoolAllocator):
return False
if allocator.swa_req_ring:
return True
kvcache = getattr(allocator, "_kvcache", None)
return getattr(kvcache, "request_window", None) is not None
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Callable, Optional, Sequence
import torch
from sglang.srt.environ import envs
from sglang.srt.mem_cache.allocator.swa import is_swa_req_ring
from sglang.srt.mem_cache.allocator.swa import swa_kept_out_of_tree
from sglang.srt.mem_cache.base_prefix_cache import (
DecLockRefParams,
EvictParams,
@@ -323,9 +323,9 @@ class SWAComponent(TreeComponent):
ct = self.component_type
state = {"len": float("inf")}
# A per-request SWA ring is not stored in tree nodes, so its bookkeeping
# must not gate prefix matching.
swa_req_ring = is_swa_req_ring(self.cache.token_to_kv_pool_allocator)
# SWA state that tree nodes do not own (a per-request ring, or a request
# window rebuilt by replay) must not gate prefix matching.
swa_out_of_tree = swa_kept_out_of_tree(self.cache.token_to_kv_pool_allocator)
def validator(node: UnifiedTreeNode) -> bool:
cd = node.component_data[ct]
@@ -333,7 +333,7 @@ class SWAComponent(TreeComponent):
# — load_back will restore SWA from host before use.
if cd.value is None and (match_device_only or cd.host_value is None):
state["len"] = 0
if swa_req_ring and (node.backuped or not node.evicted):
if swa_out_of_tree and (node.backuped or not node.evicted):
return True
return False
state["len"] += len(node.key)