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

chore(mlx-lm): fix the top_p implementation. #602

Merged
merged 6 commits into from
Mar 21, 2024

Conversation

mzbac
Copy link
Contributor

@mzbac mzbac commented Mar 21, 2024

The top_p is supposed to sort prob in ascending order and select the cumulative token prob above the threshold. The current implementation works because we have a bug in reversing the sorted prob, which accidentally makes sorted prob in the correct order. So, it's better to fix the implementation to reduce the confusion.

llms/mlx_lm/utils.py Outdated Show resolved Hide resolved
llms/mlx_lm/utils.py Outdated Show resolved Hide resolved
llms/mlx_lm/utils.py Outdated Show resolved Hide resolved
@awni
Copy link
Member

awni commented Mar 21, 2024

Btw @mzbac looks like the CI issue is resolved for you, thanks!!

@mzbac
Copy link
Contributor Author

mzbac commented Mar 21, 2024

@awni I have added the unit test, so it is ready for review again. Please let me know if there is anything else that needs to be updated.

llms/mlx_lm/sample_utils.py Outdated Show resolved Hide resolved
llms/mlx_lm/sample_utils.py Outdated Show resolved Hide resolved
llms/tests/test_sample_utils.py Outdated Show resolved Hide resolved
@awni
Copy link
Member

awni commented Mar 21, 2024

I'm not sure about introducing a separate file for that. Do you think it's necessary? Is the idea that we will add more samplers?

@mzbac
Copy link
Contributor Author

mzbac commented Mar 21, 2024

The main reason for putting it into a separate file is the current utils.py has become too large, making it difficult to maintain. So, I think we may need to start splitting up the utils.py file. sampling utils might be a good starting point. Sampling utils would include top_p, repetitive penalty and any future sampling methods that we want to support.

@awni
Copy link
Member

awni commented Mar 21, 2024

So, I think we may need to start splitting up the utils.py file.

Agreed.

Sampling utils would include top_p, repetitive penalty and any future sampling methods that we want to support.

I'm not wild about the name sampling_utils but I think collecting that related functionality in a new file makes sense. Let's go with it for now but I may change the file name in the future if I can think of a better one 😄

Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 thanks for fixing that and for the tests!

@awni awni merged commit fbed720 into ml-explore:main Mar 21, 2024
3 checks passed
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.

None yet

3 participants