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

Handle TGI error when streaming tokens #1711

Merged
merged 3 commits into from
Oct 5, 2023

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Oct 5, 2023

Fix #1651.

When streaming tokens from a TGI server, an error might happen and be returned in the stream of tokens. At the moment this raises a pydantic ValidationError as it's not recognized as a proper TextGenerationStreamResponse. This PR adds a check to parse correctly the error message + raise a custom exception whenever possible.

cc @osanseviero @OlivierDehaene

Note: I couldn't really test this PR as the problem is hard to reproduce (it happened in the falcon-180b demo Space which has heavy usage -see thread (internal)). Shouldn't be too risky though (error/error_type being optional client-side).

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 5, 2023

The documentation is not available anymore as the PR was closed or merged.

@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (90c1182) 82.30% compared to head (9d3b8a2) 82.40%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1711      +/-   ##
==========================================
+ Coverage   82.30%   82.40%   +0.10%     
==========================================
  Files          62       62              
  Lines        7226     7236      +10     
==========================================
+ Hits         5947     5963      +16     
+ Misses       1279     1273       -6     
Files Coverage Δ
src/huggingface_hub/inference/_text_generation.py 95.78% <93.33%> (-0.47%) ⬇️
src/huggingface_hub/inference/_common.py 91.40% <60.00%> (-1.34%) ⬇️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Wauplin Wauplin requested a review from LysandreJik October 5, 2023 12:00
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Looks good to me! clean abstraction

@Wauplin Wauplin merged commit 5d2d297 into main Oct 5, 2023
16 checks passed
@Wauplin Wauplin deleted the 1651-handle-error-response-when-streaming-tokens branch October 5, 2023 13:30
@Wauplin
Copy link
Contributor Author

Wauplin commented Oct 5, 2023

Thanks for the review, I'm merging it now :)

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.

InferenceClient: handle error response in when streaming tokens from TGI
3 participants