diff --git a/python/sglang/srt/entrypoints/openai/serving_chat.py b/python/sglang/srt/entrypoints/openai/serving_chat.py index e2a0886c5d..157257a592 100644 --- a/python/sglang/srt/entrypoints/openai/serving_chat.py +++ b/python/sglang/srt/entrypoints/openai/serving_chat.py @@ -1178,12 +1178,26 @@ class OpenAIServingChat(OpenAIServingBase): content={"error": "multimodal requests are not supported by /query_cache_hit"}, ) try: - tokenized = await self.tokenizer_manager._tokenize_one_request(internal_req) + # 只取 input_ids,不走 _tokenize_one_request——它要求 rid_to_state + # 里已有 ReqState(正常生成路径在 tokenize 前注册),纯查询没有。 + # dsv41 系 chat encoding 直接渲染 prompt_ids;否则对渲染后的 + # text 走 tokenizer(_tokenize_texts 与真实路径同一入口)。 + if internal_req.input_ids is not None: + input_ids = list(internal_req.input_ids) + elif internal_req.text: + input_ids, _ = await self.tokenizer_manager._tokenize_texts( + internal_req.text, False + ) + else: + return ORJSONResponse( + status_code=400, + content={"error": "request produced neither input_ids nor text"}, + ) from sglang.srt.managers.io_struct import QueryCacheHitReqInput result = await self.tokenizer_manager.query_cache_hit( QueryCacheHitReqInput( - input_ids=list(tokenized.input_ids), + input_ids=list(input_ids), extra_key=getattr(internal_req, "extra_key", None), cache_salt=getattr(internal_req, "cache_salt", None), )