-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ci: Add support for max_inflight_responses
parameter to prevent unbounded memory growth in ensemble models
#8458
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
pskiran1
wants to merge
21
commits into
main
Choose a base branch
from
spolisetty/tri-26-triton-dali-ensemble-model-memory-issue
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
Show all changes
21 commits
Select commit
Hold shift + click to select a range
240a223
Update
pskiran1 974aa25
Update
pskiran1 337e0a7
Update
pskiran1 05dcb71
Update
pskiran1 4f379ed
Fix pre-commit
pskiran1 9ed216f
Fix pre-commit errors
pskiran1 78698fc
Update
pskiran1 8665a0d
Update
pskiran1 0258eda
Update
pskiran1 81561fd
Remove duplicate code and add request cancellation test
pskiran1 10dacec
Fix pre-commit
pskiran1 e2e48a3
Fix pre-commit
pskiran1 f8f1468
Update
pskiran1 3d8b848
Update
pskiran1 4a1a8fe
Improve model preparation
pskiran1 554e1b9
Update tests
pskiran1 b2ad735
Add documentation
pskiran1 977420a
Update copyright
pskiran1 c7a6abf
Apply suggestion from @yinggeh
pskiran1 673ec6a
Update docs/user_guide/decoupled_models.md
pskiran1 ce95e2f
Update docs/user_guide/ensemble_models.md
pskiran1 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<!-- | ||
# Copyright 2018-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# Copyright 2018-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
|
@@ -183,6 +183,66 @@ performance, you can use | |
[Model Analyzer](https://github.com/triton-inference-server/model_analyzer) | ||
to find the optimal model configurations. | ||
|
||
## Managing Memory Usage in Ensembles with Decoupled Models | ||
|
||
An *inflight response* is an intermediate output generated by an upstream model and held in memory until it is consumed by a downstream model within an ensemble pipeline. When an ensemble pipeline contains [decoupled models](decoupled_models.md) that produce responses faster than downstream models can process them, inflight responses accumulate internally and may cause unbounded memory growth. This commonly occurs in data preprocessing pipelines where a fast decoupled model (such as DALI, which efficiently streams and preprocesses data) feeds into a slower inference model (such as ONNX Runtime or TensorRT, which are compute-intensive and operate at a lower throughput). | ||
|
||
Consider an example ensemble model with two steps: | ||
1. **DALI preprocessor** (decoupled): Produces 100 preprocessed images/sec | ||
2. **ONNX inference model**: Consumes 10 images/sec | ||
|
||
Here, the DALI model produces responses 10× faster than the ONNX model can process them. Without backpressure, these intermediate tensors accumulate in memory, eventually leading to out-of-memory errors. | ||
|
||
The `max_inflight_responses` field in the ensemble configuration limits the number of concurrent inflight responses between ensemble steps per request. | ||
When this limit is reached, faster upstream models are paused (blocked) until downstream models finish processing, effectively preventing unbounded memory growth. | ||
|
||
``` | ||
ensemble_scheduling { | ||
max_inflight_responses: 16 | ||
|
||
step [ | ||
{ | ||
model_name: "dali_preprocess" | ||
model_version: -1 | ||
input_map { key: "RAW_IMAGE", value: "IMAGE" } | ||
output_map { key: "PREPROCESSED_IMAGE", value: "preprocessed" } | ||
}, | ||
{ | ||
model_name: "onnx_inference" | ||
model_version: -1 | ||
input_map { key: "INPUT", value: "preprocessed" } | ||
output_map { key: "OUTPUT", value: "RESULT" } | ||
} | ||
] | ||
} | ||
``` | ||
|
||
**Configuration:** | ||
* **`max_inflight_responses: 16`**: For each ensemble request (not globally), at most 16 responses from `dali_preprocess` | ||
can wait for `onnx_inference` to process. Once this per-step limit is reached, `dali_preprocess` is blocked until the downstream step completes a response. | ||
* **Default (`0`)**: No limit - allows unlimited inflight responses (original behavior). | ||
|
||
### When to Use This Feature | ||
|
||
Use `max_inflight_responses` when your ensemble includes: | ||
* **Decoupled models** that produce multiple responses per request | ||
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. Same here |
||
* **Speed mismatch**: Upstream models significantly faster than downstream models | ||
* **Memory constraints**: Limited GPU/CPU memory available | ||
|
||
### Choosing the Right Value | ||
|
||
The optimal value depends on your deployment configuration, including batch size, request rate, available memory, and throughput characteristics.: | ||
|
||
* **Too low** (e.g., 1-2): The producer step is frequently blocked, underutilizing faster models | ||
* **Too high** (e.g., 1000+): Memory usage increases, reducing the effectiveness of backpressure | ||
* **Recommended**: Start with a small value and tune based on memory usage and throughput monitoring | ||
|
||
### Performance Considerations | ||
|
||
* **Zero overhead when disabled**: If `max_inflight_responses: 0` (default), | ||
no synchronization overhead is incurred. | ||
* **Minimal overhead when enabled**: Uses a blocking/wakeup mechanism per ensemble step, where upstream models are paused ("blocked") when the inflight response limit is reached and resumed ("woken up") as downstream models consume responses. This synchronization ensures memory usage stays within bounds, though it may increase latency. | ||
|
||
## Additional Resources | ||
|
||
You can find additional end-to-end ensemble examples in the links below: | ||
|
54 changes: 54 additions & 0 deletions
54
qa/L0_simple_ensemble/backpressure_test_models/decoupled_producer/1/model.py
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
import numpy as np | ||
import triton_python_backend_utils as pb_utils | ||
|
||
|
||
class TritonPythonModel: | ||
""" | ||
Decoupled model that produces N responses based on input value. | ||
""" | ||
|
||
def execute(self, requests): | ||
for request in requests: | ||
# Get input - number of responses to produce | ||
in_tensor = pb_utils.get_input_tensor_by_name(request, "IN") | ||
count = in_tensor.as_numpy()[0] | ||
pskiran1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
response_sender = request.get_response_sender() | ||
|
||
# Produce 'count' responses, each with 0.5 as the output value | ||
for i in range(count): | ||
out_tensor = pb_utils.Tensor("OUT", np.array([0.5], dtype=np.float32)) | ||
response = pb_utils.InferenceResponse(output_tensors=[out_tensor]) | ||
response_sender.send(response) | ||
|
||
# Send final flag | ||
response_sender.send(flags=pb_utils.TRITONSERVER_RESPONSE_COMPLETE_FINAL) | ||
|
||
return None |
58 changes: 58 additions & 0 deletions
58
qa/L0_simple_ensemble/backpressure_test_models/decoupled_producer/config.pbtxt
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
name: "decoupled_producer" | ||
backend: "python" | ||
max_batch_size: 0 | ||
|
||
input [ | ||
{ | ||
name: "IN" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
} | ||
] | ||
|
||
output [ | ||
{ | ||
name: "OUT" | ||
data_type: TYPE_FP32 | ||
dims: [ 1 ] | ||
} | ||
] | ||
|
||
instance_group [ | ||
{ | ||
count: 1 | ||
kind: KIND_CPU | ||
} | ||
] | ||
|
||
model_transaction_policy { | ||
decoupled: true | ||
} | ||
|
75 changes: 75 additions & 0 deletions
75
...e_ensemble/backpressure_test_models/ensemble_disabled_max_inflight_responses/config.pbtxt
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
pskiran1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
platform: "ensemble" | ||
max_batch_size: 0 | ||
|
||
input [ | ||
{ | ||
name: "IN" | ||
data_type: TYPE_INT32 | ||
dims: [ 1 ] | ||
} | ||
] | ||
|
||
output [ | ||
{ | ||
name: "OUT" | ||
data_type: TYPE_FP32 | ||
dims: [ 1 ] | ||
} | ||
] | ||
|
||
ensemble_scheduling { | ||
step [ | ||
{ | ||
model_name: "decoupled_producer" | ||
model_version: -1 | ||
input_map { | ||
key: "IN" | ||
value: "IN" | ||
} | ||
output_map { | ||
key: "OUT" | ||
value: "intermediate" | ||
} | ||
}, | ||
{ | ||
model_name: "slow_consumer" | ||
model_version: -1 | ||
input_map { | ||
key: "INPUT0" | ||
value: "intermediate" | ||
} | ||
output_map { | ||
key: "OUTPUT0" | ||
value: "OUT" | ||
} | ||
} | ||
] | ||
} | ||
|
Oops, something went wrong.
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.
Is it only happening in decoupled model, or any models with big processing speed difference?
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.
Based on my understanding, since the normal model step will have only one response, a slow processing step will automatically block the request. In this case, memory usage will increase at a normal rate and may not need any additional backpressure at the step level. To effectively manage overall memory usage, a
rate limiter
could be sufficient.