[bug] Fix cache salt and extra keys for prefix cache isolation (#23300)
This commit is contained in:
@@ -613,7 +613,6 @@ class Scheduler(
|
|||||||
self.require_mlp_sync = require_mlp_sync(self.server_args)
|
self.require_mlp_sync = require_mlp_sync(self.server_args)
|
||||||
|
|
||||||
def init_tp_model_worker(self):
|
def init_tp_model_worker(self):
|
||||||
|
|
||||||
worker_kwargs = dict(
|
worker_kwargs = dict(
|
||||||
server_args=self.server_args,
|
server_args=self.server_args,
|
||||||
gpu_id=self.gpu_id,
|
gpu_id=self.gpu_id,
|
||||||
@@ -826,7 +825,6 @@ class Scheduler(
|
|||||||
|
|
||||||
self.tree_cache = SWAChunkCache(params)
|
self.tree_cache = SWAChunkCache(params)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if envs.SGLANG_EXPERIMENTAL_CPP_RADIX_TREE.get():
|
if envs.SGLANG_EXPERIMENTAL_CPP_RADIX_TREE.get():
|
||||||
# lazy import to avoid JIT overhead
|
# lazy import to avoid JIT overhead
|
||||||
from sglang.srt.mem_cache.radix_cache_cpp import RadixCacheCpp
|
from sglang.srt.mem_cache.radix_cache_cpp import RadixCacheCpp
|
||||||
@@ -1622,7 +1620,6 @@ class Scheduler(
|
|||||||
):
|
):
|
||||||
recv_reqs, abort_reqs = self.mm_receiver.process_waiting_requests(recv_reqs)
|
recv_reqs, abort_reqs = self.mm_receiver.process_waiting_requests(recv_reqs)
|
||||||
for req, error_msg, error_code in abort_reqs:
|
for req, error_msg, error_code in abort_reqs:
|
||||||
|
|
||||||
status_code = (
|
status_code = (
|
||||||
HTTPStatus.BAD_REQUEST
|
HTTPStatus.BAD_REQUEST
|
||||||
if error_code == 400
|
if error_code == 400
|
||||||
@@ -1878,6 +1875,7 @@ class Scheduler(
|
|||||||
self.metrics_collector if self.enable_metrics else None
|
self.metrics_collector if self.enable_metrics else None
|
||||||
),
|
),
|
||||||
routing_key=recv_req.routing_key,
|
routing_key=recv_req.routing_key,
|
||||||
|
extra_key=recv_req.extra_key,
|
||||||
http_worker_ipc=recv_req.http_worker_ipc,
|
http_worker_ipc=recv_req.http_worker_ipc,
|
||||||
dllm_config=self.dllm_config,
|
dllm_config=self.dllm_config,
|
||||||
time_stats=recv_req.time_stats,
|
time_stats=recv_req.time_stats,
|
||||||
|
|||||||
@@ -235,6 +235,7 @@ class Session:
|
|||||||
return_routed_experts=req.return_routed_experts,
|
return_routed_experts=req.return_routed_experts,
|
||||||
priority=req.priority,
|
priority=req.priority,
|
||||||
routing_key=req.routing_key,
|
routing_key=req.routing_key,
|
||||||
|
extra_key=req.extra_key,
|
||||||
http_worker_ipc=req.http_worker_ipc,
|
http_worker_ipc=req.http_worker_ipc,
|
||||||
time_stats=req.time_stats,
|
time_stats=req.time_stats,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class TestCacheReport(CustomTestCase):
|
|||||||
timeout=300,
|
timeout=300,
|
||||||
other_args=[
|
other_args=[
|
||||||
"--chunked-prefill-size=40",
|
"--chunked-prefill-size=40",
|
||||||
|
"--attention-backend=triton",
|
||||||
"--enable-cache-report",
|
"--enable-cache-report",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -206,6 +207,14 @@ class TestCacheReport(CustomTestCase):
|
|||||||
|
|
||||||
# asyncio.run(run_test())
|
# asyncio.run(run_test())
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_cached_tokens(response) -> int:
|
||||||
|
"""Extract cached_tokens from response, returning 0 if prompt_tokens_details is None."""
|
||||||
|
details = response.usage.prompt_tokens_details
|
||||||
|
if details is None:
|
||||||
|
return 0
|
||||||
|
return int(details.cached_tokens)
|
||||||
|
|
||||||
def test_cache_salt_effectiveness(self):
|
def test_cache_salt_effectiveness(self):
|
||||||
print("=" * 100)
|
print("=" * 100)
|
||||||
print("Testing cache_salt effectiveness")
|
print("Testing cache_salt effectiveness")
|
||||||
@@ -221,7 +230,7 @@ class TestCacheReport(CustomTestCase):
|
|||||||
max_tokens=10,
|
max_tokens=10,
|
||||||
extra_body={"cache_salt": "salt1"},
|
extra_body={"cache_salt": "salt1"},
|
||||||
)
|
)
|
||||||
cached_tokens_1_first = int(response1.usage.prompt_tokens_details.cached_tokens)
|
cached_tokens_1_first = self._get_cached_tokens(response1)
|
||||||
prompt_tokens_1 = int(response1.usage.prompt_tokens)
|
prompt_tokens_1 = int(response1.usage.prompt_tokens)
|
||||||
print(
|
print(
|
||||||
f"First request with salt1 - cached_tokens: {cached_tokens_1_first}, prompt_tokens: {prompt_tokens_1}"
|
f"First request with salt1 - cached_tokens: {cached_tokens_1_first}, prompt_tokens: {prompt_tokens_1}"
|
||||||
@@ -235,9 +244,7 @@ class TestCacheReport(CustomTestCase):
|
|||||||
max_tokens=10,
|
max_tokens=10,
|
||||||
extra_body={"cache_salt": "salt1"},
|
extra_body={"cache_salt": "salt1"},
|
||||||
)
|
)
|
||||||
cached_tokens_1_second = int(
|
cached_tokens_1_second = self._get_cached_tokens(response2)
|
||||||
response2.usage.prompt_tokens_details.cached_tokens
|
|
||||||
)
|
|
||||||
print(
|
print(
|
||||||
f"Second request with salt1 - cached_tokens: {cached_tokens_1_second}, prompt_tokens: {prompt_tokens_1}"
|
f"Second request with salt1 - cached_tokens: {cached_tokens_1_second}, prompt_tokens: {prompt_tokens_1}"
|
||||||
)
|
)
|
||||||
@@ -258,7 +265,7 @@ class TestCacheReport(CustomTestCase):
|
|||||||
max_tokens=10,
|
max_tokens=10,
|
||||||
extra_body={"cache_salt": "salt2"},
|
extra_body={"cache_salt": "salt2"},
|
||||||
)
|
)
|
||||||
cached_tokens_2_first = int(response3.usage.prompt_tokens_details.cached_tokens)
|
cached_tokens_2_first = self._get_cached_tokens(response3)
|
||||||
print(f"First request with salt2 - cached_tokens: {cached_tokens_2_first}")
|
print(f"First request with salt2 - cached_tokens: {cached_tokens_2_first}")
|
||||||
|
|
||||||
# Verify no cache hit for different salt (should be similar to first request with salt1)
|
# Verify no cache hit for different salt (should be similar to first request with salt1)
|
||||||
@@ -274,14 +281,12 @@ class TestCacheReport(CustomTestCase):
|
|||||||
max_tokens=10,
|
max_tokens=10,
|
||||||
extra_body={"cache_salt": "salt2"},
|
extra_body={"cache_salt": "salt2"},
|
||||||
)
|
)
|
||||||
cached_tokens_2_second = int(
|
cached_tokens_2_second = self._get_cached_tokens(response4)
|
||||||
response4.usage.prompt_tokens_details.cached_tokens
|
|
||||||
)
|
|
||||||
print(f"Second request with salt2 - cached_tokens: {cached_tokens_2_second}")
|
print(f"Second request with salt2 - cached_tokens: {cached_tokens_2_second}")
|
||||||
|
|
||||||
# Verify cache hit for salt2
|
# Verify cache hit for salt2
|
||||||
assert (
|
assert (
|
||||||
cached_tokens_2_second == cached_tokens_2_first
|
cached_tokens_2_second > cached_tokens_2_first
|
||||||
), "Should have cache hit with same cache_salt for salt2"
|
), "Should have cache hit with same cache_salt for salt2"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user