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

Return self in InferInput setters for chain-initialization #378

Merged
merged 1 commit into from
Aug 7, 2023
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
17 changes: 17 additions & 0 deletions src/python/library/tritonclient/grpc/_infer_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ def set_shape(self, shape):
----------
shape : list
The shape of the associated input.

Returns
-------
InferInput
The updated input
"""
self._input.ClearField("shape")
self._input.shape.extend(shape)
return self

def set_data_from_numpy(self, input_tensor):
"""Set the tensor data from the specified numpy array for
Expand All @@ -106,6 +112,11 @@ def set_data_from_numpy(self, input_tensor):
input_tensor : numpy array
The tensor data in numpy array format

Returns
-------
InferInput
The updated input

Raises
------
InferenceServerException
Expand Down Expand Up @@ -160,6 +171,7 @@ def set_data_from_numpy(self, input_tensor):
self._raw_content = b""
else:
self._raw_content = input_tensor.tobytes()
return self

def set_shared_memory(self, region_name, byte_size, offset=0):
"""Set the tensor data from the specified shared memory region.
Expand All @@ -174,6 +186,10 @@ def set_shared_memory(self, region_name, byte_size, offset=0):
The offset, in bytes, into the region where the data for
the tensor starts. The default value is 0.

Returns
-------
InferInput
The updated input
"""
self._input.ClearField("contents")
self._raw_content = None
Expand All @@ -182,6 +198,7 @@ def set_shared_memory(self, region_name, byte_size, offset=0):
self._input.parameters["shared_memory_byte_size"].int64_param = byte_size
if offset != 0:
self._input.parameters["shared_memory_offset"].int64_param = offset
return self

def _get_tensor(self):
"""Retrieve the underlying InferInputTensor message.
Expand Down
17 changes: 17 additions & 0 deletions src/python/library/tritonclient/http/_infer_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ def set_shape(self, shape):
----------
shape : list
The shape of the associated input.

Returns
-------
InferInput
The updated input
"""
self._shape = shape
return self

def set_data_from_numpy(self, input_tensor, binary_data=True):
"""Set the tensor data from the specified numpy array for
Expand All @@ -111,6 +117,11 @@ def set_data_from_numpy(self, input_tensor, binary_data=True):
which means the data will be delivered as binary data in the
HTTP body after the JSON object.

Returns
-------
InferInput
The updated input

Raises
------
InferenceServerException
Expand Down Expand Up @@ -200,6 +211,7 @@ def set_data_from_numpy(self, input_tensor, binary_data=True):
else:
self._raw_data = input_tensor.tobytes()
self._parameters["binary_data_size"] = len(self._raw_data)
return self

def set_shared_memory(self, region_name, byte_size, offset=0):
"""Set the tensor data from the specified shared memory region.
Expand All @@ -214,6 +226,10 @@ def set_shared_memory(self, region_name, byte_size, offset=0):
The offset, in bytes, into the region where the data for
the tensor starts. The default value is 0.

Returns
-------
InferInput
The updated input
"""
self._data = None
self._raw_data = None
Expand All @@ -223,6 +239,7 @@ def set_shared_memory(self, region_name, byte_size, offset=0):
self._parameters["shared_memory_byte_size"] = byte_size
if offset != 0:
self._parameters["shared_memory_offset"] = offset
return self

def _get_binary_data(self):
"""Returns the raw binary data if available
Expand Down
Loading