Generate: TextIteratorStreamer (streamer for gradio)#22501
Merged
Conversation
gante
commented
Mar 31, 2023
Contributor
Author
There was a problem hiding this comment.
Note: the logic in put() and end() is a near copy-paste from TextStreamer -- instead of printing, puts things in the queue.
Most of the logic here is to work around model-specific tokenization quirks.
|
The documentation is not available anymore as the PR was closed or merged. |
sgugger
approved these changes
Mar 31, 2023
sgugger
left a comment
Collaborator
There was a problem hiding this comment.
Still not a fan of this API that requires a new thread to work, but I guess no one has to use it since it's a separate object. So only those who really like thread will end up using it ;-)
TextIteratorStreamer (streamer for gradio)
raghavanone
pushed a commit
to raghavanone/transformers
that referenced
this pull request
Apr 5, 2023
…2501) * haha text go brrr (but in gradio)
novice03
pushed a commit
to novice03/transformers
that referenced
this pull request
Jun 23, 2023
…2501) * haha text go brrr (but in gradio)
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Following the previous streamer PR (#22449), this PR adds a streamer that can be used as an iterator. If we want to use the iterator while generate is running, they must be on separate threads (naturally).
The interface looks quite simple, as can be seen in the documentation 🤗 The only kink is the need to call generation on a separate thread, but there is no great way around it (at most we can design an
ifbranch inside generate where, if a streamer is used, generate is called in a separate thread... but that seems overkill for now).A Gradio demo running on this branch can be seen here. There is pretty much no slowdown compared to a non-streamer call.
Inspired by @oobabooga's work (see this comment).