全部產品
Search
文件中心

Container Service for Kubernetes:配置MLflow模型倉庫

更新時間:Jun 19, 2024

MLflow是一個開源的機器學習生命週期管理平台,可以用來追蹤模型訓練資訊、管理和部署機器學習模型。本文介紹如何為模型管理功能配置MLflow模型倉庫。

MLflow模型倉庫介紹

關於MLflow模型倉庫功能的詳細介紹,請參見MLflow Model Registry — MLflow documentation

前提條件

  • 已建立ACK Pro叢集且Kubernetes版本不低於1.20。具體操作,請參見建立ACK Pro版叢集

  • 已建立RDS PostgreSQL執行個體。具體操作,請參見建立RDS PostgreSQL執行個體

    建議建立RDS PostgreSQL執行個體時優先選擇ACK叢集所在的VPC並將VPC所在的網段加入白名單,這樣可以使用內網地址訪問資料庫。如果RDS執行個體和ACK叢集位於不同的VPC內,請確保RDS開啟了公網訪問,並將ACK叢集的VPC網段加入白名單中。具體操作,請參見設定白名單

  • 在RDS PostgreSQL執行個體中建立一個名為mlflow的普通帳號。具體操作,請參見建立帳號

  • 在RDS PostgreSQL執行個體建立一個名為mlflow_store的資料庫用於儲存模型中繼資料,並將其授權帳號設定為mlflow帳號。具體操作,請參見建立資料庫

  • (可選)在RDS PostgreSQL執行個體建立一個名為mlflow_basic_auth的資料庫用於儲存MLflow使用者認證資訊,並將其授權帳號設定為mlflow帳號。具體操作,請參見建立資料庫

  • 已配置Arena用戶端用於進行模型管理,Arena版本需為0.9.14及以上版本。具體操作,請參見配置Arena用戶端

步驟一:在ACK叢集中部署MLflow

  1. 登入Container Service管理主控台,在左側導覽列選擇叢集

  2. 叢集列表頁面,單擊目的地組群名稱,然後在左側導覽列,選擇應用 > Helm

  3. 單擊建立,然後在建立頁面,將應用程式名稱設定為mlflow命名空間設定為kube-ai,在Chart地區的搜尋欄搜尋並選中mlflow,完成後單擊下一步,在彈出的對話方塊中,確認是否採用mlflow為Chart的預設的命名空間。

    • 如果需要通過AI套件開發控制台進行模型管理,需要將mlflow部署在kube-ai命名空間中,發布名稱需保持為預設值mlflow

    • 如果需要通過Arena進行模型管理,可以將Mlflow部署在任意命名空間中,但是發布名稱需保持為預設值mlflow

  4. 建立頁面,配置Chart的參數。

    1. 配置defaultArtifactRootbackendStore參數,配置樣本如下所示。

      trackingServer:
        # -- Specifies which mode mlflow tracking server run with, available options are `serve-artifacts`, `no-serve-artifacts` and `artifacts-only`
        mode: no-serve-artifacts
        # -- Specifies a default artifact location for logging, data will be logged to `mlflow-artifacts/:` if artifact serving is enabled, otherwise `./mlruns`
        defaultArtifactRoot: "./mlruns"
        
      # For more information about how to configure backend store, please visit https://mlflow.org/docs/latest/tracking/backend-stores.html
      backendStore:
        # -- Backend store uri e.g. `<dialect>+<driver>://<username>:<password>@<host>:<port>/<database>`
        backendStoreUri: postgresql+psycopg2://mlflow:<password>@pgm-xxxxxxxxxxxxxx.pg.rds.aliyuncs.com/mlflow_store

      其中,backendStore.backendStoreUri請替換成前提條件中建立的mlflow_store資料庫訪問地址,例如postgresql+psycopg2://mlflow:<password>@pgm-xxxxxxxxxxxxxx.pg.rds.aliyuncs.com/mlflow_store

    2. (可選)如需開啟BasicAuth,請配置如下參數。

      trackingServer:
        # -- Specifies which mode mlflow tracking server run with, available options are `serve-artifacts`, `no-serve-artifacts` and `artifacts-only`
        mode: no-serve-artifacts
        # -- Specifies a default artifact location for logging, data will be logged to `mlflow-artifacts/:` if artifact serving is enabled, otherwise `./mlruns`
        defaultArtifactRoot: "./mlruns"
        
        # Basic authentication configuration,
        # for more information, please visit https://mlflow.org/docs/latest/auth/index.html#configuration
        basicAuth:
          # -- Specifies whether to enable basic authentication
          enabled: true
          # -- Default permission on all resources, available options are `READ`, `EDIT`, `MANAGE` and `NO_PERMISSIONS`
          defaultPermission: NO_PERMISSIONS
          # -- Database location to store permissions and user data e.g. `<dialect>+<driver>://<username>:<password>@<host>:<port>/<database>`
          databaseUri: postgresql+psycopg2://<username>:<password>@pgm-xxxxxxxxxxxxxx.pg.rds.aliyuncs.com/mlflow_basic_auth
          # -- Default admin username if the admin is not already created
          adminUsername: admin
          # -- Default admin password if the admin is not already created
          adminPassword: password
          # -- Function to authenticate requests
          authorizationFunction: mlflow.server.auth:authenticate_request_basic_auth
          
      # For more information about how to configure backend store, please visit https://mlflow.org/docs/latest/tracking/backend-stores.html
      backendStore:
        # -- Backend store uri e.g. `<dialect>+<driver>://<username>:<password>@<host>:<port>/<database>`
        backendStoreUri: postgresql+psycopg2://mlflow:<password>@pgm-xxxxxxxxxxxxxx.pg.rds.aliyuncs.com/mlflow_store
      • 替換trackingServer.basicAuth.databaseUri為前提條件中建立的mlflow_basic_auth資料庫的訪問地址,例如postgresql+psycopg2://<username>:<password>@pgm-xxxxxxxxxxxxxx.pg.rds.aliyuncs.com/mlflow_basic_auth

      • 修改trackingServer.basicAuth.adminUsernametrackingServer.basicAuth.adminPassword參數來配置MLflow管理員的使用者名稱和初始密碼(僅在管理使用者還未建立時才會建立管理使用者)。

    關於MLflow完整的參數配置,請參見MLflow

步驟二:訪問部署在Kubernetes上的MLflow Web UI

  1. 執行以下命令,將MLflow Web UI服務轉寄到本地的5000連接埠。

    kubectl port-forward -n kube-ai services/mlflow 5000

    預期輸出:

    Forwarding from 127.0.0.1:5000 -> 5000
    Forwarding from [::1]:5000 -> 5000
    Handling connection for 5000
    Handling connection for 5000
    ...
  2. 從瀏覽器訪問http://127.0.0.1:5000查看MLflow Web UI。

    image

後續操作:模型管理

雲原生AI套件支援對MLflow模型倉庫中的模型進行管理,關於如何使用雲原生AI套件開發控制台和Arena命令列工具進行模型管理,請參見對MLflow模型倉庫中的模型進行管理