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

Add sleep to fix lag in chat stream #10339

Merged
merged 3 commits into from Feb 9, 2024

Conversation

w4ffl35
Copy link
Contributor

@w4ffl35 w4ffl35 commented Jan 29, 2024

Description

This is a fix for a bug which I identified while attempting to use Chat Stream from within a thread. Adding a sleep within the loop unblocks the thread allowing the chat to stream as expected.
Without this fix, each iteration severely hangs.

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

This has been tested within my application which uses llamaindex. My application runs in a separate worker thread which runs properly with all other streaming agents outside of llama index. When I use chat_stream with llama index, it hangs. This code fixes the issue.

Suggested Checklist:

  • I have performed a self-review of my own code
  • My changes generate no new warnings

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jan 29, 2024
@logan-markewich
Copy link
Collaborator

@w4ffl35 I'm not 100% this fixes anything? Both with and without this fix the behaviour seems the same. See the test code here
#10290 (comment)

Maybe I'm using flask+streaming wrong though

@w4ffl35
Copy link
Contributor Author

w4ffl35 commented Feb 3, 2024

@logan-markewich did you test with threads?

If the loop enters the continue line after the exception it will lag severely in a loop. I experienced it and lost hours debugging. Adding the sleep fixes it - you can see similar solutions employed in the huggingface workers in transformers for the same reasons as outlined in their commits (which I have since switched to).

@logan-markewich logan-markewich merged commit d15e732 into run-llama:main Feb 9, 2024
8 checks passed
Izukimat pushed a commit to Izukimat/llama_index that referenced this pull request Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants