From f68e82e7bc9b85ba076f07d886636c0d1a50adec Mon Sep 17 00:00:00 2001 From: Krishnan Prashanth <140860868+KrishnanPrash@users.noreply.github.com> Date: Wed, 21 Oct 2026 23:45:38 -0700 Subject: [PATCH] [Fix] epd: Accept tokens-in requests on scheduler-side transfer backends (#41376) Signed-off-by: Krishnan Prashanth Co-authored-by: Shangming Cai Co-authored-by: Claude Opus 5.5 --- .../srt/disaggregation/encoder/receiver.py | 9 ++++-- .../disaggregation/test_encode_receiver.py | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/registered/unit/disaggregation/test_encode_receiver.py diff --git a/python/sglang/srt/disaggregation/encoder/receiver.py b/python/sglang/srt/disaggregation/encoder/receiver.py index 535bdbcf55..4a20ff6ed3 100644 --- a/python/sglang/srt/disaggregation/encoder/receiver.py +++ b/python/sglang/srt/disaggregation/encoder/receiver.py @@ -787,9 +787,12 @@ class WaitingMMRequestStatus(IntEnum): def _select_mm_processor_prompt(recv_req, mm_processor): """Mirror tokenizer-side prompt selection for scheduler-side EPD rebuilds.""" - if mm_processor.prefer_tokenized_input and recv_req.input_ids is not None: - return list(recv_req.input_ids) - return recv_req.input_text or recv_req.input_ids + # The scheduler holds input_ids as array("q"); processors accept str or + # list[int], not array. + input_ids = None if recv_req.input_ids is None else list(recv_req.input_ids) + if mm_processor.prefer_tokenized_input and input_ids is not None: + return input_ids + return recv_req.input_text or input_ids def create_part_req_id(original_req_id: str, part_idx: int) -> str: diff --git a/test/registered/unit/disaggregation/test_encode_receiver.py b/test/registered/unit/disaggregation/test_encode_receiver.py new file mode 100644 index 0000000000..04100ade23 --- /dev/null +++ b/test/registered/unit/disaggregation/test_encode_receiver.py @@ -0,0 +1,32 @@ +"""Unit tests for the encode-disaggregation receiver.""" + +import unittest +from array import array +from types import SimpleNamespace + +from sglang.srt.disaggregation.encoder.receiver import _select_mm_processor_prompt +from sglang.test.ci.ci_register import register_cpu_ci +from sglang.test.test_utils import CustomTestCase + +register_cpu_ci(est_time=5, suite="base-a-test-cpu") + + +class TestSelectMMProcessorPrompt(CustomTestCase): + def test_tokens_in_prompt_is_list(self): + """A tokens-in prompt reaches the processor as list[int], not array("q"); + HTTP sends input_text=None and the gRPC servicer sends "".""" + processor = SimpleNamespace(prefer_tokenized_input=False) + for input_text in (None, ""): + with self.subTest(input_text=input_text): + recv_req = SimpleNamespace( + input_text=input_text, input_ids=array("q", [1, 2, 3]) + ) + + prompt = _select_mm_processor_prompt(recv_req, processor) + + self.assertIsInstance(prompt, list) + self.assertEqual(prompt, [1, 2, 3]) + + +if __name__ == "__main__": + unittest.main()