Skip to content

Commit

Permalink
Added to python_backend autocomplete: optional input and model_transa…
Browse files Browse the repository at this point in the history
…ction_policy
  • Loading branch information
oandreeva-nv committed Oct 31, 2023
1 parent a442f3f commit 09e5ab8
Showing 1 changed file with 69 additions and 5 deletions.
74 changes: 69 additions & 5 deletions src/resources/triton_python_backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,12 @@ def add_input(self, input):
Raises
------
ValueError
If input contains property other than 'name', 'data_type'
and 'dims' or any of the properties are not set, or if an
input with the same name already exists in the configuration
but has different data_type or dims property
If input contains property other than 'name', 'data_type',
'dims', 'optional' or any of the non-optional properties
are not set, or if an input with the same name already exists
in the configuration but has different data_type or dims property
"""
valid_properties = ["name", "data_type", "dims"]
valid_properties = ["name", "data_type", "dims", "optional"]
for current_property in input:
if current_property not in valid_properties:
raise ValueError(
Expand Down Expand Up @@ -447,9 +447,26 @@ def add_input(self, input):
+ " but the model configuration specifies dims "
+ str(current_input["dims"])
)
elif (
"optional" in current_input
and "optional" in input
and current_input["optional"] != input["optional"]
):
raise ValueError(
"model '"
+ self._model_config["name"]
+ "', tensor '"
+ input["name"]
+ "': the model expects optional "
+ str(input["optional"])
+ " but the model configuration specifies optional "
+ str(current_input["optional"])
)
else:
current_input["data_type"] = input["data_type"]
current_input["dims"] = input["dims"]
if "optional" in input:
current_input["optional"] = input["optional"]
return

self._model_config["input"].append(input)
Expand Down Expand Up @@ -538,6 +555,53 @@ def add_output(self, output):

self._model_config["output"].append(output)

def set_model_transaction_policy(self, transaction_policy_dict):
"""
Set model transaction policy for the model.
Parameters
----------
transaction_policy_dict : dict
The dict, containing all properties to be set as a part
of `model_transaction_policy` field.
Raises
------
ValueError
If transaction_policy_dict contains property other
than 'decoupled', or if `model_transaction_policy` already exists
in the configuration, but has different `decoupled` property.
"""
valid_properties = ["decoupled"]
for current_property in transaction_policy_dict.keys():
if current_property not in valid_properties:
raise ValueError(
"model transaction property in auto-complete-config "
+ "function for model '"
+ self._model_config["name"]
+ "' contains property other than 'decoupled'."
)

if "model_transaction_policy" not in self._model_config:
self._model_config["model_transaction_policy"] = {}

if "decoupled" in transaction_policy_dict.keys():
if (
"decoupled" in self._model_config["model_transaction_policy"]
and self._model_config["model_transaction_policy"]["decoupled"]
!= transaction_policy_dict["decoupled"]
):
raise ValueError(
"trying to change decoupled property in auto-complete-config "
+ "for model '"
+ self._model_config["name"]
+ "', which is already set to '"
+ str(self._model_config["model_transaction_policy"]["decoupled"])
+ "'."
)

self._model_config["model_transaction_policy"][
"decoupled"
] = transaction_policy_dict["decoupled"]


TRITONSERVER_REQUEST_FLAG_SEQUENCE_START = 1
TRITONSERVER_REQUEST_FLAG_SEQUENCE_END = 2
Expand Down

0 comments on commit 09e5ab8

Please sign in to comment.