Skip to content

Commit

Permalink
Return FSM final state if already in final state (#718)
Browse files Browse the repository at this point in the history
Fixes #716
  • Loading branch information
saattrupdan authored Mar 1, 2024
1 parent d938678 commit c0b47a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions outlines/fsm/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def next_state(self, state: FSMState, token_id: int) -> FSMState:
The new state of the FSM.
"""
if token_id == self.eos_token_id:
if token_id == self.eos_token_id or state == self.final_state:
return self.final_state

return self.first_state
Expand Down Expand Up @@ -172,7 +172,7 @@ def next_state(self, state: FSMState, token_id: int) -> FSMState:
The new state of the FSM.
"""
if token_id == self.eos_token_id:
if token_id == self.eos_token_id or state == self.final_state:
return self.final_state

last_token_to_end_state = self.states_to_token_maps[state]
Expand Down Expand Up @@ -354,7 +354,7 @@ def next_state(self, state: FSMState, token_id: int) -> FSMState:
-------
The new state of the FSM.
"""
if token_id == self.tokenizer.eos_token_id:
if token_id == self.tokenizer.eos_token_id or state == self.final_state:
return self.final_state

self.generation += self.tokenizer.decode([token_id])[0]
Expand Down

0 comments on commit c0b47a4

Please sign in to comment.