【问题标题】:Azure ML not able to create conda environment (exit code: -15)Azure ML 无法创建 conda 环境(退出代码:-15)
【发布时间】:2021-08-10 20:18:19
【问题描述】:

当我尝试在笔记本中运行this notebook 中定义的实验时,我在创建 conda env 时遇到了错误。执行以下单元格时发生错误:

from azureml.core import Experiment, ScriptRunConfig, Environment
from azureml.core.conda_dependencies import CondaDependencies
from azureml.widgets import RunDetails


# Create a Python environment for the experiment
sklearn_env = Environment("sklearn-env")

# Ensure the required packages are installed (we need scikit-learn, Azure ML defaults, and Azure ML dataprep)
packages = CondaDependencies.create(conda_packages=['scikit-learn','pip'],
                                    pip_packages=['azureml-defaults','azureml-dataprep[pandas]'])
sklearn_env.python.conda_dependencies = packages

# Get the training dataset
diabetes_ds = ws.datasets.get("diabetes dataset")

# Create a script config
script_config = ScriptRunConfig(source_directory=experiment_folder,
                              script='diabetes_training.py',
                              arguments = ['--regularization', 0.1, # Regularizaton rate parameter
                                           '--input-data', diabetes_ds.as_named_input('training_data')], # Reference to dataset
                              environment=sklearn_env)

# submit the experiment
experiment_name = 'mslearn-train-diabetes'
experiment = Experiment(workspace=ws, name=experiment_name)
run = experiment.submit(config=script_config)
RunDetails(run).show()
run.wait_for_completion() 

每次运行此程序时,我总是面临创建 conda env 的问题,如下所示:

Creating conda environment...
Running: ['conda', 'env', 'create', '-p', '/home/azureuser/.azureml/envs/azureml_000000000000', '-f', 'azureml-environment-setup/mutated_conda_dependencies.yml']
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... done
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done

Installing pip dependencies: ...working... 

Attempting to clean up partially built conda environment: /home/azureuser/.azureml/envs/azureml_000000000000
Remove all packages in environment /home/azureuser/.azureml/envs/azureml_000000000000:
Creating conda environment failed with exit code: -15

我在互联网上找不到任何有用的东西,而且这不是唯一失败的脚本。当我尝试进行其他实验时,我有时会遇到这个问题。在上述情况下有效的一种解决方案是将熊猫从 pip 移动到 conda,它能够创建 coonda env。下面的例子:

# Ensure the required packages are installed (we need scikit-learn, Azure ML defaults, and Azure ML dataprep)
packages = CondaDependencies.create(conda_packages=['scikit-learn','pip'],
                                    pip_packages=['azureml-defaults','azureml-dataprep[pandas]'])

# Ensure the required packages are installed (we need scikit-learn, Azure ML defaults, and Azure ML dataprep)
packages = CondaDependencies.create(conda_packages=['scikit-learn','pip','pandas'],
                                    pip_packages=['azureml-defaults','azureml-dataprep'])

错误消息(或来自 Azure 的日志)也没有多大帮助。如果有合适的解决方案,将不胜感激。

编辑:我最近开始学习使用 Azure 进行机器学习,所以如果我不确定我是否遗漏了什么?我认为示例笔记本应该可以正常工作,因此提出了这个问题。

【问题讨论】:

    标签: anaconda azure-machine-learning-service


    【解决方案1】:

    简短回答

    以前完全处于你的位置。此代码示例似乎有点过时了。以this notebook为参考,可以试试下面的吗?

    packages = CondaDependencies.create(
        pip_packages=['azureml-defaults','scikit-learn']
    )
    

    更长的答案

    Using pip with Conda 并不总是一帆风顺。在这种情况下,conda 没有报告 pip 遇到的问题。解决方案是在本地创建和测试这个环境,我们可以获得更多信息,这至少会给您提供更多信息的错误消息。

    1. 安装 anaconda 或 miniconda(或使用预装 conda 的 Azure ML 计算实例)
    2. 创建一个名为 environment.yml 的文件,如下所示
    name: aml_env
    dependencies:
     - python=3.8
     - pip=21.0.1
     - pip:
        - azureml-defaults
        - azureml-dataprep[pandas]
        - scikit-learn==0.24.1
    
    1. 使用命令conda env create -f environment.yml 创建此环境。
    2. 响应任何发现的错误消息
    3. 如果没有错误,请像这样将这个新的 environment.yml 与 Azure ML 一起使用
    sklearn_env = Environment.from_conda_specification(name = 'sklearn-env', file_path = './environment.yml')
    

    更多上下文

    我猜发生的错误是当您从 conda 环境文件中引用 pip 要求文件时。在这种情况下,conda 调用pip install -r requirements.txt,如果该命令出错,conda 将无法报告错误。

    requirements.txt

    scikit-learn==0.24.1
    azureml-dataprep[pandas]
    

    environment.yml

    name: aml_env
    dependencies:
     - python=3.8
     - pip=21.0.1
     - pip:
        - -rrequirements.txt
    

    【讨论】:

    • 感谢@Anders-Swanson,这个答案完全有道理。我想在计算实例终端中试一试,但它总是卡在“正在安装 pip 依赖项:...工作...”。我不确定到底是什么问题。但这个答案是我调查的一个很好的起点。一旦我弄清楚了,我也会接受答案。干杯! PS:我觉得应该是scikit-learn==0.24.1
    • 刚刚更新了更多关于为什么我认为错误正在发生的上下文。 azureml-dataprep 现在也是 azureml-defaults 的一部分
    • 我认为问题出在azureml-dataprep[pandas]。如果我在任何地方都有它(即使在单独的requirements.txt 中),它总是会冻结。我尝试将azureml-datapreppandas 分开,效果很好。非常感谢@Anders-Swanson!老实说,我认为调试问题需要做很多工作。
    • @11t -- 同意。肯定很难深究。当 SDK 发展得如此之快时,维护最新的文档同样困难。此外,当涉及到 Python 开源库时,这种依赖疯狂绝对是本课程的标准。lol
    • 我完全同意,但是当我们谈论这种规模的应用程序时,文档和开发应该始终齐头并进。也许我什至不应该提到这个 MS 回购?!手指交叉着其余的笔记本,我现在知道会发生什么了。
    【解决方案2】:

    查看以前的笔记本05 - Train Models.ipynb 对我有用:

    packages = CondaDependencies.create(conda_packages=['pip', 'scikit-learn'],
                                        pip_packages=['azureml-defaults'])
    

    你必须:

    1. pip_packages 中删除'azureml-dataprep[pandas]'
    2. 更改conda_packages 的顺序 - pip 应该在前

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-28
      • 1970-01-01
      • 1970-01-01
      • 2020-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多