-
Notifications
You must be signed in to change notification settings - Fork 80
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
[HF][streaming][1/n] Text Summarization #851
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,13 +128,18 @@ def construct_stream_output( | |
"metadata": {}, | ||
} | ||
) | ||
|
||
accumulated_message = "" | ||
for new_text in streamer: | ||
if isinstance(new_text, str): | ||
# For some reason these symbols aren't filtered out by the streamer | ||
new_text = new_text.replace("</s>", "") | ||
new_text = new_text.replace("<s>", "") | ||
|
||
accumulated_message += new_text | ||
options.stream_callback(new_text, accumulated_message, 0) | ||
|
||
output.data = accumulated_message | ||
|
||
return output | ||
|
||
|
||
|
@@ -245,7 +250,9 @@ async def run_inference(self, prompt: Prompt, aiconfig: "AIConfigRuntime", optio | |
|
||
# if stream enabled in runtime options and config, then stream. Otherwise don't stream. | ||
streamer = None | ||
should_stream = (options.stream if options else False) and (not "stream" in completion_data or completion_data.get("stream") != False) | ||
should_stream = (options.stream if options else False) and ( | ||
not "stream" in completion_data or completion_data.get("stream") != False | ||
) | ||
Comment on lines
+253
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very complicated logic. Ideally would prefer to break this out into if/else or create a helper function for this, but not ship-blocking if it works. I just am struggling to think how this would work. For e.g. if no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is correct! The reasoning for this is that stream isn't really a model setting, it's an inference setting which we would need to pass in a stream callback, so streaming without it doesn't really make sense if it's not included (where would you stream out to?). Sure I made a task to split this into a helper function: #861 |
||
if should_stream: | ||
tokenizer: AutoTokenizer = AutoTokenizer.from_pretrained(model_name) | ||
streamer = TextIteratorStreamer(tokenizer) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these just signify the start and end of the stream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite! I'm really not sure why they show up for a few models while for
TextGeneration
this isn't needed.I saw something like
</s><s>Streaming Text</s>
But yea just removed so it looks clean