코드를 사용하여 관리형 컴퓨팅을 배포하고 배포를 유추하는 방법

AI 스튜디오 모델 카탈로그는 1,600개 이상의 모델을 제공하며, 이러한 모델을 배포하는 가장 일반적인 방법은 관리형 온라인 배포라고도 하는 관리형 컴퓨팅 배포 옵션을 사용하는 것입니다.

LLM(대규모 언어 모델)을 배포하면 웹 사이트, 애플리케이션 또는 기타 프로덕션 환경에서 LLM을 사용할 수 있습니다. 일반적으로 배포에는 서버 또는 클라우드에서 모델을 호스트하고 사용자가 모델과 상호 작용할 수 있도록 API 또는 기타 인터페이스를 만드는 작업이 포함됩니다. 채팅 및 Copilot과 같은 생성형 AI 애플리케이션을 실시간으로 유추하기 위해 배포를 호출할 수 있습니다.

이 문서에서는 Azure Machine Learning SDK를 사용하여 모델을 배포하는 방법을 알아봅니다. 이 문서에서는 배포된 모델에 대해 유추를 수행하는 방법도 설명합니다.

모델 ID 가져오기

Azure Machine Learning SDK를 사용하여 관리형 컴퓨팅 모델을 배포할 수 있지만, 먼저 모델 카탈로그를 찾아보고 배포에 필요한 모델 ID를 가져오겠습니다.

  1. AI 스튜디오에 로그인하고 페이지로 이동합니다.

  2. 왼쪽 사이드바에서 모델 카탈로그를 선택합니다.

  3. 배포 옵션 필터에서 관리형 컴퓨팅을 선택합니다.

    카탈로그에서 관리형 컴퓨팅 모델을 필터링하는 방법을 보여 주는 스크린샷.

  4. 모델을 선택합니다.

  5. 선택한 모델의 세부 정보 페이지에서 모델 ID를 복사합니다. 다음과 같이 표시됩니다. azureml://registries/azureml/models/deepset-roberta-base-squad2/versions/16

모델 배포

모델을 배포해 보겠습니다.

먼저, Azure Machine Learning SDK를 설치해야 합니다.

pip install azure-ai-ml
pip install azure-identity

이 코드를 사용하여 Azure Machine Learning으로 인증하고 클라이언트 개체를 만듭니다. 자리 표시자를 구독 ID, 리소스 그룹 이름 및 AI Studio 프로젝트 이름으로 바꿉니다.

from azure.ai.ml import MLClient
from azure.identity import InteractiveBrowserCredential

client = MLClient(
    credential=InteractiveBrowserCredential,
    subscription_id="your subscription name goes here",
    resource_group_name="your resource group name goes here",
    workspace_name="your project name goes here",
)

관리형 컴퓨팅 배포 옵션의 경우 모델 배포 전에 엔드포인트를 만들어야 합니다. 엔드포인트를 여러 모델 배포를 저장할 수 있는 컨테이너로 간주합니다. 엔드포인트 이름은 지역에서 고유해야 하므로 이 예제에서는 타임스탬프를 사용하여 고유한 엔드포인트 이름을 만듭니다.

import time, sys
from azure.ai.ml.entities import (
    ManagedOnlineEndpoint,
    ManagedOnlineDeployment,
    ProbeSettings,
)

# Make the endpoint name unique
timestamp = int(time.time())
online_endpoint_name = "customize your endpoint name here" + str(timestamp)

# Create an online endpoint
endpoint = ManagedOnlineEndpoint(
    name=online_endpoint_name,
    auth_mode="key",
)
workspace_ml_client.begin_create_or_update(endpoint).wait()

배포를 만듭니다. 모델 카탈로그에서 모델 ID를 찾을 수 있습니다.

model_name = "azureml://registries/azureml/models/deepset-roberta-base-squad2/versions/16" 

demo_deployment = ManagedOnlineDeployment(
    name="demo",
    endpoint_name=online_endpoint_name,
    model=model_name,
    instance_type="Standard_DS3_v2",
    instance_count=2,
    liveness_probe=ProbeSettings(
        failure_threshold=30,
        success_threshold=1,
        timeout=2,
        period=10,
        initial_delay=1000,
    ),
    readiness_probe=ProbeSettings(
        failure_threshold=10,
        success_threshold=1,
        timeout=10,
        period=10,
        initial_delay=1000,
    ),
)
workspace_ml_client.online_deployments.begin_create_or_update(demo_deployment).wait()
endpoint.traffic = {"demo": 100}
workspace_ml_client.begin_create_or_update(endpoint).result()

배포 유추

유추를 테스트하려면 샘플 json 데이터가 필요합니다. 다음 예제를 사용하여 sample_score.json을 만듭니다.

{
  "inputs": {
    "question": [
      "Where do I live?",
      "Where do I live?",
      "What's my name?",
      "Which name is also used to describe the Amazon rainforest in English?"
    ],
    "context": [
      "My name is Wolfgang and I live in Berlin",
      "My name is Sarah and I live in London",
      "My name is Clara and I live in Berkeley.",
      "The Amazon rainforest (Portuguese: Floresta Amaz\u00f4nica or Amaz\u00f4nia; Spanish: Selva Amaz\u00f3nica, Amazon\u00eda or usually Amazonia; French: For\u00eat amazonienne; Dutch: Amazoneregenwoud), also known in English as Amazonia or the Amazon Jungle, is a moist broadleaf forest that covers most of the Amazon basin of South America. This basin encompasses 7,000,000 square kilometres (2,700,000 sq mi), of which 5,500,000 square kilometres (2,100,000 sq mi) are covered by the rainforest. This region includes territory belonging to nine nations. The majority of the forest is contained within Brazil, with 60% of the rainforest, followed by Peru with 13%, Colombia with 10%, and with minor amounts in Venezuela, Ecuador, Bolivia, Guyana, Suriname and French Guiana. States or departments in four nations contain \"Amazonas\" in their names. The Amazon represents over half of the planet's remaining rainforests, and comprises the largest and most biodiverse tract of tropical rainforest in the world, with an estimated 390 billion individual trees divided into 16,000 species."
    ]
  }
}

sample_score.json을 유추해 보겠습니다. 샘플 json 파일을 저장한 위치에 따라 위치를 변경합니다.

scoring_file = "./sample_score.json" 
response = workspace_ml_client.online_endpoints.invoke(
    endpoint_name=online_endpoint_name,
    deployment_name="demo",
    request_file=scoring_file,
)
response_json = json.loads(response)
print(json.dumps(response_json, indent=2))

배포 엔드포인트 삭제

AI 스튜디오에서 배포를 삭제하려면 배포 세부 정보 페이지의 맨 위 패널에서 삭제 단추를 선택합니다.

할당량 고려 사항

실시간 엔드포인트를 사용하여 유추를 배포하고 수행하려면 지역별로 구독에 할당된 VM(Virtual Machine) 코어 할당량을 사용합니다. AI 스튜디오에 등록하면 해당 지역에서 사용할 수 있는 여러 VM 제품군에 대한 기본 VM 할당량이 제공됩니다. 할당량 한도에 도달할 때까지 계속해서 배포를 만들 수 있습니다. 이 경우 할당량 증가를 요청할 수 있습니다.

다음 단계