Slackbot
11/12/2020, 8:06 AMChaoyu
11/12/2020, 8:14 AMJian Shen Yap
11/13/2020, 8:29 AMJian Shen Yap
11/13/2020, 9:24 AMJian Shen Yap
11/13/2020, 9:35 AM[2020-11-13 17:10:08,117] ERROR - Traceback (most recent call last):
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/bentoml/marshal/marshal.py", line 210, in request_dispatcher
resp = await self.batch_handlers[api_name](req)
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/bentoml/marshal/dispatcher.py", line 141, in _func
raise r
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/bentoml/marshal/dispatcher.py", line 201, in outbound_call
outputs = await self.callback(tuple(d for _, d, _ in inputs_info))
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/bentoml/marshal/marshal.py", line 109, in _batch_handler_template
return await func(requests, api_name)
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/bentoml/marshal/marshal.py", line 286, in _batch_handler_template
return tuple(
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/bentoml/marshal/marshal.py", line 287, in <genexpr>
aiohttp.web.Response(body=i.body, headers=i.headers, status=i.status)
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/aiohttp/web_response.py", line 540, in __init__
super().__init__(status=status, reason=reason, headers=real_headers)
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/aiohttp/web_response.py", line 86, in __init__
self.set_status(status, reason)
File "/Users/jianshen/Desktop/Projects/reco-engine-v2/venv/lib/python3.8/site-packages/aiohttp/web_response.py", line 119, in set_status
self._status = int(status)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'Jian Shen Yap
11/13/2020, 10:22 AMi.status -> it is None. For testing purposes I modify is so that it will return 200 when i.status is None , and it successfully ran with the right predictionJian Shen Yap
11/14/2020, 3:04 AMChaoyu
11/14/2020, 8:21 PMJiang
11/15/2020, 3:09 AMJian Shen Yap
11/15/2020, 5:51 AMimport bentoml
import tensorflow as tf
import numpy as np
from bentoml.frameworks.tensorflow import TensorflowSavedModelArtifact
from bentoml.frameworks.keras import KerasModelArtifact
from bentoml.adapters import TfTensorInput
from bentoml.adapters import DataframeInput
import pandas as pd
@bentoml.env(infer_pip_packages=True)
# @bentoml.env(pip_packages=['tensorflow', 'numpy', 'pandas','scikit-learn', 'keras'])
@bentoml.artifacts([TensorflowSavedModelArtifact('model')])
class KerasModelService(bentoml.BentoService):
@bentoml.api(input=DataframeInput(), mb_max_latency=1000, batch=True)
def predict(self, df: pd.DataFrame):
int_oh = np.append(np.zeros((2048 - df.shape[0], df.shape[1])),df,axis=0)
exp_int_oh = np.expand_dims(int_oh, axis=1)
batch_preds = self.artifacts.model(exp_int_oh.astype('float32'))
preds_idx = tf.argsort(batch_preds,axis=-1,direction='DESCENDING',stable=False,name=None)
return tf.reverse(preds_idx,[0])Jian Shen Yap
11/15/2020, 5:53 AMJian Shen Yap
11/15/2020, 5:57 AMNone .Jian Shen Yap
11/15/2020, 5:57 AMJiang
11/16/2020, 3:21 AMJian Shen Yap
11/16/2020, 3:50 AMJiang
11/16/2020, 3:52 AMJiang
11/16/2020, 3:53 AMJian Shen Yap
11/16/2020, 4:12 AMclass KerasModelService(bentoml.BentoService):
@bentoml.api(input=DataframeInput(), mb_max_latency=1000, batch=True)
def predict(self, df: pd.DataFrame):
int_oh = np.append(np.zeros((2048 - df.shape[0], df.shape[1])),df,axis=0)
exp_int_oh = np.expand_dims(int_oh, axis=1)
batch_preds = self.artifacts.model(exp_int_oh.astype('float32'))
preds_idx = tf.argsort(batch_preds,axis=-1,direction='DESCENDING',stable=False,name=None)
rev = tf.reverse(preds_idx,[0])
return rev[:df.shape[0],:]
the same error still occurs.Jian Shen Yap
11/16/2020, 4:12 AMclass KerasModelService(bentoml.BentoService):
@bentoml.api(input=DataframeInput(), mb_max_latency=1000, batch=True)
def predict(self, df: pd.DataFrame):
int_oh = np.append(np.zeros((2048 - df.shape[0], df.shape[1])),df,axis=0)
exp_int_oh = np.expand_dims(int_oh, axis=1)
batch_preds = self.artifacts.model(exp_int_oh.astype('float32'))
preds_idx = tf.argsort(batch_preds,axis=-1,direction='DESCENDING',stable=False,name=None)
rev = tf.reverse(preds_idx,[0])
return "testing"
When i tested with a dummy string above, it will automatically truncate the string “testing” according to the size of the batch input, and it doesn’t throw an error for i.status , which makes me think that it is not the output length mismatch that causes this error to occurJian Shen Yap
11/16/2020, 4:28 AMrev is type of EagerTensor . After converting it to a ndarray and return it, microbatching works!Jiang
11/16/2020, 4:34 AMoutput=TfTensorOutput() like this?
class KerasModelService(bentoml.BentoService):
@bentoml.api(input=DataframeInput(), output=TfTensorOutput(), mb_max_latency=1000, batch=True)
def predict(self, df: pd.DataFrame):
int_oh = np.append(np.zeros((2048 - df.shape[0], df.shape[1])),df,axis=0)
exp_int_oh = np.expand_dims(int_oh, axis=1)
batch_preds = self.artifacts.model(exp_int_oh.astype('float32'))
preds_idx = tf.argsort(batch_preds,axis=-1,direction='DESCENDING',stable=False,name=None)
rev = tf.reverse(preds_idx,[0])
return rev[:df.shape[0],:]Jian Shen Yap
11/16/2020, 5:00 AMconvert_to_tensor
3. explicit specify output adapter TfTensorOutput()
4. creating a dummy tensor tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
None of these work, all of it throws the same error as i shown aboveJian Shen Yap
11/16/2020, 5:01 AMJiang
11/16/2020, 5:06 AMJian Shen Yap
11/16/2020, 6:18 AMJiang
11/18/2020, 3:50 AMJian Shen Yap
11/22/2020, 5:45 AMChaoyu
11/22/2020, 5:45 PM