forked from dottxt-ai/outlines
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable generate.fsm with llamacpp by using outlines.processors
- Loading branch information
Showing
7 changed files
with
47 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
from functools import singledispatch | ||
|
||
import interegular | ||
|
||
from outlines.fsm.guide import RegexGuide | ||
from outlines.generate.api import SequenceGenerator | ||
from outlines.generate.api import SequenceGenerator, SequenceGeneratorAdapter | ||
from outlines.models import MLXLM, LlamaCpp, Transformers | ||
from outlines.samplers import Sampler, multinomial | ||
|
||
|
||
@singledispatch | ||
def fsm( | ||
model, fsm: interegular.fsm.FSM, sampler: Sampler = multinomial() | ||
) -> SequenceGenerator: | ||
fsm = RegexGuide.from_interegular_fsm(fsm, model.tokenizer) | ||
device = model.device | ||
generator = SequenceGenerator(fsm, model, sampler, device) | ||
return generator | ||
|
||
|
||
@fsm.register(MLXLM) | ||
@fsm.register(Transformers) | ||
@fsm.register(LlamaCpp) | ||
def fsm_unified( | ||
model, fsm: interegular.fsm.FSM, sampler: Sampler = multinomial() | ||
) -> SequenceGeneratorAdapter: | ||
from outlines.processors import FSMLogitsProcessor | ||
|
||
fsm = RegexGuide.from_interegular_fsm(fsm, model.tokenizer) | ||
logits_processor = FSMLogitsProcessor(tokenizer=model.tokenizer, fsm=fsm) | ||
return SequenceGeneratorAdapter(model, logits_processor, sampler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters