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

How to get the logits in mlx-lm? #1292

Open
Mihaiii opened this issue Feb 20, 2025 · 1 comment
Open

How to get the logits in mlx-lm? #1292

Mihaiii opened this issue Feb 20, 2025 · 1 comment

Comments

@Mihaiii
Copy link

Mihaiii commented Feb 20, 2025

I'm interested in adding mlx-lm as a provider in Backtrack Sampler.

I generate one token at a time, apply my own temperature, and handle the selection of the next token in my own code. Therefore, I need to retrieve the logits from mlx-lm rather than pass it a custom sampler.

I have some changes in a branch, fwiw, but they currently don't work because I handle log probabilities (logprobs) instead of logits, as I'm using the utils.stream_generate function. I don't necessarily need to use stream_generate; I used it because I saw it here.

Is there a way to get the logits in mlx-lm?

@Mihaiii Mihaiii changed the title How to get the logits? How to get the logits in mlx-lm? Feb 20, 2025
@awni
Copy link
Member

awni commented Feb 20, 2025

Typically it should be possible to treat the logprobs as if they were logits. Unless you are doing something that relies on the normalization term (which is not so common).

For example for temperature scaling, you should be able to use the logprobs as if they were logits since it should be the case that:mx.softmax(temp * logits) == mx.softmax(temp * logprobs).

Another option is to send stream_generate a custom logits_processor using the logits_processors keyword arg.

It would be good to try and track down where the discrepancy in your code is. If it's actually the case that you need to operate on the logits as opposed the log probs.. would be interesting to know what the reason is.

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