[pd]: (Bug Fix) Incorrect out_cache_loc slicing in prepare_for_prebuilt (#24230)

Co-authored-by: Shangming Cai <csmthu@gmail.com>
This commit is contained in:
Zhangheng
2026-05-03 18:35:16 +08:00
committed by GitHub
co-authored by Shangming Cai
parent 2bfc5d3bb1
commit 44ca2d01fc
2 changed files with 37 additions and 2 deletions
@@ -42,9 +42,10 @@ class ScheduleBatchDisaggregationDecodeMixin:
offset = 0
for i, req in enumerate(reqs):
req_pool_indices.append(req.req_pool_idx)
pre_len = len(req.prefix_indices)
chunk = self.req_to_token_pool.req_to_token[req.req_pool_idx][
: req.extend_input_len
pre_len : pre_len + req.extend_input_len
]
assert (
offset + req.extend_input_len <= total_size
@@ -52,7 +53,6 @@ class ScheduleBatchDisaggregationDecodeMixin:
out_cache_loc[offset : offset + req.extend_input_len] = chunk
offset += req.extend_input_len
pre_len = len(req.prefix_indices)
seq_len = len(req.origin_input_ids) + max(0, len(req.output_ids) - 1)
seq_lens.append(seq_len)
if len(req.output_ids) == 0:
@@ -1,10 +1,12 @@
import time
import unittest
from types import SimpleNamespace
import requests
from sglang.test.ci.ci_register import register_cuda_ci
from sglang.test.kits.cache_hit_kit import run_multiturn_cache_hit_test
from sglang.test.run_eval import run_eval
from sglang.test.server_fixtures.disaggregation_fixture import (
PDDisaggregationServerBase,
)
@@ -78,6 +80,39 @@ class TestDisaggregationDecodeRadixCache(PDDisaggregationServerBase):
self._assert_process_healthy("prefill", self.process_prefill, self.prefill_url)
self._assert_process_healthy("decode", self.process_decode, self.decode_url)
def test_gsm8k_accuracy_two_passes(self):
"""Run GSM8K twice to verify decode radix cache does not degrade accuracy."""
args = SimpleNamespace(
base_url=self.base_url,
model=self.model,
eval_name="gsm8k",
api="completion",
max_tokens=512,
num_examples=500,
num_threads=100,
num_shots=6,
)
metrics_first = run_eval(args)
print(f"First run metrics: {metrics_first}")
metrics_second = run_eval(args)
print(f"Second run metrics: {metrics_second}")
# Both runs should have reasonable accuracy
self.assertGreater(metrics_first["score"], 0.80)
self.assertGreater(metrics_second["score"], 0.80)
# Second run accuracy should not drop more than 3% compared to first run
accuracy_drop = metrics_first["score"] - metrics_second["score"]
self.assertLessEqual(
accuracy_drop,
0.03,
f"Second run accuracy dropped by {accuracy_drop:.4f} "
f"(first={metrics_first['score']:.4f}, second={metrics_second['score']:.4f}), "
f"exceeds 3% threshold",
)
if __name__ == "__main__":
unittest.main()