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

Micro batch followup #3306

Merged
merged 3 commits into from
Jun 17, 2021
Merged
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
27 changes: 12 additions & 15 deletions python/seldon_core/batch_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def _send_batch_predict_multi_request(

indexes = [x[0] for x in input_data]
instance_ids = [x[1] for x in input_data]
first_prediction = input_data[0][2]

predict_kwargs = {}
meta = {
Expand All @@ -309,18 +308,10 @@ def _send_batch_predict_multi_request(

try:
# Initialise concatenated array for data
data = json.loads(first_prediction)
data_np = np.array(data)
concat = data_np
for i, raw_data in enumerate(input_data):
# Already added first item.
if i == 0:
continue
data = json.loads(raw_data[2])
data_np = np.array(data)
concat = np.concatenate((concat, data_np))
loaded = [json.loads(raw_data[2]) for raw_data in input_data]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, looks much better!

concat = np.concatenate(loaded)
predict_kwargs["data"] = concat

response = None
for i in range(retries):
try:
Expand Down Expand Up @@ -362,9 +353,9 @@ def _send_batch_predict_multi_request(
elif payload_type == "tensor":
# Format new responses for each original prediction request
new_response["data"]["tensor"]["shape"][0] = 1
new_response["data"]["tensor"]["values"] = [
np.ndarray.tolist(tensor_ndarray[i])
]
new_response["data"]["tensor"]["values"] = np.ndarray.tolist(
tensor_ndarray[i]
)
new_response["meta"]["tags"]["tags"]["batch_index"] = indexes[i]
new_response["meta"]["tags"]["tags"]["batch_instance_id"] = instance_ids[i]
responses.append(json.dumps(new_response))
Expand Down Expand Up @@ -450,6 +441,7 @@ def _send_batch_predict(
"status": {"info": "FAILURE", "reason": str(e), "status": 1},
"meta": meta,
}
print("Exception: %s" % e)
str_output = json.dumps(error_resp)

return str_output
Expand Down Expand Up @@ -526,6 +518,7 @@ def _send_batch_feedback(
"status": {"info": "FAILURE", "reason": str(e), "status": 1},
"meta": meta,
}
print("Exception: %s" % e)
str_output = json.dumps(error_resp)

return str_output
Expand Down Expand Up @@ -703,3 +696,7 @@ def run_cli(
benchmark,
batch_id,
)


if __name__ == "__main__":
run_cli()