This message was deleted.
# ask-for-help
s
This message was deleted.
s
That's odd, I don't believe
get_label
is something we create, maybe it's an issue on the model side?
Oh, I see what you mean. I believe you should just be able to add
get_label
to a custom runner; see https://docs.bentoml.org/en/latest/concepts/runner.html#custom-runner.
n
@sauyon Unfortunately I don't think I can do that - it insists that the custom method should be in the
Runner
class. If I add it to the customer runner (inheriting
Runnable
), it doesn't find it in scope.
s
I'm not sure what you mean, have can you send me your Runnable code?
n
Sure thing! It's nothing fancy:
Copy code
class FastaiRunnable(bentoml.Runnable):
    SUPPORTED_RESOURCES = ("cpu",)
    SUPPORTS_CPU_MULTI_THREADING = True

    def __init__(self):
        
        MODEL_CLASSIFICATION = pipeline_info["models"]["fov_classification"]

        artifact_file_classification = get_wandb_data(MODEL_CLASSIFICATION)

        self.learner = load_learner(artifact_file_classification, cpu=True)
        self.learner.eval()

        print("FastaAI setup complete!")

    @bentoml.Runnable.method(batchable=False)
    def predict(self, input):
        return self.learner.predict(np.asarray(input))
If I add
get_label
in
FastaiRunnable
, it can't find it in scope. As mentioned above, the only way I got it to find
get_label
in scope is to add it to
bentoml_cli/worker/runner.py
. I am probably missing something obvious 🙂
s
It should be able to get the method from the runnable, can you send me the code with that extra method?
n
It's the same as above, I don't have the stack trace handy (will be able to reproduce later today), but it was complaining that
get_label
cannot be found in the
<local>...<Runner>
scope (paraphrased). Hence why I even tried to add it to
Runner
in the first place.
s
If you look at line 290 in runner.py, you'll notice that it should be setting all the methods from the runnable as methods on the main object.
If it doesn't work, that's a bug!
n
Do you know if this is a new feature by any chance? I am using
1.0.5
as this is what we currently have in production. Otherwise it might be a bug indeed!
s
It should have been in since before 1.0, I believe, though I'm not 100% sure, I can double check.
Hm, this seems to work for me:
Copy code
@bentoml.Runnable.method()
    def get_label(self, label: str) -> str:
        return "test" + label
Copy code
fastai_runnable.get_label.run("label")
👀 1
n
If it makes any difference this is run through the cli (docker deployment).
I will give this a go
@sauyon I tried this but still getting the same error, presumably because the method signature now has
self
(also tried without
self
).
Copy code
AttributeError: Custom classes or functions exported with your `Learner` not available in namespace.\Re-declare/import before loading:
        Can't get attribute 'get_label' on <module 'bentoml_cli.worker.runner' from '/usr/local/lib/python3.8/site-packages/bentoml_cli/worker/runner.py'>
s
That's odd, would you be able to send me a reproducer?