共用方式為


MLflow 和 Azure Machine Learning

適用於:Azure CLI ml 延伸模組 v2 (目前)Python SDK azure-ai-ml v2 (目前)

本文會說明 MLflow (英文) 的功能,這是一種開放原始碼架構,旨在管理完整的機器學習生命週期。 MLflow 會使用一致的工具組,在不同的平台上定型及提供模型。 無論您的實驗是在本機或遠端計算目標、虛擬機器或 Azure Machine Learning 計算執行個體上執行,都可以使用 MLflow。

Azure Machine Learning 工作區與 MLflow 相容,這表示您可以採取與使用 MLflow 伺服器相同的方式使用 Azure Machine Learning 工作區。 此相容性具有下列優點:

  • Azure Machine Learning 不會裝載 MLflow 伺服器執行個體,但可以直接使用 MLflow API。
  • 您可使用 Azure Machine Learning 工作區,作為任何 MLflow 程式碼的追蹤伺服器,無論其是否在 Azure Machine Learning 中執行。 您只需要將 MLflow 設定為指向追蹤應該發生的工作區。
  • 您可以在 Azure Machine Learning 中執行任何使用 MLflow 的定型常式,而無需進行任何變更。

提示

不同於 Azure Machine Learning SDK v1,Azure Machine Learning v2 SDK 中沒有記錄功能。 您可以使用 MLflow 記錄來確保您的定型常式與雲端無關、可攜,並且對 Azure Machine Learning 不具有任何相依性。

使用 MLflow 進行追蹤

Azure Machine Learning 會使用 MLflow 追蹤來記錄計量,並儲存實驗的成品。 當您連線到 Azure Machine Learning 時,所有 MLflow 追蹤都會您正在使用的工作區中具體化。

若要了解如何為實驗和定型常式設定 MLflow 追蹤,請參閱使用 MLflow 記錄計量、參數和檔案 (英文)。 您也可以使用 MLflow 查詢、比較實驗和執行 (英文)。

Azure Machine Learning 中的 MLflow 可讓您集中追踪。 即使您在本機工作或在不同的雲端中工作,也可以將 MLflow 連線到 Azure Machine Learning 工作區。 Azure Machine Learning 工作區會提供集中、安全且可擴充的位置來儲存定型計量和模型。

Azure Machine Learning 中的 MLflow 可以:

在 R 中使用 MLflow 進行追蹤

R 中的 MLflow 支援有下列限制:

  • MLflow 追蹤受限於追蹤 Azure Machine Learning 作業上的實驗計量、參數和模型。
  • 不支援使用 RStudio、Posit (先前稱為 RStudio Workbench) 或具有 R 核心的 Jupyter 筆記本進行互動式訓練。
  • 不支援模型管理和註冊。 使用 Azure Machine Learning CLI 或 Azure Machine Learning 工作室進行模型註冊和管理。

如需在 Azure Machine Learning 中搭配 R 模型使用 MLflow 追蹤用戶端的範例,請參閱使用 Azure Machine Learning CLI (v2) 定型 R 模型 (英文)。

在 Java 中使用 MLflow 進行追蹤

Java 中的 MLflow 支援有下列限制:

  • MLflow 追蹤受限於追蹤 Azure Machine Learning 作業上的實驗計量和參數。
  • 無法追蹤成品和模型。 或者,在作業中搭配 outputs 資料夾使用 mlflow.save_model 方法來儲存您想要擷取的模型或成品。

如需使用搭配 Azure Machine Learning 追蹤伺服器使用 MLflow 追蹤用戶端的 Java 範例,請參閱 azuremlflow-java (英文)。

MLflow 追蹤的範例筆記本

使用 MLflow 進行模型註冊

Azure Machine Learning 支援用於模型管理的 MLflow。 對於熟悉 MLflow 用戶端的使用者來說,此支援是管理整個模型生命週期相當便利的方式。 如需有關如何使用 Azure Machine Learning 中的 MLflow API 來管理模型的詳細資訊,請參閱使用 MLflow 管理 Azure Machine Learning 中的模型登錄 (英文)。

MLflow 模型註冊的範例筆記本

使用 MLflow 進行模型管理 (英文) 會示範如何管理登錄中的模型。

使用 MLflow 進行模型部署

您可以將 MLflow 模型部署至 Azure Machine Learning,以利用更好的體驗。 Azure Machine Learning 支援將 MLflow 模型部署至即時和批次端點,而不需要指定環境或評分指令碼。

MLflow SDK、Azure Machine Learning CLI、適用於 Python 的 Azure Machine Learning SDK 以及 Azure Machine Learning 工作室全都支援 MLflow 模型部署。 如需有關如何將 MLflow 模型部署至 Azure Machine Learning 以進行即時和批次推斷的詳細資訊,請參閱部署 MLflow 模型的指導方針

MLflow 模型部署的範例筆記本

使用 MLflow 專案來定型 (預覽)

警告

Azure Machine Learning 中的 MLproject 檔案 (MLflow 專案) 支援將於 2026 年 9 月完全淘汰。 MLflow 仍然完全支援,而且仍然是追蹤 Azure Machine Learning 中機器學習工作負載的建議方式。

當您繼續使用 MLflow 時,建議您使用 Azure CLI 或適用於 Python 的 Azure Machine Learning SDK (v2),從 MLproject 檔案轉換至 Azure Machine Learning 作業。 如需 Azure Machine Learning 作業的詳細資訊,請參閱使用 MLflow 追蹤 ML 實驗和模型

重要

此功能目前處於公開預覽。 此預覽版本沒有服務等級協定,不建議用於處理生產工作負載。 可能不支援特定功能,或可能已經限制功能。

如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

您可以使用 MLflow 專案 (英文) 將定型作業提交至 Azure Machine Learning。 您可以使用 Azure Machine Learning 追蹤在本機提交作業,或透過 Azure Machine Learning Compute 將您的作業移轉至雲端。

若要了解如何將使用 MLflow 專案的定型作業提交至 Azure Machine Learning 工作區以進行追蹤,請參閱在 Azure Machine Learning 中使用 MLflow 專案來定型 (預覽) (英文)。

MLflow 專案的範例筆記本

MLflow 與 Azure Machine Learning 用戶端工具功能的比較

下表會示可以使用 MLflow SDK 和 Azure Machine Learning 用戶端工具執行的機器學習生命週期作業。

功能 MLflow SDK Azure Machine Learning CLI/SDK v2 Azure Machine Learning Studio
追蹤和記錄計量、參數和模型
擷取計量、參數和模型 只能下載成品和模型。
提交定型作業 可以使用 MLflow 專案 (預覽) 來進行。
使用 Azure Machine Learning 資料資產提交定型作業
使用機器學習管線提交定型作業
管理實驗和執行
管理 MLflow 模型 可能不支援部分作業。1
管理非 MLflow 模型
將 MLflow 模型部署至 Azure Machine Learning (線上和批次) 目前不支援部署用於批次推斷的 MLflow 模型。2
將非 MLflow 模型部署至 Azure Machine Learning

1 如需詳細資料,請參閱使用 MLflow 管理 Azure Machine Learning 中的模型登錄 (英文)。

2 如需替代方案,請參閱在 Spark 作業中部署和執行 MLflow 模型 (英文)。