MLflow
MLflow
An open-source ML lifecycle management platform. Supports experiment tracking and model deployment.
MLflow
An open-source ML lifecycle management platform. Supports experiment tracking and model deployment.
MLflow is an open-source ML lifecycle management platform developed by Databricks. It provides four core components — experiment tracking (Tracking), project packaging (Projects), model management (Models), and a model registry (Registry) — to manage the entire ML workflow.
It was announced in 2018 by the Databricks team led by Matei Zaharia (creator of Spark). It was started to solve the "problem of irreproducible ML experiments," and with more than 18,000 GitHub stars today, it is one of the most widely used MLOps tools.
MLflow Tracking automatically records parameters, metrics, and artifacts and visualizes them in a UI. Model Registry provides model version management, stage (Staging/Production) transitions, and approval workflows. MLflow is compatible with all major frameworks, including PyTorch, TensorFlow, and Scikit-learn.
In practice, MLflow has become established as a standard tool for experiment management. It lets you systematically compare hundreds of experiments, deploy the best model with one click, and even serve it through a REST API. It is integrated with Databricks, AWS SageMaker, Azure ML, and more, so it is also used in enterprise environments.
import mlflow
import mlflow.pytorch
import torch
import torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset
# MLflow 설정
mlflow.set_tracking_uri("sqlite:///mlflow.db")
mlflow.set_experiment("pytorch_classifier")
# 간단한 모델 정의
class SimpleNet(nn.Module):
def __init__(self, input_dim, hidden_dim, output_dim):
super().__init__()
self.fc1 = nn.Linear(input_dim, hidden_dim)
self.fc2 = nn.Linear(hidden_dim, output_dim)
self.relu = nn.ReLU()
def forward(self, x):
return self.fc2(self.relu(self.fc1(x)))
# 하이퍼파라미터
config = {
"input_dim": 20,
"hidden_dim": 64,
"output_dim": 2,
"learning_rate": 0.001,
"epochs": 10,
"batch_size": 32
}
# MLflow autolog 활성화 (PyTorch 자동 추적)
mlflow.pytorch.autolog()
with mlflow.start_run(run_name="pytorch_simple_net"):
# 하이퍼파라미터 로깅
mlflow.log_params(config)
# 모델 초기화
model = SimpleNet(config["input_dim"], config["hidden_dim"], config["output_dim"])
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=config["learning_rate"])
# 더미 데이터 생성
X = torch.randn(1000, config["input_dim"])
y = torch.randint(0, 2, (1000,))
dataset = TensorDataset(X, y)
loader = DataLoader(dataset, batch_size=config["batch_size"])
# 학습 루프
for epoch in range(config["epochs"]):
total_loss = 0
for batch_X, batch_y in loader:
optimizer.zero_grad()
outputs = model(batch_X)
loss = criterion(outputs, batch_y)
loss.backward()
optimizer.step()
total_loss += loss.item()
avg_loss = total_loss / len(loader)
mlflow.log_metric("train_loss", avg_loss, step=epoch)
print(f"Epoch {epoch+1}: Loss = {avg_loss:.4f}")
# 모델 저장
mlflow.pytorch.log_model(model, "model")
# 모델 레지스트리에 등록
run_id = mlflow.active_run().info.run_id
model_uri = f"runs:/{run_id}/model"
mlflow.register_model(model_uri, "SimpleClassifier")
print("MLflow UI: http://localhost:5000")
# mlflow ui --port 5000 으로 실행
The following are MLflow costs by option as of January 2025.
| Option | Price | Features |
|---|---|---|
| MLflow Open Source | Free (Apache 2.0) | Self-hosted, full features |
| Databricks MLflow | Databricks pricing included | $0.20/DBU~ |
| AWS SageMaker MLflow | From $0.07/hour | Managed server |
| Azure ML MLflow | Azure ML pricing included | Integrated environment |
| Estimated self-hosted infrastructure | Cost | Notes |
|---|---|---|
| EC2 (t3.medium) | $30/month | Server for small teams |
| RDS PostgreSQL | From $15/month | Metadata store |
| S3 storage | $0.023/GB | Artifact storage |
Enterprise features (Databricks): Unity Catalog integration, Feature Store, Model Serving autoscaling, governance.
"All 150 experiments we ran over the last quarter are logged in MLflow. The best model is Run ID abc123, which achieved an F1 of 0.92 and is currently deployed to the Production stage."
"Of MLflow's four components, Tracking handles experiment logging, Projects handles code packaging, Models handles standardizing the model format, and Registry handles version management and deployment approval. The autolog feature enables automatic tracking in most frameworks."
"MLflow model serving can be deployed directly as a REST API with the mlflow models serve command. In production environments, you integrate it with Seldon Core or KServe, or use MLflow's Docker build feature to deploy to Kubernetes."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Storing only locally with the default settings makes team collaboration impossible and risks data loss.
Set up PostgreSQL/MySQL as the backend and S3/GCS as the artifact store. The whole team needs to share a single MLflow server to compare experiment results effectively.