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

top_p = 1 causes deterministic outputs #1797

Open
oobabooga opened this issue Oct 14, 2024 · 2 comments
Open

top_p = 1 causes deterministic outputs #1797

oobabooga opened this issue Oct 14, 2024 · 2 comments

Comments

@oobabooga
Copy link
Contributor

Setting top_p = 1 causes outputs to be identical even with a random seed. This was discovered by oobabooga/text-generation-webui#6431 (comment). See the full issue at oobabooga/text-generation-webui#6431.

Reproduction

from llama_cpp import Llama

# Load the model
model = Llama(
    model_path="models/Meta-Llama-3-8B-Instruct-Q4_K_S-HF/Meta-Llama-3-8B-Instruct-Q4_K_S.gguf",
    n_gpu_layers=128,
)

# Define the prompt
prompt = "Once upon a time"

for i in range(5):
    # Generate text with temperature = 1
    completion = model.create_completion(prompt=prompt, max_tokens=50, temperature=1.0, top_p=1.0, seed=-1)

    # Print the generated text
    print(completion['choices'][0]['text'])

The 5 outputs will be identical.

Verified with llama-cpp-python==0.3.1.

@jim-plus
Copy link

For now, setting topP to 0.99 serves as a casual workaround.

@m-from-space
Copy link

The 5 outputs will be identical.

In your example you use seed=-1. Could you confirm, that when not using top_p=1.0 the 5 outputs will be different, but every time it will be the same 5 outputs? I opened an issue here, which was not present in llama-cpp-python==0.2.9

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

No branches or pull requests

3 participants