writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
register-ml-modelRegister trained models in MLflow Model Registry with version control, implement stage transitions (Staging, Production, Archived) with approval workflows, and manage model lineage with comprehensive metadata and deployment tracking. Use when promoting a trained model from experimentation to production, managing multiple model versions across development st…
Independent GitHub snapshot · Automated classification · Original documentation governs
於 MLflow Model Registry 註已訓之模附版控、行階轉(Staging、Production、Archived)附審流、管模系附詳屬與部署之追。
See Extended Examples for complete configuration files and templates.
施 MLflow Model Registry 以系統行模之版、階管、部署治。
立 MLflow Model Registry 附庫後端(產不宜檔基庫)。
# Start MLflow server with Model Registry support
mlflow server \
--backend-store-uri postgresql://user:pass@localhost:5432/mlflow \
--default-artifact-root s3://mlflow-artifacts/models \
--host 0.0.0.0 \
--port 5000
Python 配置:
# model_registry_config.py
import mlflow
from mlflow.tracking import MlflowClient
# Set tracking URI (must support Model Registry)
MLFLOW_TRACKING_URI = "http://mlflow-server.company.com:5000"
mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)
# ... (see EXAMPLES.md for complete implementation)
得:Model Registry 之頁現於 MLflow,search_registered_models() 順返(雖空),庫含 registered_models 表。
敗則:驗 MLflow 版 ≥1.2(Model Registry 始於 1.2),察庫後端(SQLite 不全持 Model Registry),確 --backend-store-uri 指庫(非 file://),驗庫之用戶有 CREATE TABLE 之權,察 MLflow 服日誌之遷誤。
註已錄之模於 Model Registry 附詳屬。
# register_model.py
import mlflow
from mlflow.tracking import MlflowClient
from model_registry_config import MLFLOW_TRACKING_URI
mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)
client = MlflowClient()
# ... (see EXAMPLES.md for complete implementation)
得:新模版現於 Model Registry 之 UI,版含述與標,模件可由 models:/<model-name>/<version> URI 取,模簽與入例已存。
敗則:驗 run_id 存且已畢(client.get_run(run_id)),察模件路合錄之件(mlflow.search_runs() 以察),確模以正之框錄(mlflow.sklearn.log_model 非 mlflow.log_artifact),驗模名無特字(用短橫非下橫),察件存可訪。
行模版過諸階(None → Staging → Production → Archived)附驗察。
# stage_management.py
import mlflow
from mlflow.tracking import MlflowClient
from datetime import datetime
client = MlflowClient()
class ModelStageManager:
# ... (see EXAMPLES.md for complete implementation)
得:模版之階更於庫,舊版自存檔,轉之時錄於標,退復前產之版。
敗則:察版存且於望階,驗 archive_existing_versions 旗之行(若僅一版或不檔),確庫持並發以更階,察階轉之鎖(一版一時一轉),驗審流之集成。
用模別名以行穩之部署引(MLflow ≥2.0)。
# model_aliases.py
from mlflow.tracking import MlflowClient
client = MlflowClient()
def set_model_alias(model_name, version, alias):
"""
Set an alias for a model version (MLflow 2.0+).
# ... (see EXAMPLES.md for complete implementation)
得:別名現於 Model Registry 之 UI,由別名載模可(models:/name@alias),更別名立影新載,A/B 試之基設可行。
敗則:升 MLflow 至 ≥2.0 以原生持別名,老版退用標基,驗別名之命(獨字母數字與短橫),察別名之衝(一模版一別名)。
追自數據至部署之全系附詳屬。
# model_lineage.py
import mlflow
from mlflow.tracking import MlflowClient
import json
client = MlflowClient()
def enrich_model_metadata(model_name, version, lineage_data):
# ... (see EXAMPLES.md for complete implementation)
得:模版之標含詳系信,get_model_lineage() 返全史,JSON 報含數源、訓細、部署信。
敗則:驗標值為串(化字典為 JSON),察標鍵之命(無空或特字),確系資於訓時捕,驗 run_id 有效可訪。
集模註於 CI/CD 線以自動升。
# .github/workflows/model_promotion.yml
name: Model Promotion Pipeline
on:
workflow_dispatch:
inputs:
model_name:
description: 'Model name to promote'
# ... (see EXAMPLES.md for complete implementation)
Python 自動文:
# scripts/promote_model.py
import argparse
from stage_management import ModelStageManager
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--model-name", required=True)
parser.add_argument("--version", type=int, required=True)
# ... (see EXAMPLES.md for complete implementation)
得:GitHub Actions 流於手動發起,驗試過,模升至目階,Slack 報送,部署線自起。
敗則:察 GitHub secrets 之 MLFLOW_TRACKING_URI 配置,驗自 GitHub Actions 至 MLflow 服之網訪(或需 VPN 或 IP 許列),確驗本有正指閾,察 Slack webhook 配置,驗 Python 文之執權。
archive_existing_versions=True 自檔track-ml-experiments — 註前先錄模於 MLflowdeploy-ml-model-serving — 部署已註之模至供基設run-ab-test-models — 用庫之別名行 A/B 模試orchestrate-ml-pipeline — 自動模訓與註version-ml-data — 版訓數據以資模系