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
e205527c
Unverified
Commit
e205527c
authored
Aug 13, 2024
by
Liangsheng Yin
Committed by
GitHub
Aug 13, 2024
Browse files
Fix jump forward final state circular path bug. (#1084)
parent
0909bb0d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
python/sglang/srt/constrained/jump_forward.py
python/sglang/srt/constrained/jump_forward.py
+13
-2
No files found.
python/sglang/srt/constrained/jump_forward.py
View file @
e205527c
...
@@ -62,16 +62,22 @@ class JumpForwardMap:
...
@@ -62,16 +62,22 @@ class JumpForwardMap:
id_to_symbol
.
setdefault
(
id_
,
[]).
append
(
symbol
)
id_to_symbol
.
setdefault
(
id_
,
[]).
append
(
symbol
)
transitions
=
fsm_info
.
transitions
transitions
=
fsm_info
.
transitions
outgoings_ct
=
defaultdict
(
int
)
outgoings_ct
=
defaultdict
(
int
)
state_to_jump_forward
=
{}
# NOTE(lsyin): Final states can lead to terminate, so they have one outgoing edge naturally
for
s
in
fsm_info
.
finals
:
outgoings_ct
[
s
]
=
1
state_to_jump_forward
=
{}
for
(
state
,
id_
),
next_state
in
transitions
.
items
():
for
(
state
,
id_
),
next_state
in
transitions
.
items
():
if
id_
==
fsm_info
.
alphabet_anything_value
:
if
id_
==
fsm_info
.
alphabet_anything_value
:
# Arbitrarily symbol cannot be recognized as jump forward
continue
continue
symbols
=
id_to_symbol
[
id_
]
symbols
=
id_to_symbol
[
id_
]
for
c
in
symbols
:
for
c
in
symbols
:
if
len
(
c
)
>
1
:
if
len
(
c
)
>
1
:
# Skip byte level transitions
# Skip byte level transitions
like c = "5E"
continue
continue
outgoings_ct
[
state
]
+=
1
outgoings_ct
[
state
]
+=
1
...
@@ -87,6 +93,9 @@ class JumpForwardMap:
...
@@ -87,6 +93,9 @@ class JumpForwardMap:
# Process the byte level jump forward
# Process the byte level jump forward
outgoings_ct
=
defaultdict
(
int
)
outgoings_ct
=
defaultdict
(
int
)
for
s
in
fsm_info
.
finals
:
outgoings_ct
[
s
]
=
1
for
(
state
,
id_
),
next_state
in
transitions
.
items
():
for
(
state
,
id_
),
next_state
in
transitions
.
items
():
if
id_
==
fsm_info
.
alphabet_anything_value
:
if
id_
==
fsm_info
.
alphabet_anything_value
:
continue
continue
...
@@ -177,3 +186,5 @@ if __name__ == "__main__":
...
@@ -177,3 +186,5 @@ if __name__ == "__main__":
test_main
(
r
"霍格沃茨特快列车|霍比特人比尔博"
)
test_main
(
r
"霍格沃茨特快列车|霍比特人比尔博"
)
# 霍格: \xe9\x9c\x8d \xe6\xa0\xbc ...
# 霍格: \xe9\x9c\x8d \xe6\xa0\xbc ...
# 霍比: \xe9\x9c\x8d \xe6\xaf\x94 ...
# 霍比: \xe9\x9c\x8d \xe6\xaf\x94 ...
test_main
(
r
"[-+]?[0-9]+[ ]*"
)
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