배포 엔드포인트를 SDK v2로 업그레이드

SDK/CLI v1을 사용하면 ACI 또는 AKS에 모델을 웹 서비스로 배포할 수 있습니다. 기존 v1 모델 배포 및 웹 서비스는 그대로 계속 작동하지만 SDK/CLI v1을 사용하여 ACI 또는 AKS에 모델을 웹 서비스로 배포하면 이제 레거시로 간주됩니다. 새 모델 배포 시 v2로 업그레이드하는 것이 좋습니다.

v2에서는 관리 엔드포인트 또는 Kubernetes 엔드포인트를 제공합니다. v1과 v2를 비교하려면 엔드포인트 및 배포를 참조하세요.

관리형 온라인 엔드포인트, v2의 kubernetes 온라인 엔드포인트(Azure Kubernetes Services 및 Arc 지원 Kubernetes 포함), v1의 ACI(Azure Container Instances) 및 AKS(Kubernetes Services) 웹 서비스와 같은 여러 배포 경로가 있습니다. 이 문서에서는 ACI 웹 서비스(v1)와 관리형 온라인 엔드포인트(v2)에 대한 배포 비교에 중점을 둘 것입니다.

이 문서의 예는 다음 방법을 보여 줍니다.

  • Azure에 모델 배포
  • 엔드포인트를 사용하여 채점
  • 웹 서비스/엔드포인트 삭제

유추 리소스 만들기

  • SDK v1
    1. 모델, 환경 및 채점 스크립트를 구성합니다.

      # configure a model. example for registering a model 
      from azureml.core.model import Model
      model = Model.register(ws, model_name="bidaf_onnx", model_path="./model.onnx")
      
      # configure an environment
      from azureml.core import Environment
      env = Environment(name='myenv')
      python_packages = ['nltk', 'numpy', 'onnxruntime']
      for package in python_packages:
          env.python.conda_dependencies.add_pip_package(package)
      
      # configure an inference configuration with a scoring script
      from azureml.core.model import InferenceConfig
      inference_config = InferenceConfig(
          environment=env,
          source_directory="./source_dir",
          entry_script="./score.py",
      )
      
    2. ACI 웹 서비스 구성 및 배포:

      from azureml.core.webservice import AciWebservice
      
      # defince compute resources for ACI
      deployment_config = AciWebservice.deploy_configuration(
          cpu_cores=0.5, memory_gb=1, auth_enabled=True
      )
      
      # define an ACI webservice
      service = Model.deploy(
          ws,
          "myservice",
          [model],
          inference_config,
          deployment_config,
          overwrite=True,
      )
      
      # create the service 
      service.wait_for_deployment(show_output=True)
      

모델 등록에 대한 자세한 내용은 로컬 파일에서 모델 등록을 참조하세요.

  • SDK v2

    1. 모델, 환경 및 채점 스크립트를 구성합니다.

      from azure.ai.ml.entities import Model
      # configure a model
      model = Model(path="../model-1/model/sklearn_regression_model.pkl")
      
      # configure an environment
      from azure.ai.ml.entities import Environment
      env = Environment(
          conda_file="../model-1/environment/conda.yml",
          image="mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04:20210727.v1",
      )
      
      # configure an inference configuration with a scoring script
      from azure.ai.ml.entities import CodeConfiguration
      code_config = CodeConfiguration(
              code="../model-1/onlinescoring", scoring_script="score.py"
          )
      
    2. 온라인 엔드포인트 구성 및 만들기:

      import datetime
      from azure.ai.ml.entities import ManagedOnlineEndpoint
      
      # create a unique endpoint name with current datetime to avoid conflicts
      online_endpoint_name = "endpoint-" + datetime.datetime.now().strftime("%m%d%H%M%f")
      
      # define an online endpoint
      endpoint = ManagedOnlineEndpoint(
          name=online_endpoint_name,
          description="this is a sample online endpoint",
          auth_mode="key",
          tags={"foo": "bar"},
      )
      
      # create the endpoint:
      ml_client.begin_create_or_update(endpoint)
      
    3. 온라인 배포 구성 및 만들기:

      from azure.ai.ml.entities import ManagedOnlineDeployment
      
      # define a deployment
      blue_deployment = ManagedOnlineDeployment(
          name="blue",
          endpoint_name=online_endpoint_name,
          model=model,
          environment=env,
          code_configuration=code_config,
          instance_type="Standard_F2s_v2",
          instance_count=1,
      )
      
      # create the deployment:
      ml_client.begin_create_or_update(blue_deployment)
      
      # blue deployment takes 100 traffic
      endpoint.traffic = {"blue": 100}
      ml_client.begin_create_or_update(endpoint)
      

엔드포인트 및 배포 개념에 대한 자세한 내용은 온라인 엔드포인트란?을 참조하세요.

요청 제출

  • SDK v1

    import json
    data = {
        "query": "What color is the fox",
        "context": "The quick brown fox jumped over the lazy dog.",
    }
    data = json.dumps(data)
    predictions = service.run(input_data=data)
    print(predictions)
    
  • SDK v2

    # test the endpoint (the request will route to blue deployment as set above)
    ml_client.online_endpoints.invoke(
        endpoint_name=online_endpoint_name,
        request_file="../model-1/sample-request.json",
    )
    
    # test the specific (blue) deployment
    ml_client.online_endpoints.invoke(
        endpoint_name=online_endpoint_name,
        deployment_name="blue",
        request_file="../model-1/sample-request.json",
    )
    

리소스 삭제

  • SDK v1

    service.delete()
    
  • SDK v2

    ml_client.online_endpoints.begin_delete(name=online_endpoint_name)
    

SDK v1 및 SDK v2의 주요 기능 매핑

SDK v1의 기능 SDK v2의 대략적인 매핑
azureml.core.model.Model 클래스 azure.ai.ml.entities.Model 클래스
azureml.core.Environment 클래스 azure.ai.ml.entities.Environment 클래스
azureml.core.model.InferenceConfig 클래스 azure.ai.ml.entities.CodeConfiguration 클래스
azureml.core.webservice.AciWebservice 클래스 azure.ai.ml.entities.OnlineDeployment 클래스(및 azure.ai.ml.entities.ManagedOnlineEndpoint 클래스)
Model.deploy 또는 Webservice.deploy ml_client.begin_create_or_update(online_deployment)
Webservice.run ml_client.online_endpoints.invoke
Webservice.delete ml_client.online_endpoints.delete

자세한 내용은

v2 문서:

v1 문서: