Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Classifer-Free Guidance (take 2) #835

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

feat: Classifer-Free Guidance (take 2) #835

wants to merge 5 commits into from

Conversation

AlpinDale
Copy link
Member

@AlpinDale AlpinDale commented Nov 25, 2024

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

@AlpinDale AlpinDale marked this pull request as draft November 25, 2024 22:16
@AlpinDale
Copy link
Member Author

It works, but will fail due to changed logit shapes when running without CFG.

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.

Classifier-Free Guidance support
1 participant