Repository navigation
fix: Prevent silent gRPC stream cancellations under backpressure #9004
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
Open
akhilraj9
wants to merge
1
commit into
main
Choose a base branch
from
asaraswathi/tri-1711-stream-accept-prefetch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,18 +30,18 @@ | |
|
|
||
| sys.path.append("../common") | ||
|
|
||
| import os | ||
| import queue | ||
| import threading | ||
| import time | ||
| import unittest | ||
| from contextlib import ExitStack | ||
| from functools import partial | ||
|
|
||
| import numpy as np | ||
| import test_util as tu | ||
| import tritonclient.grpc as grpcclient | ||
| from tritonclient.utils import InferenceServerException | ||
| import os # noqa: E402 | ||
|
Contributor
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. why al of the |
||
| import queue # noqa: E402 | ||
| import threading # noqa: E402 | ||
| import time # noqa: E402 | ||
| import unittest # noqa: E402 | ||
| from contextlib import ExitStack # noqa: E402 | ||
| from functools import partial # noqa: E402 | ||
|
|
||
| import numpy as np # noqa: E402 | ||
| import test_util as tu # noqa: E402 | ||
| import tritonclient.grpc as grpcclient # noqa: E402 | ||
| from tritonclient.utils import InferenceServerException # noqa: E402 | ||
|
|
||
| SERVER_URL = "localhost:8001" | ||
| DEFAULT_RESPONSE_TIMEOUT = 60 | ||
|
|
@@ -79,6 +79,14 @@ def prepare_infer_args(input_value, enable_batching=False): | |
| return infer_input, outputs | ||
|
|
||
|
|
||
| def _describe_error(err): | ||
| """Concise, readable description of a tritonclient error for logs and asserts.""" | ||
| try: | ||
| return f"{err.status()}: {err.message()}" | ||
| except Exception: | ||
| return str(err) | ||
|
|
||
|
|
||
| def collect_responses(user_data, timeout=DEFAULT_RESPONSE_TIMEOUT): | ||
| """ | ||
| Collect responses from user_data until the final response flag is seen. | ||
|
|
@@ -138,16 +146,22 @@ def _run_inference( | |
| model_name=model_name, inputs=inputs, outputs=outputs | ||
| ) | ||
|
|
||
| # Collect and verify responses for all requests | ||
| # Collect and verify responses for all requests. Assert on errors | ||
| # first so a real failure (e.g. CANCELLED) surfaces instead of a | ||
| # misleading "expected N, got 0". | ||
| for i, ud in enumerate(user_datas): | ||
| errors, responses = collect_responses(ud) | ||
| self.assertEqual( | ||
| len(responses), | ||
| expected_responses_per_request, | ||
| f"Request {i}: expected {expected_responses_per_request} responses, got {len(responses)}", | ||
| len(errors), | ||
| 0, | ||
| f"Request {i}: Triton returned error(s): " | ||
| f"{[_describe_error(e) for e in errors]}", | ||
| ) | ||
| self.assertEqual( | ||
| len(errors), 0, f"Request {i}: unexpected errors: {errors}" | ||
| len(responses), | ||
| expected_responses_per_request, | ||
| f"Request {i}: expected {expected_responses_per_request} " | ||
| f"response(s), got {len(responses)}", | ||
| ) | ||
| # Verify correctness of responses | ||
| for idx, resp in enumerate(responses): | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -307,6 +307,7 @@ enum TritonOptionId { | |
| OPTION_GRPC_ADDRESS, | ||
| OPTION_GRPC_HEADER_FORWARD_PATTERN, | ||
| OPTION_GRPC_INFER_THREAD_COUNT, | ||
| OPTION_GRPC_STREAM_ACCEPT_PREFETCH, | ||
| OPTION_GRPC_INFER_ALLOCATION_POOL_SIZE, | ||
| OPTION_GRPC_MAX_RESPONSE_POOL_SIZE, | ||
| OPTION_GRPC_USE_SSL, | ||
|
|
@@ -542,6 +543,13 @@ TritonParser::SetupOptions() | |
| {OPTION_GRPC_INFER_THREAD_COUNT, "grpc-infer-thread-count", | ||
| Option::ArgInt, | ||
| "The number of gRPC inference handler threads. Default is 2."}); | ||
| grpc_options_.push_back( | ||
| {OPTION_GRPC_STREAM_ACCEPT_PREFETCH, "grpc-stream-accept-prefetch", | ||
| Option::ArgInt, | ||
| "The number of accept requests each gRPC streaming inference handler " | ||
|
Contributor
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. Let's clean this up a bit. Perhaps: is "maximum" the correct term to use above? also, what is an "accept request"? |
||
| "keeps outstanding, so up to this many new streams can be matched " | ||
| "immediately even while the handler is busy. Must be in the range 1 " | ||
| "to 128. Default is 16."}); | ||
| grpc_options_.push_back( | ||
| {OPTION_GRPC_INFER_ALLOCATION_POOL_SIZE, | ||
| "grpc-infer-allocation-pool-size", Option::ArgInt, | ||
|
|
@@ -1479,6 +1487,15 @@ TritonParser::Parse(int argc, char** argv) | |
| "the range 2 to 128."); | ||
| } | ||
| break; | ||
| case OPTION_GRPC_STREAM_ACCEPT_PREFETCH: | ||
| lgrpc_options.stream_accept_prefetch_ = ParseOption<int>(optarg); | ||
| if (lgrpc_options.stream_accept_prefetch_ < 1 || | ||
| lgrpc_options.stream_accept_prefetch_ > 128) { | ||
| throw ParseException( | ||
| "invalid argument for --grpc-stream-accept-prefetch. Must be " | ||
| "in the range 1 to 128."); | ||
| } | ||
| break; | ||
| case OPTION_GRPC_INFER_ALLOCATION_POOL_SIZE: | ||
| lgrpc_options.infer_allocation_pool_size_ = ParseOption<int>(optarg); | ||
| break; | ||
|
|
||
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
maybe reword as