MLflow 和 Azure Machine Learning

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

MLflow 是一種開放原始碼架構,旨在管理整個機器學習生命週期。 其可在不同平台上定型和服務模型的能力,可讓您使用一組一致的工具,不論您的實驗是在哪裡執行:您的本機電腦、遠端計算目標、虛擬機器或 Azure Machine Learning 計算執行個體。

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 第 1 版,SDK 第 2 版沒有記錄功能。 建議您使用 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 中使用 MLflow 包含下列功能:

Notebook 範例

在 R 中使用 MLflow 進行追蹤

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

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

若要了解如何使用 MLflow 追蹤用戶端搭配 Azure Machine Learning,請檢視使用 Azure Machine Learning CLI (v2) 來定型 R 模型中的範例。

在 Java 中使用 MLflow 進行追蹤

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

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

若要了解如何搭配 Azure Machine Learning 使用 MLflow 追蹤用戶端,請檢視使用 MLflow 追蹤用戶端搭配 Azure Machine Learning 的 Java 範例

使用 MLflow 的模型登錄

Azure Machine Learning 支援用於模型管理的 MLflow。 此支援是方便可針對熟悉 MLflow 用戶端的使用者支援整個模型生命週期的方式。

若要深入了解如何使用 Azure Machine Learning 中的 MLflow API 來管理模型,請檢視使用 MLflow 管理 Azure Machine Learning 中的模型登錄

範例筆記本

使用 MLflow 進行模型部署

您可以將 MLflow 模型部署至 Azure Machine Learning,並在使用 MLflow 模型時利用改良的體驗。 Azure Machine Learning 支援將 MLflow 模型部署至即時和批次端點,而不需要指定環境或評分指令碼。 支援使用 MLflow SDK、Azure Machine Learning CLI、適用於 Python 的 Azure Machine Learning SDK,或 Azure Machine Learning 工作室進行部署。

若要深入了解如何將 MLflow 模型部署至 Azure Machine Learning 進行即時和批次推斷,請參閱部署 MLflow 模型的指導方針

Notebook 範例

使用 MLflow 專案進行定型 (預覽)

重要

本文中標示為 (預覽) 的項目目前處於公開預覽狀態。 此預覽版本會在沒有服務等級協定的情況下提供,不建議用於實際執行工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

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

若要了解如何透過使用 Azure Machine Learning 工作區進行追蹤的 MLflow 專案提交定型作業,請參閱使用 MLflow 專案和 Azure Machine Learning 來定型機器學習模型

Notebook 範例

MLflow SDK、Azure Machine Learning v2 和 Azure Machine Learning 工作室功能

下表顯示可使用機器學習生命週期中可用的每個用戶端工具進行的作業。

功能 MLflow SDK Azure Machine Learning CLI/SDK Azure Machine Learning Studio
追蹤和記錄計量、參數和模型
擷取計量、參數和模型 1
提交定型作業 2
使用 Azure Machine Learning 資料資產提交定型作業
使用機器學習管線提交定型作業
管理實驗和執行
管理 MLflow 模型 3
管理非 MLflow 模型
將 MLflow 模型部署至 Azure Machine Learning (線上和批次) 4
將非 MLflow 模型部署至 Azure Machine Learning

注意