This message was deleted.
# ask-for-help
s
This message was deleted.
👀 1
🍱 1
b
@Amar Ramesh Kamat can you share your code?
And what error you are seeing?
a
Let me try to share as much as I can 🙂
b
sounds good
a
Copy code
import tensorflow as tf
import bentoml
=
service = 'foo'
model_name = 'bar'
model_dir = "models/" + model_name

model = tf.saved_model.load(model_dir)
    
bentoml_model = bentoml.tensorflow.save_model(
    service,
    model,
    signatures={"__call__": {"batchable": False}}
)
Here, I have a TF-2.x model on my local disk. I am loading it and then saving it via bento wrapper
y
How do you run the inference? How does the expected input looks like?
There are some nice ways to debug it, such as wrapping your inference function in another function to make sure there are no alterations by BentoML to the input
a
Here is how the service.py looks like
Copy code
import numpy as np
import bentoml
import tensorflow as tf
from PIL import Image
from <http://bentoml.io|bentoml.io> import JSON
from bentoml._internal.types import JSONSerializable

model_name = 'bar'
# tried model = bentoml.model.get(model_name + ":latest") too
model = bentoml.tensorflow.get(model_name + ":latest")
runner = model.to_runner()

svc = bentoml.Service(model_name, runners=[runner])

@svc.api(input=JSON(), output=JSON())
async def predict(json_obj: JSONSerializable) -> JSONSerializable:
    retur await runner.async_run([json_obj])
l
Currently our tensorflow v2 implementation only accept list/tensor/ndarray inputs. Could you do the custom processing outside the model?
a
We can. Just that its a change to the existing system.
Currently our tensorflow v2 implementation only accept list/tensor/ndarray inputs.
That’s what I expected.
There are some nice ways to debug it, such as wrapping your inference function in another function to make sure there are no alterations by BentoML to the input
Are you referring to custom wrappers?
l
Actually our implementation also expected model outputs to be ndarray/tensor. Because in our own pass experience the inputs and outputs of a tensorflow model are usually tensor-like objects. Do you think there are a lot of usage for non tensor inputs/outputs?
a
Yes. Majority of the models we have is deployed via TF Serving and the easiest way to do some custom pre-post processing was to wrap the model like this.
j
Could you do a couple of custom Runners to do your pre- and post-processing?
l
Amar, Thanks for your input. It's very helpful for us to decide which features we should support. If possible, could you point me some resource (tutorial etc.) for this kinds of usage so we can study and try to add support for it?
For now I think you can separate model and processing code, or try custom runner routine like Jim says.
y
Are you referring to custom wrappers?
Not exactly. You can take your already initialized model (when saving the models to BentoML), add a function to it that calls your actual predict or call functions. And then you can simply run code before and after the model inference. For example I had a response from my inference that wasn't compatible with BentoML's expectations so thats what I did:
Copy code
def pytorch_predict(self, d):
    return [x.pandas().xyxy for x in self(d).tolist()]

model.custom_predict = types.MethodType(pytorch_predict, model)
a
Thanks @Yakir Saadia @larme (shenyang) @Jim Rohrer . Will try out these suggestions and get back