Azure Machine Learning에서 모델 작업

적용 대상:Azure CLI ml 확장 v2(현재)Python SDK azure-ai-ml v2(현재)

Azure Machine Learning을 사용하면 다양한 형식의 모델로 작업할 수 있습니다. 이 문서에서는 Azure Machine Learning을 사용하여 사용자 지정, MLflow 및 Triton과 같은 다양한 모델 형식으로 작업하는 방법을 알아봅니다. 또한 여러 위치에서 모델을 등록하는 방법과 Azure Machine Learning SDK, UI(사용자 인터페이스) 및 Azure Machine Learning CLI를 사용하여 모델을 관리하는 방법을 알아봅니다.

SDK/CLI v1을 사용하여 만든 모델 자산이 있는 경우에도 해당 자산을 SDK/CLI v2에 사용할 수 있습니다. 완전한 이전 버전과의 호환성이 제공됩니다. V1 SDK에 등록된 모든 모델에는 custom 형식이 할당됩니다.

필수 구성 요소

또한 다음을 수행해야 합니다.

지원되는 경로

등록하려는 모델을 제공할 때 데이터 또는 작업 위치를 가리키는 path 매개 변수를 지정해야 합니다. 아래 표에서는 Azure Machine Learning에서 지원되는 다양한 데이터 위치와 path 매개 변수의 예제를 보여 줍니다.

위치 예제
로컬 컴퓨터의 경로 mlflow-model/model.pkl
Azure Machine Learning 데이터 저장소 경로 azureml://datastores/<datastore-name>/paths/<path_on_datastore>
Azure Machine Learning 작업의 경로 azureml://jobs/<job-name>/outputs/<output-name>/paths/<path-to-model-relative-to-the-named-output-location>
MLflow 작업의 경로 runs:/<run-id>/<path-to-model-relative-to-the-root-of-the-artifact-location>
Azure Machine Learning 작업 영역에서 모델 자산 경로 azureml:<model-name>:<version>
Azure Machine Learning 레지스트리에서 모델 자산 경로 azureml://registries/<registry-name>/models/<model-name>/versions/<version>

지원되는 모드

모델 입력/출력으로 작업을 실행할 때 모드를 지정할 수 있습니다. 예를 들어 모델을 읽기 전용으로 탑재할지 컴퓨팅 대상에 다운로드할지를 지정할 수 있습니다. 아래 표에서는 다양한 형식/모드/입력/출력 조합에 사용할 수 있는 모드를 보여 줍니다.

Type 입/출력 upload download ro_mount rw_mount direct
custom 파일 입력
custom 폴더 입력
mlflow 입력
custom 파일 출력
custom 폴더 출력
mlflow 출력

Jupyter Notebooks에서 따라하기

Jupyter Notebook에서 이 샘플을 따를 수 있습니다. azureml-examples 리포지토리에서 Notebook model.ipynb를 엽니다.

모델 레지스트리에서 모델 만들기

모델을 등록하면 작업 영역에서 Azure 클라우드의 모델을 저장하고 버전을 지정할 수 있습니다. 모델 레지스트리에서는 학습된 모델을 구성하고 추적할 수 있습니다.

이 섹션의 코드 조각은 다음과 같은 방법을 다룹니다.

  • CLI를 사용하여 Machine Learning에서 모델을 자산으로 등록
  • SDK를 사용하여 Machine Learning에서 모델을 자산으로 등록
  • UI를 사용하여 Machine Learning에서 모델을 자산으로 등록

이 코드 조각에서는 custommlflow를 사용합니다.

  • custom은 현재 Azure Machine Learning에서 지원하지 않는 사용자 지정 표준으로 학습된 모델 파일 또는 폴더를 참조하는 형식입니다.
  • mlflowmlflow로 학습된 모델을 참조하는 형식입니다. MLflow 학습 모델은 MLmodel 파일, model 파일, conda dependencies 파일 및 requirements.txt 파일이 포함된 폴더에 있습니다.

작업 영역에 연결

먼저 작업할 Azure Machine Learning 작업 영역에 연결해 보겠습니다.

az account set --subscription <subscription>
az configure --defaults workspace=<workspace> group=<resource-group> location=<location>

CLI를 사용하여 Machine Learning에서 모델을 자산으로 등록

다음 탭을 사용하여 모델이 있는 위치를 선택합니다.

$schema: https://azuremlschemas.azureedge.net/latest/model.schema.json
name: local-file-example
path: mlflow-model/model.pkl
description: Model created from local file.
az ml model create -f <file-name>.yml

전체 예제는 모델 YAML을 참조하세요.

SDK를 사용하여 Machine Learning에서 모델을 자산으로 등록

다음 탭을 사용하여 모델이 있는 위치를 선택합니다.

from azure.ai.ml.entities import Model
from azure.ai.ml.constants import AssetTypes

file_model = Model(
    path="mlflow-model/model.pkl",
    type=AssetTypes.CUSTOM_MODEL,
    name="local-file-example",
    description="Model created from local file.",
)
ml_client.models.create_or_update(file_model)

UI를 사용하여 Machine Learning에서 모델을 자산으로 등록

Machine Learning에서 모델을 만들려면 UI에서 모델 페이지를 엽니다. 모델 등록을 선택하고 모델이 있는 위치를 선택합니다. 필수 필드를 입력한 다음, 등록을 선택합니다.

Screenshot of the UI to register a model.


모델 관리

SDK 및 CLI(v2)를 사용하면 Azure Machine Learning 모델 자산의 수명 주기도 관리할 수 있습니다.

List

작업 영역의 모든 모델을 나열합니다.

az ml model list

지정된 이름 아래에 모든 모델 버전을 나열합니다.

az ml model list --name run-model-example

표시

특정 모델의 세부 정보를 얻습니다.

az ml model show --name run-model-example --version 1

엽데이트

특정 모델의 변경 가능한 속성을 업데이트합니다.

az ml model update --name  run-model-example --version 1 --set description="This is an updated description." --set tags.stage="Prod"

Important

모델의 경우 descriptiontags만 업데이트할 수 있습니다. 다른 모든 속성은 불변입니다. 이러한 속성을 변경해야 하는 경우 새 버전의 모델을 만들어야 합니다.

보관

모델을 보관하면 기본적으로 목록 쿼리(az ml model list)에서 해당 환경이 숨겨집니다. 워크플로에서 보관된 모델을 계속 참조하고 사용할 수 있습니다. 모델의 모든 버전 또는 특정 버전만 보관할 수 있습니다.

버전을 지정하지 않으면 해당 이름 아래의 모델의 모든 버전이 보관됩니다. 보관된 모델 컨테이너에서 새 모델 버전을 만드는 경우 해당 새 버전도 자동으로 보관으로 설정됩니다.

모델의 모든 버전을 보관합니다.

az ml model archive --name run-model-example

특정 모델 버전을 보관합니다.

az ml model archive --name run-model-example --version 1

학습에 모델 사용

또한 SDK 및 CLI(v2)를 사용하면 학습 작업의 모델을 입력 또는 출력으로 사용할 수 있습니다.

작업에서 모델을 입력으로 사용

작업 사양 YAML 파일(<file-name>.yml)을 만듭니다. 작업의 inputs 섹션에서 다음을 지정합니다.

  1. type: 모델이 mlflow_model, custom_model 또는 triton_model 중 어느 것인지를 나타냅니다.
  2. path - 데이터가 있는 위치입니다. 경로는 지원되는 경로 섹션에 설명된 경로 중 하나일 수 있습니다.
$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json

# Possible Paths for models:
# AzureML Datastore: azureml://datastores/<datastore-name>/paths/<path_on_datastore>
# MLflow run: runs:/<run-id>/<path-to-model-relative-to-the-root-of-the-artifact-location>
# Job: azureml://jobs/<job-name>/outputs/<output-name>/paths/<path-to-model-relative-to-the-named-output-location>
# Model Asset: azureml:<my_model>:<version>

command: |
  ls ${{inputs.my_model}}
inputs:
  my_model:
    type: mlflow_model # List of all model types here: https://learn.microsoft.com/azure/machine-learning/reference-yaml-model#yaml-syntax
    path: ../../assets/model/mlflow-model
environment: azureml://registries/azureml/environments/sklearn-1.0/labels/latest

다음으로, CLI에서 실행

az ml job create -f <file-name>.yml

전체 예제는 모델 GitHub 리포지토리를 참조하세요.

작업에서 모델을 출력으로 사용

작업에서 출력을 사용하여 클라우드 기반 스토리지에 모델을 쓸 수 있습니다.

데이터를 쓸 위치의 형식과 경로로 채워진 outputs 섹션을 사용하여 작업 사양 YAML 파일(<file-name>.yml)을 만듭니다.

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json

# Possible Paths for Model:
# Local path: mlflow-model/model.pkl
# AzureML Datastore: azureml://datastores/<datastore-name>/paths/<path_on_datastore>
# MLflow run: runs:/<run-id>/<path-to-model-relative-to-the-root-of-the-artifact-location>
# Job: azureml://jobs/<job-name>/outputs/<output-name>/paths/<path-to-model-relative-to-the-named-output-location>
# Model Asset: azureml:<my_model>:<version>

code: src
command: >-
  python hello-model-as-output.py 
  --input_model ${{inputs.input_model}} 
  --custom_model_output ${{outputs.output_folder}}
inputs:
  input_model: 
    type: mlflow_model # mlflow_model,custom_model, triton_model
    path: ../../assets/model/mlflow-model
outputs:
  output_folder: 
    type: custom_model # mlflow_model,custom_model, triton_model
environment: azureml://registries/azureml/environments/sklearn-1.0/labels/latest

다음으로, CLI를 사용하여 작업을 만듭니다.

az ml job create --file <file-name>.yml

전체 예제는 모델 GitHub 리포지토리를 참조하세요.

다음 단계