Skip to content

Conversation

@joelpaulkoch
Copy link
Member

This PR subsumes everything done in #1 and #2 and some more experimentation.
It shows how to implement constrained generation with DFA.
Two modes are available:

  1. :stateless
    In each generation step, we start at the initial state, then we go through each of the already generated tokens and find the new state using the state transition tensor.
    After we went through the complete generated sequence to the current point we find the current state.

With the current state we can determine which token ids are allowed, using the state transitions tensor.

(this mode implicitly assumes that the initial state is 0, and that we won't return to the initial state at a later step as we see values of 0 in the state transitions tensor as "empty/invalid". I think we could fix that by making sure that row 0 is actually empty and 0 is an invalid state).

  1. :stateful
    For this we need stateful logit processors, that's why this branch is based on [#SAMPLE-6] Add state to logits processing #3 .
    With that we can just remember the last state and use that and the last token to determine the current state using the state transitions tensor.

With the current state we can determine which token ids are allowed, using the state transitions tensor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants