最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Azure AI command job returns HttpResponseError - Stack Overflow

programmeradmin1浏览0评论

I'm trying to start a command job in a notebook in Azure AI. I have azure-ai-ml version 1.20.0.

All of the resources referred to below (compute, environment) work correctly for other tasks. I can start pipeline jobs just fine. When I follow the analogous procedure to start a command job, I get an HttpResponseError. Here's what I'm doing:

YAML environment specification

name: my-custom-env
channels:
  - conda-fe
dependencies:
  - python=3.9
  - (...several others)
  - pip:
    - inference-schema[numpy-support]==1.3.0
    - (...several others)

Create environment

from azure.ai.ml.entities import Environment
from azure.identity import DefaultAzureCredential
from azure.ai.ml import MLClient
credential = DefaultAzureCredential()
ml_client = MLClient(
    credential=credential,
    subscription_id='my-subscription-id',
    resource_group_name='my-resource-group-name',
    workspace_name='my-workspace-name'
)
env = Environment(
    name='my-custom-env',
    description='Custom environment for my project',
    conda_file='custom_environment.yaml',
    image='mcr.microsoft/azureml/openmpi4.1.0-ubuntu20.04:latest',
    version='0.0.0',
)
env = ml_client.environments.create_or_update(env)

The environment itself seems to be fine. I can use it for jobs that I create in other ways (i.e., not with command()) and everything works.

YAML job specification

jobs/run_command.yaml:

name: job_name
display_name: Job display name
experiment_name: my_experiment_name
type: command
compute: azureml:my-compute-resource
environment: azureml:my-custom-env:0.0.0
code: .
command: echo "foo"

Attempt to run job

from azure.ai.ml import load_job
job_config = load_job(source='jobs/run_command.yaml')
job = ml_client.jobs.create_or_update(job_config)

I get the following error message:

HttpResponseError: (UserError) The given resource scope /subscriptions/my-subscription-id/resourceGroups/my_resource_group/providers/Microsoft.MachineLearningServices/workspaces/my_workspace/environments/ is not valid; scope should start like /subscriptions/<subscriptionId>/resourceGroups/<resourceGroup>/providers/Microsoft.MachineLearningServices/workspaces/<workspaceName>.

Exactly the same thing happens if I specify the job directly using command(), as in this example:

from azure.ai.ml import command
job_config = command(
    code='.',
    command='echo "foo"',
    environment=ml_client.environments.get('my-custom-env', version='0.0.0'),
    compute='my-compute-resource',
    experiment_name='my_experiment_name',
    name='job_name',
    display_name='Job display name'
)
ml_client.create_or_update(job_config)

This issue may involve the same problem - at any rate, it's another example of people submitting a command job and getting an http-related error. But that discussion is focused on getting a more informative error message, not on solving the underlying problem. And, at any rate, it's not clear that the actual error is the same one.

Since the error message seems to be complaining about a reference to an environment, I've tried a bunch of different ways of specifying the environment: by name, by image, by retrieving it from the current workspace, etc. Nothing changed this error message.

I'm trying to start a command job in a notebook in Azure AI. I have azure-ai-ml version 1.20.0.

All of the resources referred to below (compute, environment) work correctly for other tasks. I can start pipeline jobs just fine. When I follow the analogous procedure to start a command job, I get an HttpResponseError. Here's what I'm doing:

YAML environment specification

name: my-custom-env
channels:
  - conda-fe
dependencies:
  - python=3.9
  - (...several others)
  - pip:
    - inference-schema[numpy-support]==1.3.0
    - (...several others)

Create environment

from azure.ai.ml.entities import Environment
from azure.identity import DefaultAzureCredential
from azure.ai.ml import MLClient
credential = DefaultAzureCredential()
ml_client = MLClient(
    credential=credential,
    subscription_id='my-subscription-id',
    resource_group_name='my-resource-group-name',
    workspace_name='my-workspace-name'
)
env = Environment(
    name='my-custom-env',
    description='Custom environment for my project',
    conda_file='custom_environment.yaml',
    image='mcr.microsoft/azureml/openmpi4.1.0-ubuntu20.04:latest',
    version='0.0.0',
)
env = ml_client.environments.create_or_update(env)

The environment itself seems to be fine. I can use it for jobs that I create in other ways (i.e., not with command()) and everything works.

YAML job specification

jobs/run_command.yaml:

name: job_name
display_name: Job display name
experiment_name: my_experiment_name
type: command
compute: azureml:my-compute-resource
environment: azureml:my-custom-env:0.0.0
code: .
command: echo "foo"

Attempt to run job

from azure.ai.ml import load_job
job_config = load_job(source='jobs/run_command.yaml')
job = ml_client.jobs.create_or_update(job_config)

I get the following error message:

HttpResponseError: (UserError) The given resource scope /subscriptions/my-subscription-id/resourceGroups/my_resource_group/providers/Microsoft.MachineLearningServices/workspaces/my_workspace/environments/ is not valid; scope should start like /subscriptions/<subscriptionId>/resourceGroups/<resourceGroup>/providers/Microsoft.MachineLearningServices/workspaces/<workspaceName>.

Exactly the same thing happens if I specify the job directly using command(), as in this example:

from azure.ai.ml import command
job_config = command(
    code='.',
    command='echo "foo"',
    environment=ml_client.environments.get('my-custom-env', version='0.0.0'),
    compute='my-compute-resource',
    experiment_name='my_experiment_name',
    name='job_name',
    display_name='Job display name'
)
ml_client.create_or_update(job_config)

This issue may involve the same problem - at any rate, it's another example of people submitting a command job and getting an http-related error. But that discussion is focused on getting a more informative error message, not on solving the underlying problem. And, at any rate, it's not clear that the actual error is the same one.

Since the error message seems to be complaining about a reference to an environment, I've tried a bunch of different ways of specifying the environment: by name, by image, by retrieving it from the current workspace, etc. Nothing changed this error message.

Share Improve this question edited Mar 20 at 22:29 A. S. K. asked Mar 13 at 20:40 A. S. K.A. S. K. 2,82616 silver badges26 bronze badges 2
  • How do you create custom env and ml_client object? please add those details. – JayashankarGS Commented Mar 20 at 9:27
  • @JayashankarGS - I've updated the post to include this information. – A. S. K. Commented Mar 20 at 22:29
Add a comment  | 

2 Answers 2

Reset to default 1

Try creating environment without explicitly passing version and get the environment object with passing latest version or name.

env = Environment(
    name='my-custom-env-2',
    description='Custom environment for my project',
    conda_file='./environment/conda-yamls/pydata.yml',
    image='mcr.microsoft/azureml/openmpi4.1.0-ubuntu20.04:latest'
)
env = ml_client.environments.create_or_update(env)

and pass it like below.

from azure.ai.ml import command
job_config = command(
    code='.',
    command='echo "foo"',
    environment=ml_client.environments.get('my-custom-env-2',version=1),
    compute='cpu-cluster',
    experiment_name='my_experiment_name',
    name='job_name3',
    display_name='Job display name'
)
ml_client.create_or_update(job_config)

If this doesn't working just try running the command job with built in environment.

from azure.ai.ml import command
job_config = command(
    code='.',
    command='echo "foo"',
    environment="azureml://registries/azureml/environments/mlflow-py312-inference/versions/8",
    compute='cpu-cluster',
    experiment_name='my_experiment_name',
    name='job_name5',
    display_name='Job display name'
)
ml_client.create_or_update(job_config)

If this works, then something wrong with custom environment and need to build correctly.

The root cause of the problem was that I was didn't change the job name between runs. Thanks to @JayashankarGS's answer for showing, correctly, an example with updated job names: job_name3, job_name5, etc. The YAML file and command() statement in the original question work correctly when name is changed to be unique or omitted entirely.

发布评论

评论列表(0)

  1. 暂无评论