当前位置:   article > 正文

[Paddle] 从零安装 Paddle 框架

[Paddle] 从零安装 Paddle 框架

1 安装前准备

1.1 安装环境

本机安装环境如下:

运行环境
操作系统Ubuntu 22.04.4 LTS (Jammy Jellyfish)
CPUIntel® Core™ i5-12400
显卡NVIDIA GeForce RTX 4090

1.2 验证 GPU 是否为 NVIDIA GPU

命令行输入以下代码,以验证您的 GPU 是否是 NVIDIA GPU

lspci | grep -i nvidia
  • 1

2 安装 NVIDIA 相关的依赖

2.1 查找支持的驱动

在命令行输入以下代码,查找本机支持的 NVIDIA 显卡驱动版本:

ubuntu-drivers devices
  • 1

这将列出系统支持的所有 NVIDIA 驱动程序,选择最新版本的驱动程序进行安装:

== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00002684sv00001458sd000040E4bc03sc00i00
vendor   : NVIDIA Corporation
manual_install: True
driver   : nvidia-driver-535-server - distro non-free
driver   : nvidia-driver-535 - distro non-free recommended
driver   : nvidia-driver-545 - distro non-free
driver   : nvidia-driver-535-server-open - distro non-free
driver   : nvidia-driver-545-open - distro non-free
driver   : nvidia-driver-535-open - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2.2 查找可安装的驱动

在命令行输入以下代码,查找本机可安装的 NVIDIA 显卡驱动:

sudo apt search nvidia-driver | grep nvidia-driver
  • 1

这将列出当前源下所有可下载的 NVIDIA 驱动程序,例如本机可下载NVIDIA显卡驱动如下:

  Transitional package for nvidia-driver-390
  Transitional package for nvidia-driver-390
nvidia-driver-390/jammy-security,jammy-updates 390.157-0ubuntu0.22.04.2 amd64
nvidia-driver-418/jammy 430.50-0ubuntu3 amd64
  Transitional package for nvidia-driver-430
nvidia-driver-418-server/jammy-security,jammy-updates 418.226.00-0ubuntu5~0.22.04.1 amd64
nvidia-driver-430/jammy 440.100-0ubuntu1 amd64
  Transitional package for nvidia-driver-440
nvidia-driver-435/jammy 455.45.01-0ubuntu1 amd64
  Transitional package for nvidia-driver-455
nvidia-driver-440/jammy 450.119.03-0ubuntu1 amd64
  Transitional package for nvidia-driver-450
nvidia-driver-440-server/jammy-security,jammy-updates 450.248.02-0ubuntu0.22.04.1 amd64
  Transitional package for nvidia-driver-450-server
nvidia-driver-450/jammy 460.91.03-0ubuntu1 amd64
  Transitional package for nvidia-driver-460
nvidia-driver-450-server/jammy-security,jammy-updates 450.248.02-0ubuntu0.22.04.1 amd64
nvidia-driver-455/jammy 460.91.03-0ubuntu1 amd64
  Transitional package for nvidia-driver-460
nvidia-driver-460/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
  Transitional package for nvidia-driver-470
nvidia-driver-460-server/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
  Transitional package for nvidia-driver-470-server
nvidia-driver-465/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
  Transitional package for nvidia-driver-470
nvidia-driver-470/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
nvidia-driver-470-server/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
nvidia-driver-495/jammy-security,jammy-updates 510.108.03-0ubuntu0.22.04.1 amd64
  Transitional package for nvidia-driver-510
nvidia-driver-510/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
  Transitional package for nvidia-driver-535
nvidia-driver-510-server/jammy-security,jammy-updates 515.105.01-0ubuntu0.22.04.1 amd64
  Transitional package for nvidia-driver-515-server
nvidia-driver-515/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
  Transitional package for nvidia-driver-535
nvidia-driver-515-open/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
  Transitional package for nvidia-driver-535
nvidia-driver-515-server/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
  Transitional package for nvidia-driver-535-server
nvidia-driver-520/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
  Transitional package for nvidia-driver-535
nvidia-driver-520-open/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
  Transitional package for nvidia-driver-535
nvidia-driver-525/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
nvidia-driver-525-open/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
nvidia-driver-525-server/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
nvidia-driver-530/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
  Transitional package for nvidia-driver-535
nvidia-driver-530-open/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
  Transitional package for nvidia-driver-535-open
nvidia-driver-535/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
nvidia-driver-535-open/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
nvidia-driver-535-server/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
nvidia-driver-535-server-open/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
nvidia-driver-545/jammy-updates 545.29.06-0ubuntu0.22.04.2 amd64
nvidia-driver-545-open/jammy-updates 545.29.06-0ubuntu0.22.04.2 amd64
nvidia-driver-550/jammy-security,jammy-updates,now 550.90.07-0ubuntu0.22.04.1 amd64 [installed]
nvidia-driver-550-open/jammy-security,jammy-updates 550.90.07-0ubuntu0.22.04.1 amd64
nvidia-driver-550-server/jammy-security,jammy-updates 550.90.07-0ubuntu0.22.04.1 amd64
nvidia-driver-550-server-open/jammy-security,jammy-updates 550.90.07-0ubuntu0.22.04.1 amd64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

2.3 安装 Nvidia 驱动

选择2.1和2.2中都有的驱动程序进行安装,参考以下命令,根据自己的显卡安装最新的显卡驱动及其对应的显卡工具包

# 下载并安装显卡工具包
sudo apt install nvidia-utils-545
# 下载并安装显卡驱动
sudo apt install nvidia-driver-545
# 重启电脑
sudo reboot
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2.4 安装内核头文件和开发包

确保已安装当前运行内核的头文件和开发包:

sudo apt-get install linux-headers-$(uname -r)
  • 1

2.5 安装 cuda 11.8

CUDA Toolkit Archive 下载 CUDA Toolkit 11.8.0 工具包。
cuda-toolkit-list.png
根据你的系统,选择并下载并安装适用于您的系统的 CUDA 工具包,例如我们的系统选择以下配置项。
cuda-toolkit-example.png
对于 Ubuntu 22.04 LTS x86_64 系统,执行以下步骤:

# 下载 cuda 工具包
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
# 安装 cuda 工具包
sudo sh cuda_11.8.0_520.61.05_linux.run
  • 1
  • 2
  • 3
  • 4

在安装过程中,按以下步骤操作:

  1. 选择 continue 并按 Enter 键。
  2. 输入 accept 并按 Enter 键。
  3. 使用 上下键空格键 选择需要安装的组件(通常只需选择 CUDA Toolkit 11.8),然后选择 install 并按 Enter 键。

2.6 配置环境变量

添加 CUDA 路径到环境变量:

sudo gedit ~/.bashrc
  • 1

在文件末尾添加以下行:

export PATH=$PATH:/usr/local/cuda-11.8/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64
  • 1
  • 2

保存并关闭文件,然后刷新环境变量:

source ~/.bashrc
  • 1

3 安装 Paddle 框架

3.1 安装 miniconda

前往 Miniconda 官方网站 下载最新的 Miniconda 版本。下载并安装 Miniconda:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
  • 1
  • 2
  • 安装过程中按以下步骤操作:
    1. Enter 键。
    2. 空格键 跳过安装协议。
    3. 输入 yes 并按 Enter 键继续安装。

完成安装后,初始化 conda:

~/miniconda3/bin/conda init bash
source ~/.bashrc
  • 1
  • 2

3.2 创建并初始化一个 python 环境

如果网络环境在国内建议配置 conda 源为中科大源:

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
  • 1
  • 2
  • 3

创建并激活一个新的 Python 环境:

conda create -n paddlepaddle python=3.10
conda activate paddlepaddle
  • 1
  • 2

3.3 使用 pip 安装 Paddle 框架

由于 Conda 镜像源可能导致 PaddlePaddle GPU 版本下载困难,建议使用 pip 安装:

python -m pip install paddlepaddle-gpu==3.0.0b1 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
  • 1

3.4 验证 Paddle 框架

安装完成后,验证 PaddlePaddle 是否安装成功:

python
  • 1

在 Python 交互环境中输入以下命令:

# 弹出 Python 窗口后继续执行以下命令
>>> import paddle
>>> paddle.utils.run_check()
>>> exit()
  • 1
  • 2
  • 3
  • 4

如果没有错误信息,则说明 PaddlePaddle 安装成功。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/946531
推荐阅读
相关标签
  

闽ICP备14008679号