Skip to content

[Inference]Modify TensorRT Input data name to collect shape in PIR #71281

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

Merged
merged 4 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions python/paddle/tensorrt/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Input:
This class supports generating random input data for minimum, optimal, and maximum shapes, with configurable data types (e.g., 'int' or 'float') and value ranges.

Args:
input_data (tuple):
warmup_data (tuple):
The tuple of Input data arrays (possibly different shapes).
min_input_shape (tuple):
The shape of the minimum input tensor.
Expand Down Expand Up @@ -89,14 +89,14 @@ class Input:

def __init__(
self,
input_data: tuple[np.ndarray, ...] | None = None,
warmup_data: tuple[np.ndarray, ...] | None = None,
min_input_shape: tuple | None = None,
max_input_shape: tuple | None = None,
optim_input_shape: tuple | None = None,
input_data_type: str | None = 'float32',
input_range: tuple | None = None,
) -> None:
if input_data is not None:
if warmup_data is not None:
if min_input_shape or max_input_shape or optim_input_shape:
logging.warning(
"Input data provided; min/max/optim shapes are ignored."
Expand All @@ -107,7 +107,7 @@ def __init__(
"When input_data is None, min/max/optim shapes must be specified."
)

self.input_data = input_data
self.warmup_data = warmup_data
self.min_input_shape = min_input_shape
self.max_input_shape = max_input_shape
self.optim_input_shape = optim_input_shape
Expand Down Expand Up @@ -141,8 +141,8 @@ def generate_input_data(self):
>>> input.input_range=(1,10)
>>> input_min_data, input_optim_data, input_max_data = input_config.generate_input_data()
"""
if self.input_data is not None:
return self.input_data
if self.warmup_data is not None:
return self.warmup_data
else:
if self.input_data_type is None:
self.input_data_type = 'float32'
Expand Down Expand Up @@ -272,7 +272,7 @@ def __init__(
>>> trt_config.workspace_size = 2 << 30
"""
# Checking Input Consistency
has_input_data = [i.input_data is not None for i in inputs]
has_input_data = [i.warmup_data is not None for i in inputs]
if any(has_input_data):
if not all(has_input_data):
raise ValueError("All Inputs must have input_data if any does.")
Expand Down Expand Up @@ -306,6 +306,10 @@ def convert_to_trt(program, trt_config, scope):

with paddle.pir_utils.IrGuard():
input_tuples = [i.generate_input_data() for i in trt_config.inputs]
# Check all inputs have same number of warmup_data samples
assert (
len({len(t) for t in input_tuples}) == 1
), "All inputs must have the same number of warmup_data samples."
feeds = [
{name: t[i] for t, name in zip(input_tuples, feed_name)}
for i in range(len(input_tuples[0]))
Expand Down
2 changes: 1 addition & 1 deletion test/tensorrt/test_converter_model_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_paddle_to_tensorrt_collect_shape(self):
np.random.rand(n, 64).astype(np.float32) for n in (1, 4, 8)
)
input_optim_data = input_data[1]
input_config = Input(input_data=input_data)
input_config = Input(warmup_data=input_data)

# Create a TensorRTConfig with inputs as a required field.
trt_config = TensorRTConfig(inputs=[input_config])
Expand Down
2 changes: 1 addition & 1 deletion test/tensorrt/test_converter_model_resnet50.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_paddle_to_tensorrt_conversion_r50_collect_shape(self):
np.random.rand(n, 3, 224, 224).astype(np.float32) for n in (1, 2, 4)
)
input_optim_data = input_data[1]
input_config = Input(input_data=input_data)
input_config = Input(warmup_data=input_data)

# Create a TensorRTConfig with inputs as a required field.
trt_config = TensorRTConfig(inputs=[input_config])
Expand Down