Skip to content

[ROCm] gfx1201 (Navi 48) support - compilation guide and known issues #1955

@UFO0506

Description

@UFO0506

System Info

bitsandbytes ROCm 編譯

踩坑 1:pip 安裝的版本不支援 ROCm

直接 pip install bitsandbytes 安裝的版本沒有 ROCm backend,必須從源碼編譯。

踩坑 2:multi-backend-refactor 分支有 bug

multi-backend-refactor 分支編譯出的 .so 缺少 kOptimizer32bit1StateI12hip_bfloat16Li2E 符號,導致 undefined symbol 錯誤。必須用 main 分支。

踩坑 3:gfx1153 無效 target ID

ROCm 6.3 的 CMake 模組內建了一個無效的 target gfx1153,必須在 cmake 前設定環境變數覆蓋:

export AMDGPU_TARGETS="gfx1201"

正確的編譯步驟

cd ~
git clone https://github.com/bitsandbytes-foundation/bitsandbytes.git
cd bitsandbytes
 
export PATH=/opt/rocm/bin:/usr/local/bin:$PATH
export AMDGPU_TARGETS="gfx1201"
 
cmake -DCOMPUTE_BACKEND=hip \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_HIP_ARCHITECTURES="gfx1201" \
      -S . -B build
 
cmake --build build -j$(nproc)
pip3.11 install -e . --no-cache-dir
 
# 驗證
python3.11 -c "import bitsandbytes as bnb; print(bnb.__version__)"

踩坑 4:editable install 路徑問題

pip install -e . 之後,bitsandbytes.__path__ 可能指向上層目錄而非模組目錄,導致 import 失敗。

解決方法:手動加入 PYTHONPATH:

echo 'export PYTHONPATH=/root/bitsandbytes:$PYTHONPATH' >> ~/.bashrc

踩坑 5:BNB_BACKEND 環境變數

推論時需要明確告知 bitsandbytes 使用 ROCm backend:

import os
os.environ['BNB_BACKEND'] = 'rocm'

Reproduction

Environment

  • GPU: AMD Radeon AI PRO R9700 (Navi 48 / gfx1201 / 32GB VRAM)
  • Host: Proxmox VE 9.0.3 (LXC Container, Ubuntu 22.04)
  • ROCm: 6.3.0
  • Python: 3.11.15
  • PyTorch: 2.9.1+rocm6.3
  • bitsandbytes: 0.50.0.dev0 (compiled from source)

Problem

pip-installed bitsandbytes has no ROCm backend for gfx1201 (Navi 48).
Must compile from source. Several issues encountered during compilation.

Issue 1: gfx1153 invalid target ID

ROCm 6.3 CMake module includes gfx1153 which is an invalid target ID,
causing cmake to fail:
clang++: error: invalid target ID 'gfx1153'

Fix: Set environment variable before cmake:

export AMDGPU_TARGETS="gfx1201"

Issue 2: multi-backend-refactor branch missing symbol

Compiling from multi-backend-refactor branch produces a .so missing
kOptimizer32bit1StateI12hip_bfloat16Li2E symbol:
OSError: undefined symbol: _Z36__device_stub__kOptimizer32bit1StateI12hip_bfloat16Li2E...

Fix: Use main branch instead.

Working Compilation Steps for gfx1201

git clone https://github.com/bitsandbytes-foundation/bitsandbytes.git
cd bitsandbytes

export AMDGPU_TARGETS="gfx1201"
export PATH=/opt/rocm/bin:$PATH

cmake -DCOMPUTE_BACKEND=hip \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_HIP_ARCHITECTURES="gfx1201" \
      -S . -B build

cmake --build build -j$(nproc)
pip install -e .

Issue 3: editable install path problem

After pip install -e ., bitsandbytes.__path__ points to parent directory
instead of module directory, causing import to fail silently.

Fix:

export PYTHONPATH=/root/bitsandbytes:$PYTHONPATH

Issue 4: BNB_BACKEND not auto-detected

Even with ROCm available, must explicitly set:

import os
os.environ['BNB_BACKEND'] = 'rocm'

Verification

python3 -c "
import sys
sys.path.insert(0, '/root/bitsandbytes')
import bitsandbytes as bnb
print(bnb.__version__)
print(bnb.supported_torch_devices)
"
# Output: 0.50.0.dev0

Expected behavior

bitsandbytes should automatically detect ROCm backend and support gfx1201 (Navi 48)
without requiring manual compilation from source or manual PYTHONPATH configuration.

Ideally:

  1. pip install bitsandbytes should include ROCm support for gfx1201
  2. AMDGPU_TARGETS should be auto-detected during cmake
  3. BNB_BACKEND should be auto-detected when ROCm is available

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions