Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
64e78bb3
"csrc/cuda/radius.cpp" did not exist on "0044fc972c2d2fe546cbf8ce0f0cb0c512ca2058"
Unverified
Commit
64e78bb3
authored
Jul 15, 2025
by
ehuaa
Committed by
GitHub
Jul 15, 2025
Browse files
prevent server crash from potential invalid grammar (#7897)
parent
7c39e8a1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
python/sglang/srt/managers/scheduler_output_processor_mixin.py
...n/sglang/srt/managers/scheduler_output_processor_mixin.py
+21
-3
No files found.
python/sglang/srt/managers/scheduler_output_processor_mixin.py
View file @
64e78bb3
...
...
@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, List, Optional, Tuple, Union
from
sglang.srt.disaggregation.utils
import
DisaggregationMode
from
sglang.srt.layers.logits_processor
import
LogitsProcessorOutput
from
sglang.srt.managers.io_struct
import
BatchEmbeddingOut
,
BatchTokenIDOut
from
sglang.srt.managers.io_struct
import
AbortReq
,
BatchEmbeddingOut
,
BatchTokenIDOut
from
sglang.srt.managers.schedule_batch
import
BaseFinishReason
,
Req
,
ScheduleBatch
if
TYPE_CHECKING
:
...
...
@@ -126,7 +126,16 @@ class SchedulerOutputProcessorMixin:
)
if
req
.
grammar
is
not
None
:
# FIXME: this try-except block is for handling unexpected xgrammar issue.
try
:
req
.
grammar
.
accept_token
(
next_token_id
)
except
ValueError
as
e
:
# Grammar accept_token can raise ValueError if the token is not in the grammar.
# This can happen if the grammar is not set correctly or the token is invalid.
logger
.
error
(
f
"Grammar accept_token failed for req
{
req
.
rid
}
with token
{
next_token_id
}
:
{
e
}
"
)
self
.
abort_request
(
AbortReq
(
req
.
rid
))
req
.
grammar
.
finished
=
req
.
finished
()
else
:
# being chunked reqs' prefill is not finished
...
...
@@ -263,7 +272,16 @@ class SchedulerOutputProcessorMixin:
)
if
req
.
grammar
is
not
None
and
batch
.
spec_algorithm
.
is_none
():
# FIXME: this try-except block is for handling unexpected xgrammar issue.
try
:
req
.
grammar
.
accept_token
(
next_token_id
)
except
ValueError
as
e
:
# Grammar accept_token can raise ValueError if the token is not in the grammar.
# This can happen if the grammar is not set correctly or the token is invalid.
logger
.
error
(
f
"Grammar accept_token failed for req
{
req
.
rid
}
with token
{
next_token_id
}
:
{
e
}
"
)
self
.
abort_request
(
AbortReq
(
req
.
rid
))
req
.
grammar
.
finished
=
req
.
finished
()
self
.
set_next_batch_sampling_info_done
(
batch
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment