FastGPU是一套阿里云推出的人工智能计算任务构建工具,提供便捷的接口和命令行,供您在阿里云IaaS资源上构建人工智能计算任务。本文以Ubuntu 18.04 64位为例介绍如何安装和使用FastGPU,并列出了FastGPU支持的运行时接口和命令行。
前提条件
说明 您的ECS实例和本地机器、阿里云Cloud Shell工具等均可以作为客户端安装FastGPU来构建人工智能计算任务。
背景信息
FastGPU作为衔接您的线下人工智能算法和线上阿里云海量GPU计算资源的关键一环,方便您将人工智能计算任务构建在阿里云的IaaS资源上。使用FastGPU构建人工智能计算任务时,您无需关心IaaS层的计算、存储、网络等资源部署操作,达到简单适配、一键部署、随处运行的效果。
FastGPU提供以下两套组件:
FastGPU的组成模块如下图所示。
安装FastGPU
运行FastGPU demo
本步骤以在Cloud Shell中运行BERT finetune任务为例,展示如何使用FastGPU。demo中自动创建的实例规格为ecs.gn6v-c10g1.20xlarge(8卡V100机型),任务部署时间约2.5分钟,训练时长约11.5分钟,总共耗时约14分钟,训练精度达到0.88以上。
运行时说明
您可以通过ncluster的接口将人工智能训练和推理脚本快速部署到云上进行计算。ncluster的接口主要提供以下功能:
- 获取阿里云账号AccessKey、默认地域、默认可用区等信息。
export ALIYUN_ACCESS_KEY_ID=L**** # Your actual aliyun access key id export ALIYUN_ACCESS_KEY_SECRET=v**** # Your actual aliyun access key secret export ALIYUN_DEFAULT_REGION=cn-hangzhou # The actual region the resource you want to use export ALIYUN_DEFAULT_ZONE=cn-hangzhou-i # The actual zone of the region you want to use
- ncluster是一套Python库,使用时需要在Python脚本中导入ncluster。
import ncluster
- 创建任务所需的资源或者复用已经存在的资源。
job = ncluster.make_job(name=args.name, run_name=f"{args.name}-{args.machines}", num_tasks=args.machines, image_name=IMAGE_NAME, instance_type=INSTANCE_TYPE)
ncluster.make_job的参数如下表所示。参数名称 参数说明 参数示例 name job的名称。 'perseus-bert' run_name 运行时的环境名,一般设置为job名+实例数量。 f"perseus-bert-1" num_tasks 需要创建实例的个数。 1 表示创建1台实例,名称为task0.perseus-bert,对应perseus-bert.tasks[0]。
image_name 实例使用的镜像,支持公共镜像和自定义镜像。 'ubuntu_18_04_64_20G_alibase_20190624.vhd' instance_type 需要创建实例的实例规格。 'ecs.gn6v-c10g1.20xlarge' - 运行任务。支持以job或task的形式运行任务,job为一组task。
说明 job和task支持相同的API,调用job的API作用于所有的task,调用task的API只作用于指定的task。示例如下:
- 调用job的API
# 为job中所有实例打开perseus-bert文件夹 job.run('cd perseus-bert') # 将当前目录中的perseus-bert文件夹上传到job中所有实例的/root目录下 job.upload('perseus-bert')
- 调用task的API
# 为task0对应实例打开perseus-bert文件夹 job.tasks[0].run('cd perseus-bert') # 将当前目录中的perseus-bert文件夹上传到task0对应实例的/root目录下 job.tasks[0].upload('perseus-bert')
- 调用job的API
命令行说明
您可以使用ecluster命令方便地管理资源的生命周期、查看运行过程的日志等操作。ecluster支持的命令如下表所示。
命令 | 命令说明 | 命令示例 |
---|---|---|
export | 获取阿里云账号的信息,在本地机器使用FastGPU时需要获取AccessKey、默认地域、默认可用区等信息。 |
|
ecluster [help,-h,--help] | 查看所有ecluster命令。 | ecluster --help |
ecluster {command} --help | 查看指定的ecluser命令。 | ecluster ls --help |
ecluster create --config create.cfg | 基于配置文件创建实例。create.cfg文件定义实例的配置环境,运行命令前您需要先创建create.cfg文件,具体内容请参见表格下方的示例。 | ecluster create --config create.cfg |
ecluster create --name {instance_name} --machines {instance_num} ... | 基于参数创建实例。 | ecluster create --name task0.ncluster-v100 --machines 1 |
ecluster ls | 列出已自动创建的实例。包括以下信息:
|
ecluster ls |
ecluster ssh {instance_name} | 登录指定的实例。 | ecluster ssh task0.ncluster-v100 |
ecluster tmux {instance_name} | 连接到运行中的任务,如果没有tmux会话,则使用ssh连接。 | ecluster tmux task0.ncluster-v100 |
ecluster stop {instance_name} | 停止指定的实例。 |
|
ecluster start {instance_name} | 启动指定的实例。 |
|
ecluster kill {instance_name} | 释放指定的实例。 |
|
ecluster mount {instance_name} | 为指定的实例挂载NAS文件系统到/ncluster目录。 | ecluster mount task0.ncluster-v100 |
ecluster scp {source} {destination} | 安全拷贝文件或目录。 | ecluster scp /local/path/to/upload task0.ncluster-v100:/remote/path/to/save |
ecluster addip {instance_name} | 将指定任务中实例的固定公网IP添加到安全组。 | ecluster addip task0.ncluster-v100 |
ecluster rename {old_name} {new_name} | 重命名指定实例。 | ecluster rename task0.ncluster-v100 task1.ncluster-v100 |
基于配置文件创建实例时,您可以参考以下内容新建配置文件。
; config.ini
[ncluster]
; The job name for current creation job.
name=ncluster-v100
; The number of machine you want to create
machines=1
; The system disk size for instances in GB
system_disk_size=300
; The data disk size for instances in GB
data_disk_size=0
; The system image name you want to installed in the instances.
image_name=ubuntu_18_04_64_20G_alibase_20190624.vhd
; The instance type you want to create at Alibaba Cloud.
instance_type=ecs.gn6v-c10g1.20xlarge
; The spot instance option; If you want to buy spot instance, please set it to True.
spot=False
; If only used to create instances, it can set to True.
confirm_cost=False
; Confirm the next operation will cost money, if set to True will default confirmed.
skip_setup=True
; Nas create/mount options; Set True will disable nas mount for current job.
disable_nas=True
; The zone id info. The option provided to use resource in the zone.
zone_id=cn-hangzhou-i
; Specify the vpc name
vpc_name=ncluster-vpc
[cmd]
install_script=pwd