Azure ML studio - 尝试提交管道时容器注册表错误

问题描述

我在尝试提交 Azure ML Studio 管道时遇到以下错误

Get credentials or pull docker image Failed with err: error response from daemon: get https://lgcrmldev.azurecr.io/v2/azureml/azureml_977f5bda2f6f4f634482661c121c8959/manifests/latest: unauthorized: authentication required,visit https://aka.ms/acr/authorization for more information.

我正在做的笔记本 python 代码是这样的:

# create a Python script to do the actual work and save it in the pipeline folder:

%%writefile $experiment_folder/batch_online_retail.py
import os
import numpy as np
from azureml.core import Model
import joblib


# Called when the service is loaded
def init():
    global model
    
    # Load the model
    model_path = Model.get_model_path('Random_Forest_model')
    model = joblib.load(model_path)

def run(batch):
    try:
        result = []
        
    # Process each line
    for in range (len(batch)):
        # Read the comma-delimited data into an array
        data = np.genfromtxt(f,delimiter=',')        
        # Reshape into a 2-dimensional array for prediction (model expects multiple items)
        prediction = model.predict(data.reshape(1,-1))        
        # Append prediction to results
        resultList.append("{}: {}".format(os.path.basename(f),prediction[0]))
    return resultList      
# Creating the run context
from azureml.core import Environment
from azureml.core.runconfig import DEFAULT_cpu_IMAGE
from azureml.core.runconfig import CondaDependencies

# Add dependencies required by the model
# For scikit-learn models,you need scikit-learn
# For parallel pipeline steps,you need azureml-core and azureml-dataprep[fuse]
cd = CondaDependencies.create(conda_packages=['scikit-learn','pip'],pip_packages=['azureml-defaults','azureml-core','azureml-dataprep[fuse,pandas]'])

batch_env = Environment(name='batch_environment')
batch_env.python.conda_dependencies = cd
batch_env.docker.enabled = True
batch_env.docker.base_image = DEFAULT_cpu_IMAGE
print('Configuration ready.')

# Creating the ParallelRunStep
from azureml.pipeline.steps import Parallelrunconfig,ParallelRunStep
from azureml.pipeline.core import PipelineData

default_ds = ws.get_default_datastore()

output_dir = PipelineData(name='inferences',datastore=default_ds,output_path_on_compute='online-retail/results')

parallel_run_config = Parallelrunconfig(
    source_directory=experiment_folder,entry_script="batch_online_retail.py",mini_batch_size="5",error_threshold=10,output_action="append_row",environment=batch_env,compute_target=inference_cluster,node_count=2)

parallelrun_step = ParallelRunStep(
    name='batch-score-retail',parallel_run_config=parallel_run_config,inputs=[batch_data_set.as_named_input('online_retail_batch')],output=output_dir,arguments=[],allow_reuse=True
)

print('Steps defined')

最后,

# Create an Azure ML experiment in your workspace,put the step into a pipeline and run it
from azureml.core import Experiment
from azureml.pipeline.core import Pipeline

pipeline = Pipeline(workspace=ws,steps=[parallelrun_step])
pipeline_run = Experiment(ws,'online-retail-deployment-cf').submit(pipeline)
pipeline_run.wait_for_completion(show_output=True)

在这最后一步中,我不断收到上述错误

我的容器注册表在访问控制面板中有我的用户和 Azure ML 资源作为贡献者,所以我认为这不是权限不足。

我发现这个 Microsoft 页面似乎修复了我遇到的错误https://docs.microsoft.com/en-us/azure/container-registry/container-registry-faq#docker-push-succeeds-but-docker-pull-fails-with-error-unauthorized-authentication-required

但我不明白如何实施建议的修复。这是因为笔记本使用的 Docker 映像位于 Azure ML 中创建的计算实例内,我们的访问权限有限。

关于问题出在哪里以及如何解决它的任何想法?

先谢谢你, 卡拉

解决方法

根据示例here,我认为您需要为存储在 Azure Container Registry 中的 docker 镜像配置环境变量:

batch_env = Environment(name='batch_environment')
batch_env.python.conda_dependencies = cd
batch_env.docker.enabled = True
# Set the container registry information.
batch_env.docker.base_image_registry.address = "myregistry.azurecr.io"
batch_env.docker.base_image_registry.username = "username"
batch_env.docker.base_image_registry.password = "password"
batch_env.docker.base_image = "myregistry.azurecr.io/DEFAULT_CPU_IMAGE"