在 Compute Engine VM 上執行 NCCL

本頁提供操作說明,說明如何使用 Debian 軟體套件 (.deb) 或 Red Hat Package Manager (.rpm) 安裝 NCCL/gIB。安裝完成後,您就能在 A3 Ultra、A4 和 A4X 虛擬機器執行個體 (VM) 上執行 NCCL 測試 (以下範例適用於 2 節點測試)。

如要在 A3 Mega 和 A3 High 上執行 NCCL 測試,請參閱建立啟用 GPUDirect 的 A3 Mega 或 A3 High 執行個體

如果您使用 Cluster Director、Cluster Toolkit 或 GKE 等排程器,則不需要按照本頁面的步驟操作。請改為參閱下列文章:

安裝 nccl-gib

視工作負載的執行位置而定,您可以在訪客 VM 或容器映像檔中安裝 NCCL/gIB。

nccl-gib 套件會與未修改的 NVidia NCCL 程式庫 (libnccl2.so) 和標頭一併提供。所有 NCCL/gIB 內容都會安裝到 /usr/local/gib 目錄。部分依附元件也會透過發行版本的存放區擷取。

Debian 12 以上版本/Ubuntu 20.04 以上版本 (.deb 封裝)

# If you're not using an image from Google, trust the Google Cloud signing key
curl http://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/cloud.google.gpg

# Add gpudirect-gib-apt repo
echo 'deb https://packages.cloud.google.com/apt gpudirect-gib-apt main' | sudo tee /etc/apt/sources.list.d/nccl-gib.list

sudo apt update
sudo apt install nccl-gib

RockyLinux/CentOS/RHEL 9 以上版本 (.rpm 套件)

# Add gpudirect-gib-rpm repo
sudo tee -a /etc/yum.repos.d/nccl-gib.repo << EOL
[gpudirect-gib-rpm]
name=NCCL/gIB
baseurl=https://packages.cloud.google.com/yum/repos/gpudirect-gib-rpm
enabled=1
repo_gpgcheck=0
gpgcheck=0

sudo dnf makecache
sudo dnf install nccl-gib

如果您使用標準 OS 映像檔,也必須安裝最新版 NVIDIA DOCA-OFED 驅動程式。如果您使用 Google 的 A* 最佳化映像檔 (例如 Container OSGuest Accelerator Ubuntu/RockyLinux OS 映像檔),則不需要安裝這個驅動程式。

為避免 VM 執行不同版本的 nccl-gib 套件,建議您在執行 NCCL 工作負載前更新 nccl-gib,或停用無人值守升級。

使用 NCCL/gIB

如要在工作負載中啟用 NCCL/gIB,請確認下列事項:

  • /usr/local/gib/scripts/set_nccl_env.sh 是在執行階段環境中取得,來源檔案包含 NCCL/gIB 的所有必要環境變數,Google 預計在日後的 NCCL/gIB 版本中更新這些變數。
  • /usr/local/gib/lib64 目錄位於 LD_LIBRARY_PATH 中。

如要確認 NCCL/gIB 已啟用,請檢查是否有下列 NCCL INFO 層級的記錄項目:

# A sample log entry from NCCL core
vm-0:606:642 [6] NCCL INFO Using network gIB

# A sample log entry from the gIB network plugin
vm-0:606:642 [6] NCCL INFO NET/gIB : Initializing gIB v1.0.5

執行 NCCL 測試

如要瞭解如何在排定的環境中執行 NCCL 測試,請參閱下列文章:

我們也會發布診斷容器映像檔,其中包含所有內容,網址為 http://us-docker.pkg.dev/gce-ai-infra/gpudirect-gib/nccl-plugin-gib-diagnostic:latest

如要在非排程環境中執行 NCCL 測試,請按照下列步驟操作:

  1. 安裝 cuda-12.8 (或更新版本) 和 openmpi
  2. 在 VM 之間設定非互動式 SSH 登入
  3. 建構啟用 MPI 的 nccl-tests。建構 nccl-tests 時,請設定 NCCL_HOME=/usr/local/gib

如要執行 NCCL/gIB 套件隨附的指令碼,請按照下列步驟操作:

# The script assumes binaries at /opt/nccl-tests/build/
$ /usr/local/gib/scripts/run_nccl_tests.sh -d /opt/nccl-tests/build/ -p 22 -t all_gather -m 0x0 -b 4K -e 16G a4-vm-1 a4-vm-2

兩個 A4 VM 的輸出範例:

NCCL version 2.25.1+cuda12.8
#
#                                                              out-of-place                       in-place
#       size         count      type   redop    root     time   algbw   busbw #wrong     time   algbw   busbw #wrong
#        (B)    (elements)                               (us)  (GB/s)  (GB/s)            (us)  (GB/s)  (GB/s)
        4096            64     float    none      -1    59.97    0.07    0.06      0    57.49    0.07    0.07      0
        8192           128     float    none      -1    58.17    0.14    0.13      0    58.36    0.14    0.13      0
       16384           256     float    none      -1    59.07    0.28    0.26      0    59.03    0.28    0.26      0
       32768           512     float    none      -1    60.93    0.54    0.50      0    60.79    0.54    0.51      0
       65536          1024     float    none      -1    61.93    1.06    0.99      0    62.17    1.05    0.99      0
      131072          2048     float    none      -1    64.62    2.03    1.90      0    64.48    2.03    1.91      0
      262144          4096     float    none      -1    66.50    3.94    3.70      0    67.05    3.91    3.67      0
      524288          8192     float    none      -1    69.37    7.56    7.09      0    67.83    7.73    7.25      0
     1048576         16384     float    none      -1    117.2    8.95    8.39      0    113.7    9.22    8.64      0
     2097152         32768     float    none      -1    118.8   17.65   16.55      0    118.1   17.75   16.64      0
     4194304         65536     float    none      -1    122.2   34.32   32.17      0    122.6   34.22   32.08      0
     8388608        131072     float    none      -1    132.2   63.44   59.48      0    130.7   64.20   60.18      0
    16777216        262144     float    none      -1    139.2  120.49  112.96      0    139.7  120.07  112.56      0
    33554432        524288     float    none      -1    152.0  220.81  207.01      0    152.1  220.59  206.81      0
    67108864       1048576     float    none      -1    227.6  294.87  276.44      0    225.9  297.08  278.51      0
   134217728       2097152     float    none      -1    431.7  310.87  291.44      0    438.0  306.41  287.26      0
   268435456       4194304     float    none      -1    728.6  368.44  345.41      0    735.9  364.79  341.99      0
   536870912       8388608     float    none      -1   1404.2  382.33  358.44      0   1418.4  378.51  354.85      0
  1073741824      16777216     float    none      -1   2795.8  384.06  360.05      0   2768.9  387.79  363.55      0
  2147483648      33554432     float    none      -1   5440.1  394.75  370.08      0   5418.7  396.31  371.54      0
  4294967296      67108864     float    none      -1    10754  399.40  374.43      0    10746  399.67  374.69      0
  8589934592     134217728     float    none      -1    21434  400.77  375.72      0    21421  401.01  375.95      0
 17179869184     268435456     float    none      -1    42679  402.53  377.38      0    42792  401.48  376.38      0

後續步驟