ModelScope环境安装

本篇文章介绍ModelScope使用所需的环境配置指南。

ModelScope Library目前支持模型和数据集的获取和管理,以及基于PyTorch、Tensorflow等学习框架基础上进行模型训练、推理, 在Python 3.8+, Pytorch 1.11+, Tensorflow上测试可运行。

注: 大部分语音模型当前需要在Linux环境上使用,并且推荐使用python3.8 + tensorflow 2.13.0 + torch 2.0.1 的组合。部分模态模型可以在mac,windows等环境上安装使用,少部分模型需要tensorflow1.15.0。

基于ModelScope官方镜像直接使用#

为了让大家能无需配置环境直接用上ModelScope平台上的模型,ModelScope除了在网站上集成了Notebook在线编程环境以外,同时也提供了官方镜像,方便有需要的开发者获取。基于官方镜像,可以跳过所有的环境安装和配置,直接使用,当前我们提供的最新版本的CPU镜像和GPU镜像可从如下地址获取:

最新镜像#

CPU环境镜像(python3.11):

modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py311-torch2.3.1-1.25.0
modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py311-torch2.3.1-1.25.0
modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py311-torch2.3.1-1.25.0

GPU环境镜像(python3.11):

modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.1.0-py311-torch2.3.1-tf2.16.1-1.25.0
modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.1.0-py311-torch2.3.1-tf2.16.1-1.25.0
modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.1.0-py311-torch2.3.1-tf2.16.1-1.25.0

另外,特别针对LLM和AIGC模型的运行环境,我们提供了基于PyTorch:2.6.0及vLLM:0.8.x/LMDeploy:0.7.x的镜像,但请注意该版本对mmcv框架的传统cv模型不兼容:

modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-1.25.0-LLM
modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-1.25.0-LLM
modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-1.25.0-LLM

正常情况下,我们均推荐您使用最新版本镜像。 极少部分模型存在和最新镜像不兼容情况,可以参考模型卡片,使用下文提供的历史镜像

Python环境安装配置#

首先,参考文档 安装配置Anaconda环境。 安装完成后,执行如下命令为ModelScope library创建对应的Python环境。

 

conda create -n modelscope python=3.11 conda activate modelscope

ModelScope Library 安装#

pip安装#

ModelScope Library由核心hub支持,框架,以及不同领域模型的对接组件组成。根据您实际使用的场景,可以选择不同的安装选项。

如果只需要通过ModelScope SDK,或者ModelScope命令行工具来下载模型,可以只最轻量化的安装ModelScope的核心hub支持:

 

pip install modelscope

如果需要更完整的使用ModelScope平台上的一系列框架能力,包括数据集的加载,外部模型的使用等,则推荐使用"framework"的安装选项,也就是:

 

pip install modelscope[framework]

以上两种方法,都不涉及ModelScope上原生模型的集成。要使用ModelScope来实现各种领域模型的使用,包括基于NLP、CV、语音、多模态,等不同领域的模型,来进行模型推理以及模型训练、微调等能力,则需要根据具体领域,通过安装选项,来安装额外的依赖。同时也涉及对应的PyTorch,Tensorflow等机器学习框架的安装。

深度学习框架依赖的安装#

注: 机器学习框架本身包通常较大,客观上在国内使用pip安装的时候,如果默认是用海外的pypi源的话,下载速度较慢。这种情况下,可以考虑通过pip的"-i"命令行选项,来手工配置仓库来源,例如"-i Simple Index " 可以将配置仓库来源使用"清华源"。例如:

 

pip3 install torch -i https://pypi.tuna.tsinghua.edu.cn/simple

常见的可用源还包括 "-i Simple Index", "-i Verifying - USTC Mirrors "等等,可以根据自己的网络条件自行选择。

此外,如果您在使用阿里云上环境(例如ECS,DSW等),通过配置如下pip源,可以加快安装速度

 

pip config set global.index-url https://mirrors.cloud.aliyuncs.com/pypi/simple pip config set install.trusted-host mirrors.cloud.aliyuncs.com

注: 如果在安装过程中遇到错误,可以前往常见问题查找解决方案。

 

pip3 install torch torchvision torchaudio

 

pip install --upgrade tensorflow==2.13.0 # 仅支持 CPU 的版本

操作系统

linux

windows

MacOS

Python

python3.7

python3.8

深度学习框架

pytorch

tensorflow1.x

tensorflow2.x

计算平台

CPU

GPU

运行此命令

pip3 install torch==1.11.0 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu

分领域ModelScope模型依赖的安装#

在ModelScope基础框架以及PyTorch,Tensorflow等机器学习框架基础之上,ModelScope对于不同领域的各种模型的集成,为开发者提供了通过相对统一的接口,来调用不同领域的模型。通常不同领域的模型所需要的依赖,也会有所不同,所以ModelScope提供了针对不同领域模型的,不同的安装选项。方便开发者针对自己所感兴趣的模型所处领域,实现领域模型有选择性的依赖安装。 具体而言,

  • 如仅需体验NLP领域模型,可执行如下命令安装领域依赖(因部分依赖由ModelScope独立host,所以需要使用"-f"参数):
 

pip install "modelscope[nlp]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

如果使用miniconda环境,需要提前安装setuptools_scm。

  • 如仅需体验CV领域模型,可执行如下命令安装领域依赖(因部分依赖由ModelScope独立host,所以需要使用"-f"参数):
 

pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

  • 如仅需体验语音领域模型,可执行如下命令安装领域依赖(因部分依赖由ModelScope独立host,所以需要使用"-f"参数):
 

pip install "modelscope[audio]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

注意:当前大部分语音模型需要在Linux环境上使用,并且推荐使用python3.8。

  • 如仅需体验多模态领域的模型,可执行如下命令安装领域依赖:
 

pip install "modelscope[multi-modal]"

  • 如仅需体验科学计算领域模型,请执行如下命令:
 

pip install "modelscope[science]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

  1. 如果您已经安装过ModelScope,但是需要升级使用新版发布的Library,可以使用
 

pip install modelscope --upgrade

来升级到最新版本。也可以通过指定特定版本号来选择选择某一版本。 2. 目前极少部分部分模型仅支持tensorflow1.15.5的Linux环境使用。 其他大部分模型可以在windows、mac(x86)上安装使用。

  1. 语音领域中一部分模型使用了三方库SoundFile进行wav文件处理,在Linux系统上用户需要手动安装SoundFile的底层依赖库libsndfile,在Windows和MacOS上会自动安装不需要用户操作。详细信息可参考SoundFile官网。以Ubuntu系统为例,用户需要执行如下命令:
 

sudo apt-get update sudo apt-get install libsndfile1

  1. CV领域的少数模型,需要安装mmcv-full, 如果运行过程中提示缺少mmcv,请参考mmcv安装手册进行安装。 注意这里需要安装的是mmcv 1.x版本(mmcv-full),请不要安装mmcv 2.0及以上版本。 这里提供一个最简版的mmcv-full安装步骤,但是要达到最优的mmcv-full的安装效果(包括对于cuda版本的兼容),请根据自己的实际机器环境,以mmcv官方安装手册为准。
 

pip uninstall mmcv && pip uninstall mmcv-full # 如果已经安装过简装版本的mmcv,请先卸载 pip install -U openmim mim install mmcv-full # 如果您使用python3.10,torch 2.1.0和2.1.1,cuda 11.8.0,12.1.0,可以按照如下方式安装 # 版本1.7.0+torch2.1.1cu121 1.7.0+torch2.1.0cu121 1.7.0+torch2.1.1cu118 1.7.0+torch2.1.0cu118 pip install mmcv_full=='1.7.0+torch2.1.1cu121' -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

安装验证#

安装成功后,即可使用对应领域模型进行推理,训练等操作。这里我们以NLP领域为例,在"pip install modelscope[nlp]"后,可执行如下命令,运行中文分词任务,来验证安装是否正确:

 

python -c "from modelscope.pipelines import pipeline;print(pipeline('word-segmentation')('今天天气不错,适合 出去游玩'))"

历史镜像#

镜像版本命名规则#

  • CPU:
    OS[version]-py[version]-torch[version]-tf[version]-[modelscope_version], 例如:
    ubuntu22.04-py310-torch2.1.2-tf2.14.0-1.13.1,表示镜像基于ubuntu22.04,python3.10,torch2.1.0,tensorflow 2.14.0, modelscope 1.13.1构建。
  • GPU:
    OS[version]-cuda[version]-py[version]-torch[version]-tf[version]-[modelscope_version],例如:
    ubuntu22.04-cuda12.1.0-py310-torch2.1.2-tf2.14.0-1.13.1,表示镜像基于ubuntu22.04,cuda12.1.0,python3.10,torch2.1.0,tensorflow 2.14.0, modelscope 1.13.1构建。

历史版本#

CPU环境镜像(python3.10):

registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py310-torch2.1.2-tf2.14.0-1.12.0
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py310-torch2.1.2-tf2.14.0-1.12.0
registry.us-west-1.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-py310-torch2.1.2-tf2.14.0-1.12.0

GPU环境镜像(python3.10):

registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.1.0-py310-torch2.1.2-tf2.14.0-1.12.0
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.1.0-py310-torch2.1.2-tf2.14.0-1.12.0
registry.us-west-1.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.1.0-py310-torch2.1.2-tf2.14.0-1.12.0

CPU环境镜像(python3.7):

registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1
registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-1.6.1

CPU环境镜像(python3.8):

registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch1.11.0-tf1.15.5-1.8.1
registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch1.11.0-tf1.15.5-1.8.1
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf1.15.5-1.8.1
registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf1.15.5-1.8.1

GPU环境镜像(python3.7):

registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1
registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-1.6.1

GPU环境镜像(python3.8):

registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py38-torch1.11.0-tf1.15.5-1.8.1
registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.3.0-py38-torch1.11.0-tf1.15.5-1.8.1
registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.7.1-py38-torch2.0.1-tf1.15.5-1.8.1
registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.7.1-py38-torch2.0.1-tf1.15.5-1.8.1

CPU环境镜像(python3.8):

registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf2.13.0-1.9.5
registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf2.13.0-1.9.5
registry.us-west-1.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-py38-torch2.0.1-tf2.13.0-1.9.5

GPU环境镜像(python3.8):

registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.5
registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.5
registry.us-west-1.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值