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

feat: smooth and combine token output #936

Merged
merged 2 commits into from Mar 22, 2024

Conversation

Saghen
Copy link
Contributor

@Saghen Saghen commented Mar 18, 2024

I noticed while using the Anthropic endpoint that the output would jump by ~10 tokens, pause for 200ms, and repeat. I've implemented a smoothing function for the streamed output that attempts to estimate the token/s and output at that rate instead.

I also added a chunking function that attempts to concatenate tokens like do and n't. It made it a bit easier to read, especially for long words and code which are split quite heavily.

Some stats for chunking (Anthropic Claude 3 Opus):
~10% fewer tokens in regular text
~25% fewer tokens in mix of 80% code and 20% text

Also, to make these changes easily, I moved the logic into a separate utils file. But I'm pretty sure that's not the right place for this :D

@nsarrazin nsarrazin self-requested a review March 18, 2024 12:42
@nsarrazin nsarrazin added enhancement New feature or request front This issue is related to the front-end of the app. labels Mar 19, 2024
@nsarrazin
Copy link
Collaborator

Works quite well! It's quite a lot of new code so I want to make sure I understand it all but just from a usage point of view I think it's quite nice.

@gary149
Copy link
Collaborator

gary149 commented Mar 19, 2024

I like the UX of it - I'll let @nsarrazin check the code.

@nsarrazin
Copy link
Collaborator

I tested this PR a bit more and seems like the "Stop generating" feature doesn't work anymore, do you think you could take a look? @Saghen

@Saghen
Copy link
Contributor Author

Saghen commented Mar 20, 2024

@nsarrazin fixed! More correct solution might be to expose the abort controller to the stop event and abort directly from there but that seemed hacky

Copy link
Collaborator

@nsarrazin nsarrazin left a comment

Choose a reason for hiding this comment

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

Seems to work quite well! Thanks for the contribution, will merge and deploy soon 🚀

@nsarrazin nsarrazin merged commit 8583cf1 into huggingface:main Mar 22, 2024
3 checks passed
@gary149
Copy link
Collaborator

gary149 commented Mar 22, 2024

You are awesome @Saghen 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request front This issue is related to the front-end of the app.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants