Skip to content

A sampling function that returns top token probabilities #1784

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

Closed
WangHaoranRobin opened this issue Jun 10, 2023 · 2 comments
Closed

A sampling function that returns top token probabilities #1784

WangHaoranRobin opened this issue Jun 10, 2023 · 2 comments

Comments

@WangHaoranRobin
Copy link
Contributor

I was using playing around with the server example and wanted to expose the probabilities of the generated tokens to the server client to implement custom stopping sequences and criteria(similar to openai's api here).

All it would take should just be creating a different version of "llama_sample_token" and "llama_sample_token_greedy" that returns an object containing the top X tokens and their probabilities.

The only related issue/pr/discussion I was able to find is this pr about logging probabilities. Please give me pointers if similar requests have been discussed somewhere.

Since I'm relatively new to the repo, what is the protocol here? Should I just make a PR?

@nauyisu022
Copy link

Did you find out how to achieve this?

@WangHaoranRobin
Copy link
Contributor Author

Yes. I realized the parameters passed into the sample functions are references. So no need to change the core logic to get the probs. just read directly from the candidate list object after passing it through the sampling function is enough.

i.e. in server.cpp :
https://github.com/ggerganov/llama.cpp/blob/049aa16b8c5c6d086246e4e6b9feb18de4fbd663/examples/server/server.cpp#L293
Read candidates_p.data[i].p after the sampling functions are called to get the probs.

I'm working on a PR for server example about this rn.

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

2 participants