構建說明¶
注意:最新的構建說明包含在 FBGEMM 倉庫下 setup_env.bash 捆綁的一組指令碼中。
當前可用的 FBGEMM GenAI 構建變體有
CUDA
構建 FBGEMM GenAI 的一般步驟如下
設定獨立的構建環境。
設定用於 CUDA 構建的工具鏈。
安裝 PyTorch。
執行構建指令碼。
設定獨立的構建環境¶
按照說明設定 Conda 環境
其他預構建設定¶
由於 FBGEMM GenAI 利用與 FBGEMM_GPU 相同的構建過程,請參閱 準備構建 以獲取更多預構建設定資訊。
準備構建¶
克隆倉庫及其子模組,並安裝 requirements_genai.txt
# !! Run inside the Conda environment !!
# Select a version tag
FBGEMM_VERSION=v1.2.0
# Clone the repo along with its submodules
git clone --recursive -b ${FBGEMM_VERSION} https://github.com/pytorch/FBGEMM.git fbgemm_${FBGEMM_VERSION}
# Install additional required packages for building and testing
cd fbgemm_${FBGEMM_VERSION}/fbgemm_gpu
pip install -r requirements_genai.txt
設定 Wheel 構建變數¶
構建 Python wheel 時,必須首先正確設定包名、Python 版本標籤和 Python 平臺名稱
# Set the package name depending on the build variant
export package_name=fbgemm_genai_{cuda}
# Set the Python version tag. It should follow the convention `py<major><minor>`,
# e.g. Python 3.13 --> py313
export python_tag=py313
# Determine the processor architecture
export ARCH=$(uname -m)
# Set the Python platform name for the Linux case
export python_plat_name="manylinux_2_28_${ARCH}"
# For the macOS (x86_64) case
export python_plat_name="macosx_10_9_${ARCH}"
# For the macOS (arm64) case
export python_plat_name="macosx_11_0_${ARCH}"
# For the Windows case
export python_plat_name="win_${ARCH}"
CUDA 構建¶
為 CUDA 構建 FBGEMM GenAI 需要安裝 NVML 和 cuDNN,並透過環境變數使其可用於構建。但是,構建包不需要存在 CUDA 裝置。
與僅支援 CPU 的構建類似,透過將 --cxxprefix=$CONDA_PREFIX 附加到構建命令,可以啟用使用 Clang + libstdc++ 進行構建,前提是工具鏈已正確安裝。
# !! Run in fbgemm_gpu/ directory inside the Conda environment !!
# [OPTIONAL] Specify the CUDA installation paths
# This may be required if CMake is unable to find nvcc
export CUDACXX=/path/to/nvcc
export CUDA_BIN_PATH=/path/to/cuda/installation
# [OPTIONAL] Provide the CUB installation directory (applicable only to CUDA versions prior to 11.1)
export CUB_DIR=/path/to/cub
# [OPTIONAL] Allow NVCC to use host compilers that are newer than what NVCC officially supports
nvcc_prepend_flags=(
-allow-unsupported-compiler
)
# [OPTIONAL] If clang is the host compiler, set NVCC to use libstdc++ since libc++ is not supported
nvcc_prepend_flags+=(
-Xcompiler -stdlib=libstdc++
-ccbin "/path/to/clang++"
)
# [OPTIONAL] Set NVCC_PREPEND_FLAGS as needed
export NVCC_PREPEND_FLAGS="${nvcc_prepend_flags[@]}"
# [OPTIONAL] Enable verbose NVCC logs
export NVCC_VERBOSE=1
# Specify cuDNN header and library paths
export CUDNN_INCLUDE_DIR=/path/to/cudnn/include
export CUDNN_LIBRARY=/path/to/cudnn/lib
# Specify NVML filepath
export NVML_LIB_PATH=/path/to/libnvidia-ml.so
# Specify NCCL filepath
export NCCL_LIB_PATH=/path/to/libnccl.so.2
# Build for SM70/80 (V100/A100 GPU); update as needed
# If not specified, only the CUDA architecture supported by current system will be targeted
# If not specified and no CUDA device is present either, all CUDA architectures will be targeted
cuda_arch_list=7.0;8.0
# Unset TORCH_CUDA_ARCH_LIST if it exists, bc it takes precedence over
# -DTORCH_CUDA_ARCH_LIST during the invocation of setup.py
unset TORCH_CUDA_ARCH_LIST
# Build the wheel artifact only
python setup.py bdist_wheel \
--package_variant=genai \
--python-tag="${python_tag}" \
--plat-name="${python_plat_name}" \
--nvml_lib_path=${NVML_LIB_PATH} \
--nccl_lib_path=${NCCL_LIB_PATH} \
-DTORCH_CUDA_ARCH_LIST="${cuda_arch_list}"
# Build and install the library into the Conda environment
python setup.py install \
--package_variant=genai \
--nvml_lib_path=${NVML_LIB_PATH} \
--nccl_lib_path=${NCCL_LIB_PATH} \
-DTORCH_CUDA_ARCH_LIST="${cuda_arch_list}"
構建後檢查(面向開發者)¶
由於 FBGEMM GenAI 利用與 FBGEMM_GPU 相同的構建過程,請參閱 構建後檢查(面向開發者) 以獲取有關額外構建後檢查的資訊。