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

Prerelease 0.2.0rc1 no longer returns log probs with llama.cpp #1064

Open
oj-sec opened this issue Oct 26, 2024 · 4 comments
Open

Prerelease 0.2.0rc1 no longer returns log probs with llama.cpp #1064

oj-sec opened this issue Oct 26, 2024 · 4 comments

Comments

@oj-sec
Copy link

oj-sec commented Oct 26, 2024

The bug
Updating from guidance==0.1.16 to prerelease guidance==0.2.0rc1 causes model.log_prob() to return 0 rather than the true log probs for a generation when using the llama.cpp backend. I have tested GGUF quants of models based on Llama, Mistral and Gemma and observed this behaviour to be model agnostic.

To Reproduce
Reproduction Colab notebook here - involves uninstalling and reinstalling Guidance, but the change in output between installs is:

# With guidance==0.1.16
from guidance import models, gen, select
import math

llm = models.LlamaCpp(f"./models/{model}", n_gpu_layers=40, n_ctx=2000, compute_log_probs=True)
output = llm + "You flip a coin. The result is: " + gen(name="coinflip", regex="(heads|tails)")
logprobs = output.log_prob("coinflip")
prob = round(math.exp(logprobs), 5)
print(f"Output:{output['coinflip']}\nLP: {logprobs}\nP: {prob}")
You flip a coin. The result is: heads
Output:heads
LP: -1.1534752799652015
P: 0.31554
# With guidance==0.2.0rc1
from guidance import models, gen, select
import math

llm = models.LlamaCpp(f"./models/{model}", n_gpu_layers=40, n_ctx=2000, compute_log_probs=True)
output = llm + "You flip a coin. The result is: " + gen(name="coinflip", regex="(heads|tails)")
logprobs = output.log_prob("coinflip")
prob = round(math.exp(logprobs), 5)
print(f"Output:{output['coinflip']}\nLP: {logprobs}\nP: {prob}")
You flip a coin. The result is: heads
Output:heads
LP: 0.0
P: 1.0

System info (please complete the following information):

If I can provide any further info please let me know. Huge thanks for this amazing library.

@hudson-ai
Copy link
Collaborator

Hi @oj-sec thanks for bringing this up, and our apologies if it's impacting your workflow. The new parser that we're using in 0.2.0rc1 is considerably faster than what was running in previous versions, but it currently has a few limitations that we need to continue working on (probability outputs is probably the primary one). So, it's on our radar.

Thank you for submitting the issue!

@woitee
Copy link

woitee commented Jan 14, 2025

@hudson-ai Since 0.2.0 has released and the visualization seems to display probabilities, can we expect this issue to get fixed (soon)?

@hudson-ai
Copy link
Collaborator

Hi @woitee, sorry for the late reply. We're currently displaying probabilities for outputted tokens, but we don't yet have a satisfactory solution for mapping these back to probabilities for a given capture (which is a string that may or may not align to token boundaries). Getting this working again is on the roadmap, but I don't yet have a timeline for you.

Would you mind giving me an idea of how you like to use this feature in practice? More example usages may help motivate a solution :)

@woitee
Copy link

woitee commented Feb 3, 2025

@hudson-ai Thanks for the reply! The main thing I need this for is categorization, I use guidance for classifying e-mails and free-text forms into categories, and I used to provide users with information on how "certain" AI is in these, based on probabilities. If it worked only for select captures, it would solve 90% of usage for me. But I assume that still has to deal with token boundaries correctly and is far from trivial.

Can I access the token probabilities? I might be able to arrange my systems such that a token definitely ends before the select clause and different tokens are at the starts of options - and create some work arounds :)

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