1. 安装 cuda
大多数新发布的大语言模型使用了较新的 PyTorch v2.0+ 版本,Pytorch 官方认为 CUDA 最低版本是 11.8 以及匹配的 GPU 驱动版本。详情见Pytorch官方 如下图:
1.1 下载 cuda
cuda 12.1 官方网站:
下载:
$wget https://developer.download.nvidia.com/compute/cuda/12.1.1/local_installers/cuda_12.1.1_530.30.02_linux.run
1.2 安装 cuda
$sudo sh cuda_12.1.1_530.30.02_linux.run
然后,接受协议
由于已经安装显卡驱动,选择不安装,然后光标到 install 处,点击回车
同意覆盖原有的 /usr/local/cuda
查看cuda:
$ ll /usr/local/cuda
lrwxrwxrwx 1 root root 21 Mar 6 17:10 /usr/local/cuda -> /usr/local/cuda-12.1/
如果不是这样的话,重新链接
$sudo ln -s /usr/local/cuda-12.1 /usr/local/cuda
同时修改 ~/.bashrc
$ vim ~/.bashrc
$ source ~/.bashrc
然后查看 cuda 是否安装成功:
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Mon_Apr__3_17:16:06_PDT_2023
Cuda compilation tools, release 12.1, V12.1.105
Build cuda_12.1.r12.1/compiler.32688072_0
$ stat /usr/local/cuda
File: /usr/local/cuda -> /usr/local/cuda-12.1/
Size: 21 Blocks: 0 IO Block: 4096 symbolic link
Device: 10303h/66307d Inode: 20972187 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-03-06 17:14:48.054414724 +0800
Modify: 2024-03-06 17:10:45.351626652 +0800
Change: 2024-03-06 17:10:45.351626652 +0800
Birth: -
2. 安装 cudnn
2.1 下载 cudnn
cudnn 官网,登录后可以直接点击下载
2.2 安装 cudnn
$ cd ~/Downloads/ & ls
$ tar -xvf cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz
$ cd cudnn-linux-x86_64-8.9.7.29_cuda12-archive
$ sudo cp include/cudnn.h /usr/local/cuda-12.1/include/
$ sudo cp lib/libcudnn* /usr/local/cuda-12.1/lib64/
$ sudo chmod a+r /usr/local/cuda-12.1/include/cudnn.h /usr/local/cuda-12.1/lib64/libcudnn*
3. 安装 TensorFlow
$ pip install tensorflow -i https://mirror.baidu.com/pypi/simple
4. 安装 Pytorch
参考 Pytorch 官网
$ pip3 install torch torchvision torchaudio
5. 安装 transformers
$ conda install -c conda-forge transformers
检验 transformers
$ python
Python 3.11.8 | packaged by conda-forge | (main, Feb 16 2024, 20:53:32) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import transformers
>>> print(transformers.__version__)
4.38.2