从头开始配置一台NVIDIA GPU大模型训练推理服务器

从头开始配置一台NVIDIA GPU大模型训练推理服务器

服务器信息

操作系统:Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-100-generic x86_64)

GPU:8×A100 40G

1. 配置DNS

设置DNS,方便后续下载各种软件包

vim /etc/resolv.conf

写入以下信息

nameserver 8.8.8.8
nameserver 8.8.4.4

2. 安装显卡驱动

2.1 安装基础依赖

sudo apt-get update 
sudo apt-get install -y g++ gcc make

2.2 安装驱动

下载 NVIDIA 官方驱动 | NVIDIA

找到适合自己显卡的驱动,确定好驱动版本,下载驱动安装包,并上传到服务器

我这边的显卡驱动信息:

Data Center Driver for Linux x64 570.133.20 | Linux 64-bit
驱动版本:	570.133.20
发布日期:	Thu Apr 17, 2025
操作系统:	Linux 64-bit
CUDA 工具包:	12.8
语言:	Chinese (Simplified)
文件大小:	375.65 MB

给驱动安装包加执行权限,然后开始安装驱动:

chmod +x NVIDIA-Linux-x86_64-570.133.20.run
./NVIDIA-Linux-x86_64-570.133.20.run

安装驱动后可以通过nvidia-smi命令查看:

+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.133.20             Driver Version: 570.133.20     CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA A100-SXM4-40GB          Off |   00000000:0E:00.0 Off |                    0 |
| N/A   32C    P0             63W /  400W |   36925MiB /  40960MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   1  NVIDIA A100-SXM4-40GB          Off |   00000000:0F:00.0 Off |                    0 |
| N/A   31C    P0             65W /  400W |   36795MiB /  40960MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   2  NVIDIA A100-SXM4-40GB          Off |   00000000:1F:00.0 Off |                    0 |
| N/A   32C    P0             62W /  400W |   36795MiB /  40960MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   3  NVIDIA A100-SXM4-40GB          Off |   00000000:20:00.0 Off |                    0 |
| N/A   30C    P0             59W /  400W |   36507MiB /  40960MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   4  NVIDIA A100-SXM4-40GB          Off |   00000000:B5:00.0 Off |                    0 |
| N/A   29C    P0             55W /  400W |       0MiB /  40960MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   5  NVIDIA A100-SXM4-40GB          Off |   00000000:B6:00.0 Off |                    0 |
| N/A   30C    P0             53W /  400W |       0MiB /  40960MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   6  NVIDIA A100-SXM4-40GB          Off |   00000000:CE:00.0 Off |                    0 |
| N/A   31C    P0             62W /  400W |   36123MiB /  40960MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+
|   7  NVIDIA A100-SXM4-40GB          Off |   00000000:CF:00.0 Off |                    0 |
| N/A   31C    P0             59W /  400W |   36099MiB /  40960MiB |      0%      Default |
|                                         |                        |             Disabled |
+-----------------------------------------+------------------------+----------------------+

2.3 安装CUDA-Toolkit

注意:CUDA-Toolkit的版本需要小于等于驱动版本

这里选择安装CUDA Toolkit 12.2 (<驱动版本12.8)

CUDA Toolkit 12.2 Downloads | NVIDIA Developer

wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run
sudo sh cuda_12.2.0_535.54.03_linux.run

在安装时取消driver项 (选中driver,按回车,将叉号消除)

配置环境变量:

sudo vim ~/.bashrc

写入(注意根据自己的驱动版本对路径进行替换):

export PATH=/usr/local/cuda-12.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

刷新环境变量:

source ~/.bashrc

检查CUDA Toolkit是否安装成功:

nvcc -V

# 输出
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Jun_13_19:16:58_PDT_2023
Cuda compilation tools, release 12.2, V12.2.91
Build cuda_12.2.r12.2/compiler.32965470_0

2.4 安装cudann

https://developer.nvidia.com/cudnn

选择适合自己系统版本的安装包,依次执行以下命令:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cudnn
sudo apt-get -y install cudnn-cuda-12

如果你的驱动是cuda-11.x,最后一行命令替换为sudo apt-get -y install cudnn-cuda-11

2.5 安装fabricmanager

Index of /compute/cuda/repos/ubuntu2004/x86_64

去上面的网址找到符合自己环境的安装包,要求:fabricmanager版本与驱动版本需要完全一致,精确到最版本号的每一位。

我这里的驱动版本是570.133.20,所以就必须下载cuda-drivers-fabricmanager-570_570.133.20-1_amd64.deb

如果你找不到自己驱动版本对应的fabricmanager,比如你的驱动版本是570.133.16(该版本找不到对应的fabricmanager),请重新回到步骤2.2安装官方驱动。

依次执行以下命令:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-drivers-fabricmanager-570_570.133.20-1_amd64.deb
sudo dpkg -i xxx
sudo systemctl daemon-reload 
sudo systemctl enable --now nvidia-fabricmanager
sudo dpkg --list | grep nvidia-fabricmanager
sudo systemctl list-unit-files | grep nvidia-fabricmanager
sudo apt-mark hold nvidia-fabricmanager-570

3. 安装Miniconda

# 下载安装包
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# 安装
bash Miniconda3-latest-Linux-x86_64.sh
# 激活miniconda
source ~/miniconda3/bin/activate
# 设置pip源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

4. 安装SWIFT

SWIFT用于大模型训练和推理。

conda create --name swift python=3.10
conda activate swift
git clone https://github.com/modelscope/ms-swift.git
cd ms-swift
pip install -e .

5. 安装vLLM

vLLM用于加速大模型推理。

pip install vllm==0.8.5

6. 安装FlashAttention2

FlashAttention2用于加速大模型训练和推理。

安装系统构建包ninja:

pip install ninja

Releases · Dao-AILab/flash-attention · GitHub

在上面的网址中找到适合自己的whl安装包(一定要找正确,不然会安装失败)。

我的环境对应的包是:

flash_attn-2.7.4.post1+cu12torch2.3cxx11abiFALSE-cp310-cp310-linux_x86_64.whl

包名的含义:

  • 2.7.2.post1:包的版本号。
  • cu12:表示该包是针对CUDA 12构建的。
  • torch2.3:表示该包是针对PyTorch 2.3构建的(如果你的PyTorch > 2.3一般也是可以的)。
  • cxx11abiFALSE:表示该包在构建时不启用 C++11 ABI(Application Binary Interface)。如果安装包后不识别,就要选为False的版本。
  • cp310:表示该包是为 Python 3.10 构建的。
  • linux_x86_64:表示该包是为 Linux 操作系统和 x86_64 架构(即 64 位 Intel/AMD 处理器)构建的。
  • .whl:文件扩展名,表示这是一个 Python Wheel 文件。Wheel 是 Python 的一种二进制分发格式,用于快速安装包。

下载完成后,直接使用pip安装:

pip install flash_attn-2.7.4.post1+cu12torch2.3cxx11abiFALSE-cp310-cp310-linux_x86_64.whl --no-build-isolation

至此,可以开始愉快地训练和推理大模型了!

posted @ 2025-05-23 17:00  一蓑烟雨度平生  阅读(491)  评论(0)    收藏  举报