diff --git a/python/sglang/srt/environ.py b/python/sglang/srt/environ.py index 4510e77d9c..415a16160b 100644 --- a/python/sglang/srt/environ.py +++ b/python/sglang/srt/environ.py @@ -633,6 +633,10 @@ class Envs: # size the KV pool after CUDA-graph capture SGLANG_ENABLE_POST_CAPTURE_KV_SIZING = EnvBool(False) + # DSv4.1 unified cache: allow a FULL prefix match even when the SWA component has + # no live value (the SWA window is rebuilt/recovered downstream). + SGLANG_DSV4_SWA_GATES_PREFIX_MATCH = EnvBool(True) + # =================================================================== # Scheduler token budgeting and admission # =================================================================== diff --git a/python/sglang/srt/mem_cache/kv_cache_builder.py b/python/sglang/srt/mem_cache/kv_cache_builder.py index 3df242ca90..bc44314303 100644 --- a/python/sglang/srt/mem_cache/kv_cache_builder.py +++ b/python/sglang/srt/mem_cache/kv_cache_builder.py @@ -352,7 +352,7 @@ def build_kv_cache( # SWA the tree does not own must not gate prefix matching: a per-request ring, # or paged SWA beside the target's encoder-replay request window, which then # only the draft uses. - swa_gates_prefix_match = not ( + swa_gates_prefix_match = envs.SGLANG_DSV4_SWA_GATES_PREFIX_MATCH.get() and not ( is_swa_req_ring(token_to_kv_pool_allocator) or ( isinstance(token_to_kv_pool, DeepSeekV4TokenToKVPool)