aphrodite-engine
aphrodite-engine copied to clipboard
feat: Classifer-Free Guidance (take 2)
Redoing #651
FIX #36
Example usage:
from typing import List
from aphrodite import LLM, SamplingParams
from aphrodite.inputs import PromptInputs
llm = LLM(
model="NousResearch/Meta-Llama-3.1-8B-Instruct",
use_v2_block_manager=True,
cfg_model="NousResearch/Meta-Llama-3.1-8B-Instruct"
)
prompt_pairs = [
{
"prompt": "Hello, my name is",
"negative_prompt": "I am uncertain and confused about who I am"
},
{
"prompt": "The president of the United States is",
"negative_prompt": "I don't know anything about US politics or leadership"
},
]
tokenizer = llm.get_tokenizer()
inputs: List[PromptInputs] = [
{
"prompt_token_ids": tokenizer.encode(text=pair["prompt"]),
"negative_prompt_token_ids": tokenizer.encode(text=pair["negative_prompt"])
}
for pair in prompt_pairs
]
sampling_params = SamplingParams(guidance_scale=5.0)
outputs = llm.generate(inputs, sampling_params)
TODO:
- [ ] See if we can skip the double forward pass for the model
- [ ] Pipe into OpenAI API
It works, but will fail due to changed logit shapes when running without CFG.