Skip to content

Commit

Permalink
Merge branch 'dev/onevision' of https://github.com/EvolvingLMMs-Lab/s…
Browse files Browse the repository at this point in the history
…glang into dev/onevision
  • Loading branch information
kcz358 committed Aug 14, 2024
2 parents 4348171 + 0b59e8c commit 21785a9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions python/sglang/srt/constrained/jump_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,22 @@ def _init_state_to_jump_forward(regex_string):
id_to_symbol.setdefault(id_, []).append(symbol)

transitions = fsm_info.transitions

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():
if id_ == fsm_info.alphabet_anything_value:
# Arbitrarily symbol cannot be recognized as jump forward
continue

symbols = id_to_symbol[id_]
for c in symbols:
if len(c) > 1:
# Skip byte level transitions
# Skip byte level transitions like c = "5E"
continue

outgoings_ct[state] += 1
Expand All @@ -87,6 +93,9 @@ def _init_state_to_jump_forward(regex_string):

# Process the byte level jump forward
outgoings_ct = defaultdict(int)
for s in fsm_info.finals:
outgoings_ct[s] = 1

for (state, id_), next_state in transitions.items():
if id_ == fsm_info.alphabet_anything_value:
continue
Expand Down Expand Up @@ -177,3 +186,5 @@ def test_main(regex_string):
test_main(r"霍格沃茨特快列车|霍比特人比尔博")
# 霍格: \xe9\x9c\x8d \xe6\xa0\xbc ...
# 霍比: \xe9\x9c\x8d \xe6\xaf\x94 ...

test_main(r"[-+]?[0-9]+[ ]*")

0 comments on commit 21785a9

Please sign in to comment.