Exporting a PyTorch model to ONNX and running it with ONNX Runtime
Moving the model from the training environment to a standalone inference environment and checking that the outputs match.
Goal: Turning a model into an HTTP service that can be packaged in a container.
# service.py
import bentoml
import numpy as np
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
@bentoml.service(resources={"cpu": "1"})
class Classifier:
def __init__(self):
X, y = load_iris(return_X_y=True)
self.model = LogisticRegression(max_iter=500).fit(X, y)
@bentoml.api
def predict(self, features: list[list[float]]) -> list[int]:
return self.model.predict(np.array(features)).tolist()
The class decorated with @bentoml.service represents the service, and each @bentoml.api function becomes an endpoint. Run the service with bentoml serve service:Classifier. We did not run the server in the test environment, so no output is shown.
This example was not run in the test environment: needs an HTTP server running (bentoml serve). Check it against the library documentation before relying on it.
Moving the model from the training environment to a standalone inference environment and checking that the outputs match.
Sections
No section has this name. Press “Search” to search all site content.
Favourites
My results & certificates
My academy progressMy quiz resultsKids’ progressAcademy certificatesQuiz certificatesStart any lesson or quiz and it will show up here so you can get back to it quickly.
Settings
I am the AI Frameworks & Libraries Assistant. Describe your project or ask me about a library, a comparison or a code example, and I will answer from the encyclopedia's database with links and sources.
Answers from the encyclopedia's database only, without a language model and without sending your question to any third party.
The assistant can make mistakes, so check the attached sources.