서버리스 컴퓨팅에 대한 모델 학습

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

확장 가능한 방식으로 모델을 학습시키기 위해 더 이상 컴퓨팅을 만들고 관리할 필요가 없습니다. 대신 작업을 서버리스 컴퓨팅이라는 새로운 컴퓨팅 대상 유형에 제출할 수 있습니다. 서버리스 컴퓨팅은 Azure Machine Learning에서 학습 작업을 실행하는 가장 쉬운 방법입니다. 서버리스 컴퓨팅은 완전 관리되는 주문형 컴퓨팅입니다. Azure Machine Learning은 컴퓨팅을 만들고, 스케일링하고, 관리합니다. 서버리스 컴퓨팅을 사용한 모델 학습을 통해 기계 학습 전문가는 컴퓨팅 인프라나 설정에 대해 알아볼 필요 없이 기계 학습 모델 빌드에 대한 전문 지식에 집중할 수 있습니다.

기계 학습 전문가는 작업에 필요한 리소스를 지정할 수 있습니다. Azure Machine Learning은 컴퓨팅 인프라를 관리하고 관리되는 네트워크 격리를 제공하여 사용자의 부담을 줄여줍니다.

기업은 각 작업에 최적의 리소스를 지정하여 비용을 절감할 수도 있습니다. IT 관리자는 구독 및 작업 영역 수준에서 코어 할당량을 지정하여 제어를 적용하고 Azure Policy를 적용할 수 있습니다.

서버리스 컴퓨팅을 사용하여 LLAMA 2와 같은 모델 카탈로그의 모델을 미세 조정할 수 있습니다. 서버리스 컴퓨팅을 사용하여 Azure Machine Learning 스튜디오, SDK 및 CLI에서 모든 유형의 작업을 실행할 수 있습니다. 서버리스 컴퓨팅은 환경 이미지 빌드 및 책임 있는 AI 대시보드 시나리오에도 사용할 수 있습니다. 서버리스 작업은 Azure Machine Learning 컴퓨팅 할당량과 동일한 할당량을 사용합니다. 표준(전용) 계층 또는 스폿(낮은 우선 순위) VM을 선택할 수 있습니다. 서버리스 작업에는 관리 ID 및 사용자 ID가 지원됩니다. 청구 모델은 Azure Machine Learning 컴퓨팅과 동일합니다.

서버리스 컴퓨팅의 장점

  • Azure Machine Learning은 인프라 만들기, 설정, 크기 조정, 삭제, 패치 적용, 컴퓨팅 인프라를 관리하여 관리 오버헤드를 줄입니다.
  • 컴퓨팅, 다양한 컴퓨팅 형식 및 관련 속성에 대해 알아볼 필요가 없습니다.
  • 동일한 설정을 사용하고 각 작업 영역에 대해 복제하면서 필요한 각 VM 크기에 대해 클러스터를 반복적으로 만들 필요가 없습니다.
  • 인스턴스 형식(VM 크기) 및 인스턴스 수 측면에서 런타임 시 각 작업에 필요한 정확한 리소스를 지정하여 비용을 최적화할 수 있습니다. 작업의 사용률 메트릭을 모니터링하여 작업에 필요한 리소스를 최적화할 수 있습니다.
  • 작업 실행에 필요한 단계 감소
  • 작업 제출을 더욱 간소화하려면 리소스를 모두 건너뛸 수 있습니다. Azure Machine Learning은 인스턴스 수를 기본값으로 설정하고 할당량, 비용, 성능, 디스크 크기와 같은 요소를 기반으로 인스턴스 형식(VM 크기)을 선택합니다.
  • 경우에 따라 작업 실행이 시작되기 전 대기 시간이 줄어듭니다.
  • 작업 제출에는 사용자 ID 및 작업 영역 사용자 할당 관리 ID가 지원됩니다.
  • 관리되는 네트워크 격리를 사용하면 네트워크 격리 구성을 간소화하고 자동화할 수 있습니다. 고객 가상 네트워크도 지원됩니다.
  • 할당량 및 Azure Policy를 통한 관리자 제어

서버리스 컴퓨팅을 사용하는 방법

  • 아래와 같이 Notebook을 사용하여 LLAMA 2와 같은 기초 모델을 미세 조정할 수 있습니다.

  • 자체 컴퓨팅 클러스터를 만들 때 명령 작업에서 해당 이름을 사용합니다(예: compute="cpu-cluster"). 서버리스를 사용하면 컴퓨팅 클러스터 만들기를 건너뛰고 compute 매개 변수를 생략하여 대신 서버리스 컴퓨팅을 사용할 수 있습니다. 작업에 대해 compute가 지정되지 않으면 작업은 서버리스 컴퓨팅에서 실행됩니다. 다음 작업 형식에서 서버리스 컴퓨팅을 사용하고 선택적으로 인스턴스 수 및 인스턴스 형식 측면에서 작업에 필요한 리소스를 제공하려면 CLI 또는 SDK 작업에서 컴퓨팅 이름을 생략합니다.

    • 대화형 작업 및 분산 학습을 포함한 명령 작업
    • AutoML 작업
    • 청소 작업
    • 병렬 작업
  • CLI를 통한 파이프라인 작업의 경우 파이프라인 수준 기본 컴퓨팅에 default_compute: azureml:serverless를 사용합니다. SDK를 통한 파이프라인 작업의 경우 default_compute="serverless"를 사용합니다. 예를 보려면 파이프라인 작업을 참조하세요.

  • 스튜디오(미리 보기)에서 학습 작업을 제출할 때 컴퓨팅 형식으로 서버리스를 선택합니다.

  • Azure Machine Learning 디자이너를 사용하는 경우 기본 컴퓨팅으로 서버리스를 선택합니다.

  • 책임 있는 AI 대시보드에 서버리스 컴퓨팅을 사용할 수 있습니다.

성능 고려 사항

서버리스 컴퓨팅은 다음과 같은 방법으로 학습 속도를 높이는 데 도움이 됩니다.

할당량이 부족함: 자체 컴퓨팅 클러스터를 만들 때 만들 VM 크기와 노드 수를 파악해야 합니다. 작업이 실행될 때 클러스터에 대한 할당량이 충분하지 않으면 작업이 실패합니다. 서버리스 컴퓨팅은 기본적으로 할당량에 대한 정보를 사용하여 적절한 VM 크기를 선택합니다.

스케일 업 최적화: 컴퓨팅 클러스터가 스케일 업되면 새 작업은 스케일 업이 발생할 때까지 기다린 다음 작업을 실행하기 전에 스케일 업해야 합니다. 서버리스 컴퓨팅을 사용하면 스케일 다운을 기다릴 필요가 없으며 작업이 다른 클러스터/노드에서 실행을 시작할 수 있습니다(할당량이 있다고 가정).

클러스터 사용 중 최적화: 컴퓨팅 클러스터에서 작업이 실행 중이고 다른 작업이 제출되면 해당 작업은 현재 실행 중인 작업 뒤에 큐에 추가됩니다. 서버리스 컴퓨팅을 사용하면 다른 노드/다른 클러스터에서 작업 실행을 시작할 수 있습니다(할당량이 있다고 가정).

할당량

작업을 제출할 때 계속하려면 충분한 Azure Machine Learning 컴퓨팅 할당량이 필요합니다(작업 영역 및 구독 수준 할당량 모두). 서버리스 작업의 기본 VM 크기는 이 할당량에 따라 선택됩니다. 자체 VM 크기/제품군을 지정하는 경우:

  • VM 크기/제품군에 대한 할당량이 일부 있지만 인스턴스 수에 대한 할당량이 충분하지 않은 경우 오류가 표시됩니다. 오류에서는 할당량 한도에 따라 인스턴스 수를 유효한 수로 줄이거나 이 VM 제품군에 대한 할당량 증가를 요청하거나 VM 크기를 변경하도록 권장합니다.
  • 지정된 VM 크기에 대한 할당량이 없으면 오류가 표시됩니다. 이 오류에서는 이 VM 제품군에 대한 할당량 또는 요청 할당량이 있는 다른 VM 크기를 선택하도록 권장합니다.
  • VM 제품군이 서버리스 작업을 실행하는 데 충분한 할당량이 있지만 다른 작업에서 할당량을 사용하고 있는 경우 할당량이 사용 가능해질 때까지 작업이 큐에서 대기해야 한다는 메시지가 표시됩니다.

Azure Portal에서 사용량 및 할당량을 보면 “서버리스”라는 이름이 표시되어 서버리스 작업에서 사용되는 모든 할당량을 볼 수 있습니다.

ID 지원 및 자격 증명 통과

  • 사용자 자격 증명 통과: 서버리스 컴퓨팅은 사용자 자격 증명 통과를 완벽하게 지원합니다. 작업을 제출하는 사용자의 사용자 토큰은 스토리지 액세스에 사용됩니다. 이러한 자격 증명은 Microsoft Entra ID에서 가져옵니다.

    from azure.ai.ml import command
    from azure.ai.ml import MLClient     # Handle to the workspace
    from azure.identity import DefaultAzureCredential     # Authentication package
    from azure.ai.ml.entities import ResourceConfiguration
    from azure.ai.ml.entities import UserIdentityConfiguration 
    
    credential = DefaultAzureCredential()
    # Get a handle to the workspace. You can find the info on the workspace tab on ml.azure.com
    ml_client = MLClient(
        credential=credential,
        subscription_id="<Azure subscription id>", 
        resource_group_name="<Azure resource group>",
        workspace_name="<Azure Machine Learning Workspace>",
    )
    job = command(
        command="echo 'hello world'",
        environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",
            identity=UserIdentityConfiguration(),
    )
    # submit the command job
    ml_client.create_or_update(job)
    
  • 사용자 할당 관리 ID: 사용자 할당 관리 ID로 구성된 작업 영역이 있는 경우 스토리지 액세스를 위해 서버리스 작업에 해당 ID를 사용할 수 있습니다.

    from azure.ai.ml import command
    from azure.ai.ml import MLClient     # Handle to the workspace
    from azure.identity import DefaultAzureCredential    # Authentication package
    from azure.ai.ml.entities import ResourceConfiguration
    from azure.ai.ml.entities import ManagedIdentityConfiguration
    
    credential = DefaultAzureCredential()
    # Get a handle to the workspace. You can find the info on the workspace tab on ml.azure.com
    ml_client = MLClient(
        credential=credential,
        subscription_id="<Azure subscription id>", 
        resource_group_name="<Azure resource group>",
        workspace_name="<Azure Machine Learning Workspace>",
    )
    job = command(
        command="echo 'hello world'",
        environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",
            identity= ManagedIdentityConfiguration(),
    )
    # submit the command job
    ml_client.create_or_update(job)
    
    

사용자가 할당한 관리 ID 연결에 대한 자세한 내용은 사용자가 할당한 관리 ID 연결을 참조하세요.

명령 작업에 대한 속성 구성

명령, 스윕 및 AutoML 작업에 대해 컴퓨팅 대상이 지정되지 않은 경우 컴퓨팅은 기본적으로 서버리스 컴퓨팅으로 설정됩니다. 예를 들어, 이 명령 작업의 경우:

from azure.ai.ml import command
from azure.ai.ml import command 
from azure.ai.ml import MLClient # Handle to the workspace
from azure.identity import DefaultAzureCredential # Authentication package

credential = DefaultAzureCredential()
# Get a handle to the workspace. You can find the info on the workspace tab on ml.azure.com
ml_client = MLClient(
    credential=credential,
    subscription_id="<Azure subscription id>", 
    resource_group_name="<Azure resource group>",
    workspace_name="<Azure Machine Learning Workspace>",
)
job = command(
    command="echo 'hello world'",
    environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",
)
# submit the command job
ml_client.create_or_update(job)

컴퓨팅은 기본적으로 다음을 사용하여 서버리스 컴퓨팅으로 설정됩니다.

  • 이 작업의 단일 노드입니다. 기본 노드 수는 작업 형식에 따라 다릅니다. 다른 작업 형식은 다음 섹션을 참조하세요.
  • 할당량, 성능, 비용 및 디스크 크기를 기준으로 결정되는 CPU 가상 머신입니다.
  • 전용 가상 머신
  • 작업 영역 위치

이러한 기본값을 재정의할 수 있습니다. 서버리스 컴퓨팅을 위한 VM 형식 또는 노드 수를 지정하려면 작업에 resources를 추가합니다.

  • instance_type 특정 VM을 선택합니다. 특정 CPU/GPU VM 크기를 원하는 경우 이 매개 변수를 사용합니다.

  • instance_count는 노드 수를 지정합니다.

    from azure.ai.ml import command 
    from azure.ai.ml import MLClient # Handle to the workspace
    from azure.identity import DefaultAzureCredential # Authentication package
    from azure.ai.ml.entities import JobResourceConfiguration 
    
    credential = DefaultAzureCredential()
    # Get a handle to the workspace. You can find the info on the workspace tab on ml.azure.com
    ml_client = MLClient(
        credential=credential,
        subscription_id="<Azure subscription id>", 
        resource_group_name="<Azure resource group>",
        workspace_name="<Azure Machine Learning Workspace>",
    )
    job = command(
        command="echo 'hello world'",
        environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",
        resources = JobResourceConfiguration(instance_type="Standard_NC24", instance_count=4)
    )
    # submit the command job
    ml_client.create_or_update(job)
    
  • 작업 계층을 변경하려면 queue_settings를 사용하여 전용 VM(job_tier: Standard)과 낮은 우선 순위(jobtier: Spot) 중에서 선택합니다.

    from azure.ai.ml import command
    from azure.ai.ml import MLClient    # Handle to the workspace
    from azure.identity import DefaultAzureCredential    # Authentication package
    credential = DefaultAzureCredential()
    # Get a handle to the workspace. You can find the info on the workspace tab on ml.azure.com
    ml_client = MLClient(
        credential=credential,
        subscription_id="<Azure subscription id>", 
        resource_group_name="<Azure resource group>",
        workspace_name="<Azure Machine Learning Workspace>",
    )
    job = command(
        command="echo 'hello world'",
        environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",
        queue_settings={
          "job_tier": "spot"  
        }
    )
    # submit the command job
    ml_client.create_or_update(job)
    

명령 작업이 있는 모든 필드의 예

다음은 작업에서 사용해야 하는 ID를 포함하여 지정된 모든 필드의 예입니다. 작업 영역 수준의 관리되는 네트워크 격리가 자동으로 사용되므로 가상 네트워크 설정을 지정할 필요가 없습니다.

from azure.ai.ml import command
from azure.ai.ml import MLClient      # Handle to the workspace
from azure.identity import DefaultAzureCredential     # Authentication package
from azure.ai.ml.entities import ResourceConfiguration
from azure.ai.ml.entities import UserIdentityConfiguration 

credential = DefaultAzureCredential()
# Get a handle to the workspace. You can find the info on the workspace tab on ml.azure.com
ml_client = MLClient(
    credential=credential,
    subscription_id="<Azure subscription id>", 
    resource_group_name="<Azure resource group>",
    workspace_name="<Azure Machine Learning Workspace>",
)
job = command(
    command="echo 'hello world'",
    environment="AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest",
         identity=UserIdentityConfiguration(),
    queue_settings={
      "job_tier": "Standard"  
    }
)
job.resources = ResourceConfiguration(instance_type="Standard_E4s_v3", instance_count=1)
# submit the command job
ml_client.create_or_update(job)

다음에서 서버리스 컴퓨팅을 사용한 학습의 더 많은 예를 확인합니다.

AutoML 작업

AutoML 작업에 대한 컴퓨팅을 지정할 필요가 없습니다. 리소스는 선택적으로 지정할 수 있습니다. 인스턴스 수를 지정하지 않으면 max_concurrent_trials 및 max_nodes 매개 변수를 기반으로 기본값이 지정됩니다. 인스턴스 형식 없이 AutoML 이미지 분류 또는 NLP 작업을 제출하면 GPU VM 크기가 자동으로 선택됩니다. CLI, SDK 또는 스튜디오를 통해 AutoML 작업을 제출할 수 있습니다. 스튜디오에서 서버리스 컴퓨팅을 사용하여 AutoML 작업을 제출하려면 먼저 미리 보기 패널에서 스튜디오에서 학습 작업 제출(미리 보기) 기능을 사용하도록 설정하세요.

형식이나 인스턴스 수를 지정하려면 ResourceConfiguration 클래스를 사용합니다.

# Create the AutoML classification job with the related factory-function.
from azure.ai.ml.entities import ResourceConfiguration 

classification_job = automl.classification(
    experiment_name=exp_name,
    training_data=my_training_data_input,
    target_column_name="y",
    primary_metric="accuracy",
    n_cross_validations=5,
    enable_model_explainability=True,
    tags={"my_custom_tag": "My custom value"},
)

# Limits are all optional
classification_job.set_limits(
    timeout_minutes=600,
    trial_timeout_minutes=20,
    max_trials=max_trials,
    # max_concurrent_trials = 4,
    # max_cores_per_trial: -1,
    enable_early_termination=True,
)

# Training properties are optional
classification_job.set_training(
    blocked_training_algorithms=[ClassificationModels.LOGISTIC_REGRESSION],
    enable_onnx_compatible_models=True,
)

# Serverless compute resources used to run the job
classification_job.resources = 
ResourceConfiguration(instance_type="Standard_E4s_v3", instance_count=6)

파이프라인 작업

파이프라인 작업의 경우 서버리스 컴퓨팅을 사용하려면 "serverless"를 기본 컴퓨팅 형식으로 지정합니다.

# Construct pipeline
@pipeline()
def pipeline_with_components_from_yaml(
    training_input,
    test_input,
    training_max_epochs=20,
    training_learning_rate=1.8,
    learning_rate_schedule="time-based",
):
    """E2E dummy train-score-eval pipeline with components defined via yaml."""
    # Call component obj as function: apply given inputs & parameters to create a node in pipeline
    train_with_sample_data = train_model(
        training_data=training_input,
        max_epochs=training_max_epochs,
        learning_rate=training_learning_rate,
        learning_rate_schedule=learning_rate_schedule,
    )

    score_with_sample_data = score_data(
        model_input=train_with_sample_data.outputs.model_output, test_data=test_input
    )
    score_with_sample_data.outputs.score_output.mode = "upload"

    eval_with_sample_data = eval_model(
        scoring_result=score_with_sample_data.outputs.score_output
    )

    # Return: pipeline outputs
    return {
        "trained_model": train_with_sample_data.outputs.model_output,
        "scored_data": score_with_sample_data.outputs.score_output,
        "evaluation_report": eval_with_sample_data.outputs.eval_output,
    }


pipeline_job = pipeline_with_components_from_yaml(
    training_input=Input(type="uri_folder", path=parent_dir + "/data/"),
    test_input=Input(type="uri_folder", path=parent_dir + "/data/"),
    training_max_epochs=20,
    training_learning_rate=1.8,
    learning_rate_schedule="time-based",
)

# set pipeline to use serverless compute
pipeline_job.settings.default_compute = "serverless"

디자이너에서 서버리스 컴퓨팅을 기본 컴퓨팅으로 설정할 수도 있습니다.

다음 단계

다음에서 서버리스 컴퓨팅을 사용한 학습의 더 많은 예를 확인합니다.