Skip to content

Commit

Permalink
Merge branch 'master' into issue_1361
Browse files Browse the repository at this point in the history
  • Loading branch information
lxning authored Dec 14, 2021
2 parents e762ac2 + e15b4fe commit bbba6d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions ts/torch_handler/request_envelope/kfserving.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ class KFservingEnvelope(BaseEnvelope):
"""

def parse_input(self, data):
logger.info("Parsing input in KFServing.py")
self._data_list = [row.get("data") or row.get("body") for row in data]
# selecting the first input from the list torchserve creates
logger.info("Parse input data_list %s", self._data_list)
logger.debug("Parse input data_list %s", self._data_list)
data = self._data_list[0]

# If the KF Transformer and Explainer sends in data as bytesarray
if isinstance(data, (bytes, bytearray)):

data = data.decode()
data = json.loads(data)
logger.info("Bytes array is %s", data)
logger.debug("Bytes array is %s", data)

self._inputs = data.get("instances")
logger.info("KFServing parsed inputs %s", self._inputs)
logger.debug("KFServing parsed inputs %s", self._inputs)
return self._inputs

def format_output(self, data):
Expand All @@ -49,7 +48,7 @@ def format_output(self, data):
(list): The response is returned as a list of predictions and explanations
"""
response = {}
logger.info("The Response of KFServing %s", data)
logger.debug("The Response of KFServing %s", data)
if not self._is_explain():
response["predictions"] = data
else:
Expand Down
10 changes: 5 additions & 5 deletions ts/torch_handler/request_envelope/kfservingv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ def parse_input(self, data):
}]
"""
logger.info("Parsing input in KFServing v2 format %s", data)
logger.debug("Parsing input in KFServing v2 format %s", data)
inputs = self._batch_from_json(data)
logger.info("KFServingv2 parsed inputs %s", inputs)
logger.debug("KFServingv2 parsed inputs %s", inputs)
return inputs

def _batch_from_json(self, rows):
"""
Joins the instances of a batch of JSON objects
"""
logger.info("Parse input data %s", rows)
logger.debug("Parse input data %s", rows)
body_list = list(map(lambda body_list: body_list.get("body"), rows))
data_list = self._from_json(body_list)
return data_list
Expand All @@ -93,7 +93,7 @@ def _from_json(self, body_list):
if isinstance(body_list, (bytes, bytearray)):
body_list = body_list.decode()
body_list = json.loads(body_list)
logger.info("Bytes array is %s", body_list)
logger.debug("Bytes array is %s", body_list)
if "id" in body_list:
setattr(self.context, "input_request_id", body_list["id"])
data_list = list(
Expand All @@ -120,7 +120,7 @@ def format_output(self, data):
}
"""
logger.info("The Response of KFServing v2 format %s", data)
logger.debug("The Response of KFServing v2 format %s", data)
response = {}
if hasattr(self.context, "input_request_id"):
response["id"] = getattr(self.context, "input_request_id")
Expand Down

0 comments on commit bbba6d7

Please sign in to comment.