Cross-compile FlashAttention-3 for a non-Hopper node
mainIf you are on a CPU-only node or a node without a Hopper GPU, you can build a transferable .whl file to be installed on an H100 node later.
Requirements for compatibility between build and runtime nodes:
- CUDA toolkit major version: Must be $\ge$ 12.3 (12.4+ recommended). The build node needs the toolkit; the H100 node only needs a compatible driver.
- PyTorch & Python versions: The build must use the same
torchwheel and Python minor version as the runtime environment. - glibc: Ensure build and runtime nodes share a compatible glibc version (ideally the same OS image).
Build process:
Set TORCH_CUDA_ARCH_LIST="9.0a" to target the Hopper architecture explicitly and adjust MAX_JOBS based on available RAM (approximately 32 GB is required).
Installation on the H100 node:
Once the wheel is generated, transfer it to the H100 node and install it using pip.
# On the build node
export TORCH_CUDA_ARCH_LIST="9.0a"
export MAX_JOBS=4
git clone https://github.com/Dao-AILab/flash-attention.git
cd flash-attention/hopper
pip wheel . --no-build-isolation -w /tmp/fa3-wheel/
# On the H100 node
pip install /tmp/fa3-wheel/flash_attn_3-*.whl
python -c "from flash_attn_interface import flash_attn_func; print('ok')"