MediumMLOps and LLMOps
How would you deploy a trained model as a production API, for example with MLflow and FastAPI?
Log the model with MLflow, register it, and point an alias such as champion at the version to serve. A FastAPI service loads that model once at start-up and validates every request against a Pydantic schema, so bad input gets a 422 error with details instead of a crash. Package it in a container, set timeouts on downstream calls and retry only safe ones, and monitor latency, errors and the distribution of inputs and predictions. Moving the alias rolls a new version forward, or back.
import fastapi, mlflow.pyfunc, pandas as pd
from pydantic import BaseModel
model = mlflow.pyfunc.load_model("models:/churn@champion") # loaded once, by alias
app = fastapi.FastAPI()
class Customer(BaseModel): # a wrong type gets a 422
tenure_months: int
monthly_charge: float
@app.post("/predict")
def predict(c: Customer):
return {"prediction": model.predict(pd.DataFrame([c.model_dump()])).tolist()[0]}Say your answer out loud first. Then check ours.