From b4616dcbf54305fab69a0537ba481b7aa05a1418 Mon Sep 17 00:00:00 2001 From: mingyue300 Date: Wed, 15 Apr 2026 03:43:50 +0800 Subject: [PATCH] =?UTF-8?q?[BugFix]=20Fix=20EAGLE=20speculative=20decoding?= =?UTF-8?q?=20missing=20grammar-based=20finish=20=E2=80=A6=20(#21723)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/sglang/srt/speculative/eagle_info.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/sglang/srt/speculative/eagle_info.py b/python/sglang/srt/speculative/eagle_info.py index c1eee1298..a21f6b0ae 100644 --- a/python/sglang/srt/speculative/eagle_info.py +++ b/python/sglang/srt/speculative/eagle_info.py @@ -426,20 +426,20 @@ class EagleVerifyInput(SpecInput, EagleVerifyInputV2Mixin): if req.require_reasoning and think_end_id is not None: req.update_reasoning_tokens(id, think_end_id) req.check_finished() + if not req.finished() and req.grammar is not None: + try: + req.grammar.accept_token(id) + except ValueError as e: + logger.info( + f"{i=}, {req=}\n" f"{accept_index=}\n" f"{predict=}\n" + ) + raise e + req.check_finished() if req.finished(): has_finished = True # set all tokens after finished token to -1 and break accept_index[i, j + 1 :] = -1 break - else: - if req.grammar is not None: - try: - req.grammar.accept_token(id) - except ValueError as e: - logger.info( - f"{i=}, {req=}\n" f"{accept_index=}\n" f"{predict=}\n" - ) - raise e # Update KV cache tracking for the accepted tokens req.kv_committed_len += num_accepted req.kv_allocated_len = req.kv_committed_len