diff --git a/python/sglang/srt/managers/schedule_batch.py b/python/sglang/srt/managers/schedule_batch.py index d625f9047..2ff3b406d 100644 --- a/python/sglang/srt/managers/schedule_batch.py +++ b/python/sglang/srt/managers/schedule_batch.py @@ -1121,6 +1121,14 @@ class Req(ReqDllmMixin): self.extend_batch_idx = 0 self.decode_batch_idx = 0 + # When using input_embeds, we cannot easily mix the original input embeddings + # with the newly generated output token IDs during re-prefill of retracted request. + # output_ids will have no use, but will lead to wrong size cache indexes. + # Therefore, we discard the generated output_ids and restart prefill and generation + # to ensure shape consistency in KV cache. + if self.input_embeds is not None: + self.output_ids = [] + def offload_kv_cache(self, req_to_token_pool, token_to_kv_pool_allocator): token_indices = req_to_token_pool.req_to_token[ self.req_pool_idx, : self.seqlen - 1