BentoML
BentoML copied to clipboard
bug: adaptive batching not work in mlflow model (gensim word2vec)
Describe the bug
gensim word2vec model
import os
import mlflow
from gensim.models.word2vec import Word2Vec
class ScappyWrapper(mlflow.pyfunc.PythonModel):
def load_context(self, context):
file_path = os.path.join(context.artifacts["model_path"], "scappy_base.bin")
self.model = Word2Vec.load(file_path)
def predict(self, _, model_input):
model_input = model_input[0].tolist()
return self.model.wv[model_input]
save_model
bentoml.mlflow.import_model(
tag,
model_uri=version.source,
signatures={"predict": {"batchable": True}},
)
service.py
import bentoml
from bentoml.io import JSON, NumpyNdarray
from constant import BUILD_NAME, MODEL_NAME
scappy_model = bentoml.mlflow.get(MODEL_NAME)
_scappy_runnable = scappy_model.to_runnable()
class ScappyRunnable(_scappy_runnable):
def __init__(self):
super().__init__()
@bentoml.Runnable.method(batchable=True)
def predict(self, input_series):
keywords = input_series["keywords"]
output = super().predict(keywords)
return output
scappy_runner = bentoml.Runner(ScappyRunnable)
svc = bentoml.Service(MODEL_NAME, runners=[scappy_runner])
@svc.api(
input=JSON(),
output=NumpyNdarray(),
route=BUILD_NAME,
)
async def predict(input_series):
output = await scappy_runner.predict.async_run(input_series)
return output
With these codes, it was confirmed that the service and the reference are operating normally But adaptive batching not work in bentoml with mlflow,, why not??
To reproduce
No response
Expected behavior
No response
Environment
python: 3.10.12 bentoml: 1.0.22 mlflow: 2.5.0 gensim: 4.3.2