雙語說明 | Bilingual Documentation
這是一個以 FastAPI + MLflow 為核心、搭配 Docker Compose 及 GitHub Actions CI/CD 的端到端 MLOps 框架,協助團隊快速完成:
- 🏗 模型生命週期管理 – 從資料處理、訓練、註冊、載入到線上推論,一條龍自動化。
- 🗂 實驗追蹤與版本控制 – 透過 MLflow 實驗與 Model Registry,精準記錄參數、指標與 Artifact。
- 🔌 RESTful 服務 – 使用 FastAPI 提供非同步
/train → /train-status → /register-model → /load-model → /predict流程。 - ♻️ 可重現與可擴充 – 容器化部署、乾淨的專案結構、完整單元與整合測試,方便 CI/CD 及多環境落地。
| 功能 | 說明 |
|---|---|
| 🚀 非同步訓練 | /train 端點將訓練任務丟入背景執行,API 即刻回應不阻塞 |
| 🔍 進度查詢 | /train-status 依 model_name 標籤回傳最近一次 run 狀態 |
| 🏷 自動註冊 | /register-model 偵測不到 Registry 時,自動建立 Registered Model 再創建版本 |
| 📦 快速載入 | /load-model 以 run_id 載入模型到記憶體,隨即可供 /predict 呼叫 |
| 🛠 CI/CD | GitHub Actions 針對測試、lint、Docker Build 自動化;可擴充為自動部署 |
This repository provides an end-to-end MLOps scaffold powered by FastAPI and MLflow, packaged with Docker Compose and wired into GitHub Actions.
Key goals:
- 🏗 Full model life-cycle – data → train → register → load → infer via REST endpoints.
- 🗂 Experiment tracking & versioning – MLflow captures parameters, metrics, and artifacts; Model Registry governs promotion flow.
- 🔌 Async REST services – non-blocking training endpoint with status polling for smooth UX.
- ♻️ Reproducible & extensible – containerised, test-driven, ready for CI/CD pipelines and multi-env deployment.
| Feature | Details |
|---|---|
| 🚀 Async training | /train schedules background tasks to keep the API responsive |
| 🔍 Progress check | /train-status returns the latest run state filtered by model_name tag |
| 🏷 Auto registration | /register-model creates a Registered Model on-the-fly when absent |
| 📦 Instant load | /load-model retrieves a model by run_id into memory for immediate /predict |
| 🛠 CI/CD ready | GitHub Actions for tests, lint, Docker build; extendable to deploy steps |
# 1. Build & launch Postgres, MLflow & FastAPI
$ docker compose up -d --build
# 2. Open UIs
MLflow : http://localhost:5000
docs : http://localhost:8000/docs
# 3. Tear down
$ docker compose down -v# Trigger async training
curl -X POST http://localhost:8000/train -H "Content-Type: application/json" -d '{"model_name":"iris-demo"}'
# Poll status
curl http://localhost:8000/train-status?model_name=iris-demo
# Register trained run
curl -X POST http://localhost:8000/register-model -H "Content-Type: application/json" \
-d '{"run_id":"<RUN_ID>", "model_name":"iris-demo"}'
# Load model into memory
curl -X POST http://localhost:8000/load-model -H "Content-Type: application/json" \
-d '{"run_id":"<RUN_ID>"}'
# Predict
curl -X POST http://localhost:8000/predict -H "Content-Type: application/json" \
-d '{"data":[[5.1,3.5,1.4,0.2]]}'mlops-framework/
├── serving/ # FastAPI service (Dockerfile, main.py)
├── src/ # Core library (data, train, pipeline, utils)
├── tests/ # Unit & integration tests (pytest)
├── docker-compose.yml
├── .github/workflows/
└── README.md
- JWT/OAuth2 authentication
- Promotion API (
/promote) for stage transitions - Kubernetes manifests & Helm chart
MIT © 2025 atgenomix
一個基於 MLflow 和 FastAPI 的 MLOps 框架,用於訓練、追蹤和部署機器學習模型。
- 🚀 使用 MLflow 追蹤實驗和模型版本控制
- 🎯 支援即時推論 API (FastAPI)
- 📦 容器化部署 (Docker + Docker Compose)
- 🔄 CI/CD 自動化測試與部署
- 🧪 完整的單元測試與整合測試
mlops-framework/
├── .github/workflows/ # GitHub Actions 工作流程
│ └── ci-cd.yml # CI/CD 設定
├── configs/ # Hydra 設定檔
│ ├── config.yaml # 主設定檔
│ └── ...
├── data/ # 資料目錄 (DVC 追蹤)
├── serving/ # API 服務程式碼
│ ├── Dockerfile # API 服務容器設定
│ └── main.py # FastAPI 應用程式
├── src/ # 原始碼
│ ├── mlops_framework/ # 核心套件
│ │ ├── __init__.py
│ │ ├── data.py # 資料處理
│ │ ├── pipeline.py # 管線邏輯
│ │ └── train.py # 訓練邏輯
│ └── cli.py # 命令列介面
├── tests/ # 測試程式碼
│ ├── conftest.py # pytest 設定
│ └── test_pipeline.py # 單元測試
├── .gitignore
├── docker-compose.yml # 服務編排
├── Dockerfile.mlflow # MLflow 服務容器設定
├── pyproject.toml # Python 專案設定
└── README.md
├── pyproject.toml # 專案定義與依賴
└── README.md # 說明文件
## Quickstart
1. Build and start all services (Postgres, MLflow, FastAPI):
```bash
docker compose up -d --build
- Open the UIs:
- MLflow Tracking Server: http://localhost:5000
- FastAPI docs (Swagger): http://localhost:8000/docs
- Stop services:
docker compose downOn your development laptop, create a virtual environment and install dependencies:
poetry install # or pip install -r requirements.txt if you export one
uvicorn serving.main:app --reload --port 8000 --host 0.0.0.0Set the environment variable so the API connects to your desktop MLflow server:
export MLFLOW_TRACKING_URI=http://<desktop-ip>:5000