-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration for
transformers
via logits processors
- Loading branch information
1 parent
11143df
commit 5d97ee1
Showing
16 changed files
with
763 additions
and
319 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Example of integrating `outlines` with `transformers`.""" | ||
|
||
from pydantic import BaseModel | ||
from transformers import pipeline | ||
|
||
from outlines.integrations.transformers import JSONPrefixAllowedTokens | ||
|
||
|
||
class Person(BaseModel): | ||
first_name: str | ||
surname: str | ||
|
||
|
||
pipe = pipeline("text-generation", model="mistralai/Mistral-7B-v0.1") | ||
prefix_allowed_tokens_fn = JSONPrefixAllowedTokens( | ||
schema=Person, tokenizer_or_pipe=pipe, whitespace_pattern=r" ?" | ||
) | ||
results = pipe( | ||
["He is Tom Jones", "She saw Linda Smith"], | ||
return_full_text=False, | ||
do_sample=False, | ||
max_new_tokens=50, | ||
prefix_allowed_tokens_fn=prefix_allowed_tokens_fn, | ||
) | ||
print(results) |
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,20 +1,24 @@ | ||
"""Example of integrating `outlines` with `vllm`.""" | ||
|
||
import vllm | ||
from pydantic import BaseModel | ||
|
||
from outlines.serve.vllm import JSONLogitsProcessor | ||
from outlines.integrations.vllm import JSONLogitsProcessor | ||
|
||
|
||
class User(BaseModel): | ||
id: int | ||
name: str | ||
class Person(BaseModel): | ||
first_name: str | ||
surname: str | ||
|
||
|
||
llm = vllm.LLM(model="openai-community/gpt2") | ||
logits_processor = JSONLogitsProcessor(schema=User, llm=llm) | ||
llm = vllm.LLM(model="mistralai/Mistral-7B-v0.1", max_model_len=512) | ||
logits_processor = JSONLogitsProcessor(schema=Person, llm=llm, whitespace_pattern=r" ?") | ||
result = llm.generate( | ||
["A prompt", "Another prompt"], | ||
["He is Tom Jones", "She saw Linda Smith"], | ||
sampling_params=vllm.SamplingParams( | ||
max_tokens=100, logits_processors=[logits_processor] | ||
temperature=0.0, | ||
max_tokens=50, | ||
logits_processors=[logits_processor], | ||
), | ||
) | ||
print(result) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Utility functions and classes used to integrate `outlines` into other packages.""" |
Oops, something went wrong.