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
全配檔與模、見 Extended Examples。
於 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 UI 籤現於 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 密配 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 - 版訓數以模譜