4

NVIDIA 7th SkyHackathon(一)环境配置

 1 year ago
source link: https://alex-mcavoy.github.io/skyhackathon/bbb8d9ae.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

获取 NGC 秘钥

1)登录 NGC | NVIDIA GPU Cloud 官网,创建 NGC 用户并登录

2)在右上角用户名的下拉界面点击 setup

01-1.png

3)进入 setup 页后生成 NGC 秘钥并做好记录,该秘钥在模型训练过程以及推理过程都会使用到,且只有在创建时可看到秘钥内容,无法后续进行查询

01-2.png

下载相关资料

下载大赛网盘中相应的资料,资料目录结构说明如下:

01-3.png

配置 NVIDIA GPU 环境

x86 CPU + NVIDIA GPU + Ubuntu 18.04 以上

安装 NVIDIA 驱动

NVIDIA 驱动要求 460 以上版本,安装完成后需要重启,重启完后执行 nvidia-smi 检查驱动

root@Alex-McAvoy:~$ apt-get install software-properties-common
root@Alex-McAvoy:~$ add-apt-repository ppa:graphics-drivers/ppa
root@Alex-McAvoy:~$ apt-get install nvidia-driver-460
root@Alex-McAvoy:~$ reboot

安装 docker

关于 docker,详见:docker 手册,命令图解如下:

01-4.png

安装完毕后,使用 docker run hello-world 测试是否安装成功

root@Alex-McAvoy:~$ apt-get install -y ca-certificates curl gnupg lsb-release
root@Alex-McAvoy:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o
/usr/share/keyrings/docker-archive-keyring.gpg
root@Alex-McAvoy:~$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs)stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
root@Alex-McAvoy:~$ apt-get update
root@Alex-McAvoy:~$ apt-get install -y docker-ce docker-ce-cli containerd.io

当出现以下信息后,说明 docker 安装成功

01-5.png

安装 nvidia-docker2

安装完毕后,使用 docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi 测试是否安装成功

root@Alex-McAvoy:~$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | apt-key add -distribution=$(./etc/os-release;echo $ID$VERSION_ID)
root@Alex-McAvoy:~$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | tee /etc/apt/sources.list.d/nvidia-docker.list
root@Alex-McAvoy:~$ apt-get update && apt-get install -y nvidia-docker2
root@Alex-McAvoy:~$ systemctl restart docker

当出现以下信息后,说明 nvidia-docker2 安装成功

01-6.png

登录 NGC

root@Alex-McAvoy:~$ docker login -u '$oauthtoken' --password-stdin nvcr.io <<< '申请的密钥'

安装 MiniConda3

root@Alex-McAvoy:~$ export DL_SITE=https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda
root@Alex-McAvoy:~$ wget -c $DL_SITE/Miniconda3-py38_4.10.3-Linux-x86_64.sh
root@Alex-McAvoy:~$ bash Miniconda3-py38_4.10.3-Linux-x86_64.sh
root@Alex-McAvoy:~$ source ~/.bashrc

安装 Jupyterlab 开发环境

root@Alex-McAvoy:~$ pip install jupyter jupyterlab
root@Alex-McAvoy:~$ export PW='登录密码'
root@Alex-McAvoy:~$ python3 -c "from notebook.auth.security import set_password; set_password('$PW','$HOME/.jupyter/jupyter_notebook_config.json')"

安装 GPU 版本 Pytorch

使用 nvidia-smi 查看 GPU 详细信息,可以看到,已安装的 cuda 版本为 11.8,之后通过 pytorch 官网,根据 cuda 版本和操作系统版本等信息,选择对应版本的 pytorch

01-7.png
root@Alex-McAvoy:~$ pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1
--extra-index-url https://download.pytorch.org/whl/cu113

NeMo 开源工具包

关于 NeMo

NeMo(Neural Modules)是 NVIDIA 发布的基于 PyTorch 的开源工具包,它允许开发者快速构建、训练和微调会话式人工智能模型

NeMo 由 NeMo Core 和 NeMo Collection 组成,NeMo Core 为所有模型和模块提供了一个通用的外观,NeMo Collection 则是特定领域模块和模型的组合

NeMo Collection 主要分为三个模块:

  • Speech Collection(nemo_asr):用于 ASR 任务的模型,如语音识别、命令识别等
  • NLP Collection(nemo_nlp):用于 NLP 任务的模型,如问题回答、命名实体识别等
  • Speech Synthesis(nemo_tts):用于 TTS 任务的模块,如谱图生成器、声码器等

关于 TAO 的详细介绍,见:NVIDIA NeMo

NeMo 的应用栈如下图

01-8.png

安装 NeMo 语音工具包(NeMo Speech Collection)

root@Alex-McAvoy:~$ apt-get update && sudo apt-get install -y libsndfile1 ffmpeg
root@Alex-McAvoy:~$ pip install Cython
root@Alex-McAvoy:~$ pip install --user pytest-runner
root@Alex-McAvoy:~$ pip install rosa numpy==1.19.4
root@Alex-McAvoy:~$ pip install torchmetrics==0.6.0
root@Alex-McAvoy:~$ pip install nemo_toolkit[all]==1.4.0
root@Alex-McAvoy:~$ pip install ASR-metrics

NeMo 语音工具包检测

若没有报错表示安装成功(Warning 无需理会)

root@Alex-McAvoy:~$ python
>>> import nemo
>>> import nemo.collections.asr as nemo_asr

TAO 模型训练工具

关于 TAO

TAO(Train, Adapt and Optimize)是 NVIDIA 基于TensorFlow 和 PyTorch 构建的工具套件,其利用迁移学习从现有的神经网络模型中已学习到的特征提取到新的自定义模型中,通过利用自己的数据对预训练 NVIDIA 模型进行微调,并针对推理进行优化

关于 TAO 的详细介绍,见:NVIDIA TAO 工具套件

TAO 的应用栈如下图

01-9.png

安装运行 TAO 的 Virtualenv 虚拟环境

为确保 TAO 有独立的 Python 运行环境,需要安装 Virtualenv 虚拟环境

root@Alex-McAvoy:~$ pip install virtualenv virtualenvwrapper
root@Alex-McAvoy:~$ mkdir $HOME/.virtualenvs

之后,利用 vim 在 ~/.bashrc 中,添加如下行:

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=$HOME/miniconda3/bin/python3
source $HOME/miniconda3/bin/virtualenvwrapper.sh

保存退出后,执行 source ~/.bashrc 重新加载 bash 配置

最后,创建名为 tao 的虚拟环境

root@Alex-McAvoy:~$ mkvirtualenv tao -p $HOME/miniconda3/bin/python3

安装 TAO 模型训练工具

执行 workon tao 进入之前创建的名为 tao 的虚拟环境,然后在其中安装 TAO

(tao)root@Alex-McAvoy:~$ pip3 install nvidia-pyindex
(tao)root@Alex-McAvoy:~$ pip3 install nvidia-tao
(tao)root@Alex-McAvoy:~$ tao info

当出现以下信息后,说明安装成功

01-10.png

启动 Jupyter Lab

进入工作目录 7thSkyHackathon 后,执行下述命令启动 Jupyter 即可

(tao)root@Alex-McAvoy:~/7thSkyHackathon$ jupyter lab --ip 0.0.0.0 --port 8888 --allow-root

此时,在浏览器输入 URL,并输入密码后,即可进入到 Jupyter Lab 界面

01-11.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK