MLOps is the practice of unifying ML system development (modeling) and operations (deployment, monitoring) to enable reliable, reproducible, and scalable AI. MLflow and BentoML together let you capture model lineage, version artifacts, and spin up production‑grade inference endpoints with minimal code.
Step‑by‑step workflow
1. Initialize an MLflow experiment
```python
import mlflow
mlflow.set_experiment("customer_churn")
```
2. Log data version and preprocessing
```python
mlflow.log_artifact("data/v1/customers.parquet")
mlflow.log_params({"impute_strategy": "median", "scale": "standard"})
```
3. Train and log the model (PyTorch example)
```python
import torch
model = MyNet()
# training loop …
mlflow.pytorch.log_model(model, "model")
```
4. Register the run as a model version
```python
model_uri = f"runs:/{mlflow.active_run().info.run_id}/model"
mlflow.register_model(model_uri, "ChurnPredictor")
```
5. Create a BentoML service that pulls the registered model
```python
import bentoml
from bentoml.io import JSON
@bentoml.service(resources={"cpu": "2", "memory": "4Gi"})
class ChurnService:
@bentoml.artifact
def model(self):
return bentoml.pytorch.load_model("ChurnPredictor:latest")
@bentoml.api(input=JSON())
def predict(self, input_json):
tensor = torch.tensor(input_json["features"])
return {"prob": self.model(tensor).item()}
```
6. Deploy
- Local: bentoml serve ChurnService:latest
- Kubernetes: bentoml containerize ChurnService:latest && helm install ml‑service ./helm-chart
MLflow vs. BentoML (quick compare)
| Aspect | MLflow | BentoML |
|-----------------|--------------------------------|---------------------------------|
| Primary goal | Experiment tracking & model registry | Model serving & containerization |
| Artifact store | File system, S3, GCS, Azure | Same as MLflow (reuse) |
| Endpoint type | None (requires custom code) | REST/gRPC automatically generated |
| Auto‑scaling | No built‑in | Integrates with K8s/HPA |
Follow the steps, keep the same run_id across logs, and you obtain a full lineage trace from raw data to live endpoint.