Run failed: User program failed with ModuleNotFoundError: No module named 'amlrun' in Azure ML Experiment

Run failed: User program failed with ModuleNotFoundError: No module named 'amlrun' in Azure ML Experiment

我正在使用 VS Code 在 Azure 门户中提交机器学习实验。 运行 实验时出现以下错误:

运行 失败:用户程序因 ModuleNotFoundError 失败:没有名为 'amlrun'

的模块

这是代码结构:

.vscode(json 配置文件)

aml_config

脚本

----- amlrun.py(具有部分功能的脚本)

----- model_training.py(创建和保存模型的脚本)

这是配置文件:

{
    "script": "model_training.py",
    "framework": "Python",
    "communicator": "None",
    "target": "testazure",
    "environment": {
        "python": {
            "userManagedDependencies": false,
            "condaDependencies": {
                "dependencies": [
                    "python=3.6.2",
                    "scikit-learn",
                    "numpy",
                    "pandas",
                    {
                        "pip": [
                            "azureml-defaults"
                        ]
                    }
                ]
            }
        },
        "docker": {
            "baseImage": "mcr.microsoft.com/azureml/base:0.2.4",
            "enabled": true,
            "baseImageRegistry": {
                "address": null,
                "username": null,
                "password": null
            }
        }
    },
    "history": {
        "outputCollection": true,
        "snapshotProject": false,
        "directoriesToWatch": [
            "logs"
        ]
    }
}

我错过了什么吗? 谢谢

当你的训练脚本是 运行 天蓝色时,它无法找到你所有的本地导入,即 amlrun.py 脚本。

提交给 Azure 的训练作业首先使用您的文件构建一个 docker 图像并运行实验;但在这种情况下,扩展名不包括 amlrun.py

这可能是因为当您提交带有扩展名的训练作业时,打开的 visual studio 代码 window 未指向 scripts 文件夹中。

摘自对 previously raised github issue 的回复之一:

The extension currently requires the script you are working on to be in the folder that is open in VS Code and not in a sub-directory.


要解决此问题,您可以执行以下任一操作

  1. 您需要重新打开 scripts 文件夹而不是父目录中的 Visual Studio 代码。

  2. script 目录中的所有文件移动到其父目录中。


如果您正在寻找更灵活的方式来提交培训作业和管理反洗钱 - 您可以使用 azure machine learning sdk for python。

可以在以下链接中找到一些使用 SDK 管理过期的示例:

  1. Scikit Learn Model Training Docs

  2. Basic Pytorch Model Training and Deployment Example Repo