Skip to content

Commit

Permalink
Merge pull request #262 from israel-hdez/odh-prepare-v0.12
Browse files Browse the repository at this point in the history
Prepare ODH's v0.12.0 branch cut
  • Loading branch information
openshift-merge-bot[bot] authored Apr 10, 2024
2 parents 926a43c + 4cdd3a7 commit 535288f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 13 additions & 5 deletions python/kserve/kserve/protocol/infer_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,26 +621,29 @@ def __eq__(self, other):
class InferResponse:
id: str
model_name: str
model_version: Optional[str]
parameters: Optional[Dict]
outputs: List[InferOutput]
from_grpc: bool

def __init__(self, response_id: str, model_name: str, infer_outputs: List[InferOutput],
raw_outputs=None, from_grpc: Optional[bool] = False,
model_version: Optional[str] = None, raw_outputs=None, from_grpc: Optional[bool] = False,
parameters: Optional[Union[Dict, MessageMap[str, InferParameter]]] = None):
"""The InferResponse Data Model
Args:
response_id: The id of the inference response.
model_name: The name of the model.
infer_outputs: The inference outputs of the inference response.
model_version: The version of the model.
raw_outputs: The raw binary data of the inference outputs.
from_grpc: Indicate if the InferResponse is constructed from a gRPC response.
parameters: The additional inference parameters.
"""

self.id = response_id
self.model_name = model_name
self.model_version = model_version
self.outputs = infer_outputs
self.parameters = parameters
self.from_grpc = from_grpc
Expand All @@ -657,8 +660,9 @@ def from_grpc(cls, response: ModelInferResponse) -> 'InferResponse':
data=get_content(output.datatype, output.contents),
parameters=output.parameters)
for output in response.outputs]
return cls(model_name=response.model_name, response_id=response.id, parameters=response.parameters,
infer_outputs=infer_outputs, raw_outputs=response.raw_output_contents, from_grpc=True)
return cls(model_name=response.model_name, model_version=response.model_version, response_id=response.id,
parameters=response.parameters, infer_outputs=infer_outputs,
raw_outputs=response.raw_output_contents, from_grpc=True)

@classmethod
def from_rest(cls, model_name: str, response: Dict) -> 'InferResponse':
Expand All @@ -672,6 +676,7 @@ def from_rest(cls, model_name: str, response: Dict) -> 'InferResponse':
parameters=output.get('parameters', None))
for output in response['outputs']]
return cls(model_name=model_name,
model_version=response.get('model_version', None),
response_id=response.get('id', None),
parameters=response.get('parameters', None),
infer_outputs=infer_outputs)
Expand Down Expand Up @@ -702,6 +707,7 @@ def to_rest(self) -> Dict:
res = {
'id': self.id,
'model_name': self.model_name,
'model_version': self.model_version,
'outputs': infer_outputs
}
if self.parameters:
Expand Down Expand Up @@ -742,15 +748,17 @@ def to_grpc(self) -> ModelInferResponse:
raise InvalidInput("to_grpc: invalid output datatype")
infer_outputs.append(infer_output_dict)

return ModelInferResponse(id=self.id, model_name=self.model_name, outputs=infer_outputs,
raw_output_contents=raw_output_contents,
return ModelInferResponse(id=self.id, model_name=self.model_name, model_version=self.model_version,
outputs=infer_outputs, raw_output_contents=raw_output_contents,
parameters=to_grpc_parameters(self.parameters) if self.parameters else None)

def __eq__(self, other):
if not isinstance(other, InferResponse):
return False
if self.model_name != other.model_name:
return False
if self.model_version != other.model_version:
return False
if self.id != other.id:
return False
if self.from_grpc != other.from_grpc:
Expand Down
11 changes: 6 additions & 5 deletions python/kserve/test/test_infer_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_from_grpc(self):

class TestInferResponse:
def test_to_rest(self):
infer_res = InferResponse(model_name="TestModel", response_id="123",
infer_res = InferResponse(model_name="TestModel", response_id="123", model_version="v1",
parameters={
"test-str": InferParameter(string_param="dummy"),
"test-bool": InferParameter(bool_param=True),
Expand All @@ -156,6 +156,7 @@ def test_to_rest(self):
expected = {
"id": "123",
"model_name": "TestModel",
"model_version": "v1",
"outputs": [
{
"name": "output-0",
Expand All @@ -179,7 +180,7 @@ def test_to_rest(self):
assert res == expected

def test_to_grpc(self):
infer_res = InferResponse(model_name="TestModel", response_id="123",
infer_res = InferResponse(model_name="TestModel", response_id="123", model_version="v1",
parameters={
"test-str": "dummy",
"test-bool": True,
Expand All @@ -193,7 +194,7 @@ def test_to_grpc(self):
"test-int": 100
})]
)
expected = ModelInferResponse(model_name="TestModel", id="123",
expected = ModelInferResponse(model_name="TestModel", id="123", model_version="v1",
parameters={
"test-str": InferParameter(string_param="dummy"),
"test-bool": InferParameter(bool_param=True),
Expand All @@ -218,7 +219,7 @@ def test_to_grpc(self):
assert res == expected

def test_from_grpc(self):
infer_res = ModelInferResponse(model_name="TestModel", id="123",
infer_res = ModelInferResponse(model_name="TestModel", id="123", model_version="v1",
parameters={
"test-str": InferParameter(string_param="dummy"),
"test-bool": InferParameter(bool_param=True),
Expand All @@ -239,7 +240,7 @@ def test_from_grpc(self):
},
}]
)
expected = InferResponse(model_name="TestModel", response_id="123",
expected = InferResponse(model_name="TestModel", response_id="123", model_version="v1",
parameters={
"test-str": InferParameter(string_param="dummy"),
"test-bool": InferParameter(bool_param=True),
Expand Down

0 comments on commit 535288f

Please sign in to comment.