다음을 통해 공유


Azure AI 스튜디오를 사용하여 대규모 언어 모델을 배포하는 방법

Important

이 문서에 설명된 기능 중 일부는 미리 보기로만 제공될 수 있습니다. 이 미리 보기는 서비스 수준 계약 없이 제공되며, 프로덕션 워크로드에는 권장되지 않습니다. 특정 기능이 지원되지 않거나 기능이 제한될 수 있습니다. 자세한 내용은 Microsoft Azure Preview에 대한 추가 사용 약관을 참조하세요.

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

이 문서에서는 Azure AI 스튜디오에서 대규모 언어 모델을 배포하는 방법을 알아봅니다. 모델 카탈로그 또는 프로젝트에서 모델을 배포할 수 있습니다. Azure Machine Learning SDK를 사용하여 모델을 배포할 수도 있습니다. 이 문서에서는 배포된 모델에 대해 유추를 수행하는 방법도 설명합니다.

코드를 사용하여 서버리스 API 모델 배포 및 유추

모델 배포

서버리스 API 모델은 종량제 청구로 배포할 수 있는 모델입니다. 예를 들어 Phi-3, Llama-2, Command R, Mistral Large 등이 있습니다. 서버리스 API 모델의 경우 모델을 미세 조정하도록 선택하지 않는 한 유추에 대해서만 요금이 청구됩니다.

모델 ID 가져오기

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

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

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

  3. 배포 옵션 필터에서 서버리스 API를 선택합니다.

    카탈로그에서 서버리스 API 모델을 필터링하는 방법을 보여 주는 스크린샷.

  4. 모델을 선택합니다.

  5. 선택한 모델의 세부 정보 페이지에서 모델 ID를 복사합니다. 다음과 같이 표시됩니다. azureml://registries/azureml-cohere/models/Cohere-command-r-plus/versions/3

Azure Machine Learning SDK 설치

다음으로, Azure Machine Learning SDK를 설치해야 합니다. 터미널에서 다음 명령을 실행합니다.

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

서버리스 API 모델 배포

먼저 Azure AI에 인증해야 합니다.

from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential
from azure.ai.ml.entities import MarketplaceSubscription, ServerlessEndpoint

# You can find your credential information in project settings.
client = MLClient(
    credential=DefaultAzureCredential(),
    subscription_id="your subscription name goes here",
    resource_group_name="your resource group name goes here",
    workspace_name="your project name goes here",
)

둘째, 앞에서 찾은 모델 ID를 참조해 보겠습니다.

# You can find the model ID on the model catalog.
model_id="azureml://registries/azureml-meta/models/Llama-2-70b-chat/versions/18" 

타사 모델 공급자의 서버리스 API 모델은 모델을 사용하려면 Azure Marketplace 구독이 필요합니다. 마켓플레이스 구독을 만들어 보겠습니다.

참고 항목

Microsoft에서 서버리스 API 모델(예: Phi-3)을 배포하는 경우 파트를 건너뛸 수 있습니다.

# You can customize the subscription name.
subscription_name="Meta-Llama-2-70b-chat" 

marketplace_subscription = MarketplaceSubscription(
    model_id=model_id,
    name=subscription_name,
)

marketplace_subscription = client.marketplace_subscriptions.begin_create_or_update(
    marketplace_subscription
).result()

마지막으로 서버리스 엔드포인트를 만들어 보겠습니다.


endpoint_name="Meta-Llama-2-70b-chat-qwerty" # Your endpoint name must be unique

serverless_endpoint = ServerlessEndpoint(
    name=endpoint_name,
    model_id=model_id
)

created_endpoint = client.serverless_endpoints.begin_create_or_update(
    serverless_endpoint
).result()

서버리스 API 엔드포인트 및 키 가져오기

endpoint_keys = client.serverless_endpoints.get_keys(endpoint_name)
print(endpoint_keys.primary_key)
print(endpoint_keys.secondary_key)

배포 유추

유추하기 위해 사용하는 다양한 모델 형식 및 SDK에 맞게 특별히 제공되는 코드를 사용하려고 합니다. Azure/azureml-examples 샘플 리포지토리에서 코드 샘플을 찾을 수 있습니다.

코드를 사용하여 관리형 컴퓨팅 배포 배포 및 유추

모델 배포

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

모델 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 설치

이 단계에서는, Azure Machine Learning SDK를 설치해야 합니다.

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

모델 배포

먼저 Azure AI에 인증해야 합니다.

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 할당량이 제공됩니다. 할당량 한도에 도달할 때까지 계속해서 배포를 만들 수 있습니다. 이 경우 할당량 증가를 요청할 수 있습니다.

다음 단계