Skip to content

アプリケーション内で をクリックすると、お使いのDataRobotバージョンに関する全プラットフォームドキュメントにアクセスできます。

Azure MLでのスコアリングコードの使用

スコアリングコードモデルをAzure MLにインポートする前に、以下のタスクを完了する必要があります。

スコアリングコードモデルをAzure MLにインポートするには:

  1. ログインコマンドを使用してAzureにログインします。

    az login
    
  2. リソースグループをまだ作成していない場合、このコマンドを使用してリソースグループを作成できます。

    az group create --location --name [--subscription] [--tags]
    

    例:

    az group create --location westus2 --name myresourcegroup
    
  3. カスタムDocker画像の保存に使用する既存のコンテナレジストリがない場合、コンテナレジストリを作成する必要があります。 独自のイメージを作成するのではなく、DataRobot Dockerイメージを使用する場合は、コンテナレジストリを作成する必要はありません。 その場合は、手順6に進みます。

    次のコマンドでコンテナを作成します。

    | az acr create --name --resource-group --sku {Basic | Classic | Premium | Standard} |
    | [--admin-enabled {false | true}] [--default-action {Allow | Deny}] [--location] |
    [--subscription] [--tags] [--workspace]
    

    例:

    az acr create --name mycontainerregistry --resource-group myresourcegroup --sku Basic
    
  4. 次のコマンドを使用して管理者アクセスをセットアップします。

    | az acr update --name --admin-enabled {false | true} |
    

    例:

    az acr update --name mycontainerregistry --admin-enabled true
    

    レジストリ認証情報を出力します。

    az acr credential show --name
    

    例:

    az acr credential show --name mycontainerregistry
    

    戻り値:

    {
    "passwords": [
        {
        "name": "password",
        "value": <password>
        },
        {
        "name": "password2",
        "value": <password>
        }
    ],
    "username": mycontainerregistry
    }
    
  5. Javaを実行するカスタムDockerイメージをアップロードします。

    | az acr build --registry [--auth-mode {Default | None}] [--build-arg] [--file] [--image] |
    [--no-format] [--no-logs] [--no-push] [--no-wait] [--platform] [--resource-group]
    [--secret-build-arg] [--subscription] [--target] [--timeout] []
    

    例:

    az acr build --registry mycontainerregistry --image myImage:1 --resource-group myresourcegroup --file Dockerfile .
    

    カスタムDocker画像の例を以下に示します。 イメージ構築の詳細については、Microsoftのドキュメントを参照してください。

    FROM ubuntu:16.04
    
    ARG CONDA_VERSION=4.5.12
    ARG PYTHON_VERSION=3.6
    
    ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
    ENV PATH /opt/miniconda/bin:$PATH
    
    RUN apt-get update --fix-missing && \
        apt-get install -y wget bzip2 && \
        apt-get clean && \
        rm -rf /var/lib/apt/lists/*
    
    RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-${CONDA_VERSION}-Linux-x86_64.sh -O ~/miniconda.sh && \
        /bin/bash ~/miniconda.sh -b -p /opt/miniconda && \
        rm ~/miniconda.sh && \
        /opt/miniconda/bin/conda clean -tipsy
    
    RUN conda install -y conda=${CONDA_VERSION} python=${PYTHON_VERSION} && \
        conda clean -aqy && \
        rm -rf /opt/miniconda/pkgs && \
        find / -type d -name __pycache__ -prune -exec rm -rf {} \;
    
    RUN apt-get update && \
        apt-get upgrade -y && \
        apt-get install software-properties-common -y && \
        add-apt-repository ppa:openjdk-r/ppa -y && \
        apt-get update -q && \
        apt-get install -y openjdk-11-jdk && \
        apt-get clean
    
  6. ワークスペースを作成していない場合は、次のコマンドを使用してワークスペースを作成します。 それ以外の場合は、手順7に進みます。

    az ml workspace create --workspace-name [--application-insights] [--container-registry]
    [--exist-ok] [--friendly-name] [--keyvault] [--location] [--resource-group] [--sku]
    [--storage-account] [--yes]
    

    例:

    az ml workspace create --workspace-name myworkspace --resource-group myresourcegroup
    
  7. Azureモデルストレージにスコアリングコードモデルを登録します。

    備考

    続行する前に、DataRobotからスコアリングコードJARファイルをエクスポートしてください。 JARファイルはリーダーボードまたはデプロイからダウンロードできます。

    az mlモデル登録 --name [--asset-path][--cc] [--description][--experiment-name] [--gb][--gc] [--model-framework][--model-framework-version] [--model-path][--output-metadata-file] [--path][--property] [--resource-group][--run-id] [--run-metadata-file][--sample-input-dataset-id] [--sample-output-dataset-id][--tag] [--workspace-name][-v]

    codegenmodelという名前のモデルを登録する場合の例を以下に示します。

    az ml model register --name codegenmodel --model-path 5cd071deef881f011a334c2f.jar --resource-group myresourcegroup --workspace-name myworkspace
    
  8. 2つの構成、および予測を実行する1つのPythonエントリスクリプトを準備します。

    Pythonエントリスクリプトを含む設定の例を以下に示します。

    • deploymentconfig.json:

      {
          "computeType": "aci",
          "containerResourceRequirements": {
              "cpu": 0.5,
              "memoryInGB": 1.0
          },
          "authEnabled": true,
          "sslEnabled": false,
          "appInsightsEnabled": false
      }
      
    • inferenceconfig.jsonDataRobot Dockerイメージを使用しない場合):

      {
          "entryScript": "score.py",
          "runtime": "python",
          "enableGpu": false,
          "baseImage": "<container-registry-name>.azurecr.io/<Docker-image-name>",
          "baseImageRegistry": {
              "address": "<container-registry-name>.azurecr.io",
              "password": <password from the step 2>,
              "username": <container-registry-name>
          }
      }
      
    • inferenceconfig.jsonDataRobot Dockerイメージを使用する場合):

      {
          "entryScript": "score.py",
          "runtime": "python",
          "enableGpu": false,
          "baseImage": "datarobotdev/scoring-inference-code-azure:latest",
          "baseImageRegistry": {
              "address": "registry.hub.docker.com"
          }
      }
      
    • score.py:

      import os
      import subprocess
      import tempfile
      import json
      from azureml.core import Model
      
      # Called when the deployed service starts
      
      def init():
      pass
      
      # Handle requests to the service
      
      def run(data):
          try:
              result_csv = ''
              data = json.loads(data)
      
              # Access your model registered in step 6 
              model_path = Model.get_model_path('codegenmodel')
              with tempfile.NamedTemporaryFile() as output_file:
                  p = subprocess.run(['java', '-jar', model_path, 'csv', '--input=-',
      '--output={}'.format(output_file.name)], input=bytearray(data['csv'].encode('utf-8')), stdout=subprocess.PIPE)
                  with open(output_file.name) as result_file:
                      result_csv = result_file.read()
      
      # Return prediction
      
      return result_csv
      except Exception as e:
          error = str(e)
          return error
      
  9. 新しい予測エンドポイントを作成します

    az ml model deploy --name [--ae] [--ai] [--ar] [--as] [--at] [--autoscale-max-replicas]
    [--autoscale-min-replicas] [--base-image] [--base-image-registry] [--cc] [--cf]
    [--collect-model-data] [--compute-target] [--compute-type] [--cuda-version] [--dc]
    [--description] [--dn] [--ds] [--ed] [--eg] [--entry-script] [--environment-name]
    [--environment-version] [--failure-threshold] [--gb] [--gc] [--ic] [--id] [--kp]
    [--ks] [--lo] [--max-request-wait-time] [--model] [--model-metadata-file] [--namespace]
    [--no-wait] [--nr] [--overwrite] [--path] [--period-seconds] [--pi] [--po] [--property]
    [--replica-max-concurrent-requests] [--resource-group] [--rt] [--sc] [--scoring-timeout-ms]
    [--sd] [--se] [--sk] [--sp] [--st] [--tag] [--timeout-seconds] [--token-auth-enabled]
    [--workspace-name] [-v]
    

    myserviceという名前の新しいエンドポイントを作成する場合の例を以下に示します。

    az ml model deploy --name myservice --model codegenmodel:1 --compute-target akscomputetarget --ic inferenceconfig.json --dc deploymentconfig.json --resource-group myresourcegroup --workspace-name myworkspace
    
  10. 予測リクエストを作成するトークンを取得します。

    az ml service get-keys --name [--path] [--resource-group] [--workspace-name] [-v]
    

    例:

    az ml service get-keys --name myservice --resource-group myresourcegroup --workspace-name myworkspace
    

    次のコマンドは、JSON応答を返します。

    {
        "primaryKey": <key>,
        "secondaryKey": <key>
    }
    

これでAzureを使用して予測リクエストを作成できるようになります。


更新しました December 5, 2023