A BentoML Runnable packages model computation into a reusable execution unit. Its constructor initializes the model, while methods marked with @bentoml.Runnable.method become remotely invocable through a BentoML Service. section 10.4.1
import bentoml
import json
from ultralytics import YOLO
class YOLOv8Runnable(bentoml.Runnable):
def __init__(self):
self.model = YOLO("yolov8_custom.pt")
@bentoml.Runnable.method(batchable=False) #1
def inference(self, input_img): #2
results = self.model(input_img)[0] #3
return json.loads(results[0].tojson()) #4
A YOLOv8 Runnable loads weights directly, exposes non-batchable image inference, selects the first result, and returns JSON-compatible output. section 10.4.1
Register the Runnable with bentoml.Runner, attach that Runner to a Service, and invoke its method asynchronously from an API endpoint. Direct constructor loading keeps the first service simple; model registry features support later versioning and dynamic loading. section 10.4.1
