文档首页/ AI开发平台ModelArts/ 常见问题/ Standard推理部署/ 模型管理/ 导入模型/ 导入模型时,模型配置文件中的安装包依赖参数如何编写?
更新时间:2024-10-28 GMT+08:00

导入模型时,模型配置文件中的安装包依赖参数如何编写?

问题描述

从OBS中或者从容器镜像中导入模型时,开发者需要编写模型配置文件。模型配置文件描述模型用途、模型计算框架、模型精度、推理代码依赖包以及模型对外API接口。配置文件为JSON格式。配置文件中的“dependencies”,表示配置模型推理代码需要的依赖包,需要提供依赖包名、安装方式和版本约束的信息,详细参数见模型配置文件编写说明。导入模型时,模型配置文件中的安装包依赖参数“dependencies”如何编写?

解决方案

安装包存在前后依赖关系。例如您在安装“mmcv-full”之前,需要完成“Cython”“pytest-runner”“pytest”的安装,在配置文件中,您需要把“Cython”“pytest-runner”“pytest”写在“mmcv-full”的前面。

示例如下:

"dependencies": [
    {
    "installer": "pip",
    "packages": [
        {
            "package_name": "Cython"
        },
        {
            "package_name": "pytest-runner"
        },
        {
            "package_name": "pytest"
        },
        {
            "restraint": "ATLEAST",
            "package_version": "5.0.0",
            "package_name": "Pillow"
        },
        {
            "restraint": "ATLEAST",
            "package_version": "1.4.0",
            "package_name": "torch"
        },
        {
            "restraint": "ATLEAST",
            "package_version": "1.19.1",
            "package_name": "numpy"
        },
        {
            "package_name": "mmcv-full"
        }
      ]
   }
]

当"mmcv-full"安装失败,原因可能是基础镜像中没有安装gcc,无法编译导致安装失败,此时需要用户使用线下wheel包安装。

示例如下:

"dependencies": [
    {
    "installer": "pip",
    "packages": [
        {
            "package_name": "Cython"
        },
        {
            "package_name": "pytest-runner"
        },
        {
            "package_name": "pytest"
        }, 
        {
            "restraint": "ATLEAST",
            "package_version": "5.0.0",
            "package_name": "Pillow"
        },
        {
            "restraint": "ATLEAST",
            "package_version": "1.4.0",
            "package_name": "torch"
        },
        {
            "restraint": "ATLEAST",
            "package_version": "1.19.1",
            "package_name": "numpy"
        },
        {
            "package_name": "mmcv_full-1.3.9-cp37-cp37m-manylinux1_x86_64.whl"
        }
      ]
    }
]

模型配置文件的“dependencies”支持多个“dependency”结构数组以list形式填入。

示例如下:
"dependencies": [
    {
    "installer": "pip",
    "packages": [
        {
            "package_name": "Cython"
        },
        {
            "package_name": "pytest-runner"
        },
        {
            "package_name": "pytest"
        }, 
        {
            "package_name": "mmcv_full-1.3.9-cp37-cp37m-manylinux1_x86_64.whl"
        }
      ]
    },
    {
    "installer": "pip",
    "packages": [
        {
            "restraint": "ATLEAST",
            "package_version": "5.0.0",
            "package_name": "Pillow"
        },
        {
            "restraint": "ATLEAST",
            "package_version": "1.4.0",
            "package_name": "torch"
        },
        {
            "restraint": "ATLEAST",
            "package_version": "1.19.1",
            "package_name": "numpy"
        },
      ]
    }
]