Repository navigation
Introduce AMD GPU support with ROCm HIP - #1989
Conversation
The distribution part is tricky for rocm. My recommendation from minimum to best:
I will start with 1 and 2. |
|
Added docker and windows whls (artifacts). I give up fixing linux whl, it's dependency hell between cibw/rocm. Edited see new instructions below |
|
I lied, I think I figured out linux whls, will add soon |
|
Ok actually done now. Currently building for rocm 7.2 Linux: Windows: |
|
Hello @sssshhhhhh! For the next release I plan to publish the roc wheel as part of the release: https://github.com/jordimas/CTranslate2/releases And also the docker images: https://github.com/jordimas/CTranslate2/pkgs/container/ctranslate2 These will be published in https://github.com/OpenNMT/CTranslate2, these tests are in my fork just to test the process. Let me know if these wheels and Docker work |
|
All works but linux needs some env variables set, new commits should remove that |
|
Thanks, @sssshhhhhh This is an outstanding work! Thanks |
|
Thanks @sssshhhhhh and @jordimas for getting this merged. Confirming the v4.7.1 release wheel works out of the box on AMD Strix Halo (Ryzen AI Max+ 395, gfx1151) with ROCm 7.2.2. Setup: Ubuntu 26.04 LTS + ROCm 7.2.2 from AMD's official noble-pocket apt repo + the Result on faster-whisper-large-v3 (float16):
The wheel's Full recipe with scripts and benchmarks: https://github.com/nabe2030/faster-whisper-rocm-strix-halo |
Dockerfile.gpu says CTranslate2 cannot use ROCm, but PR #1989 added HIP support and official ROCm wheels (OpenNMT/CTranslate2#1989). Use those wheels to add an AMD image based on AMD's matching PyTorch and ONNX Runtime stack, and pin its GPU packages so pip does not replace them with CPU builds. Rename the existing image to Dockerfile.CUDA so each vendor has a clear entry point. Present rocm and rocm:N to users even though ROCm does not have a consistent name inside the libraries. PyTorch and CTranslate2 expose HIP devices through their existing "cuda" APIs, so translate those values to cuda for both backends. ONNX Runtime uses MIGraphX instead. Keep sherpa-onnx on CPU because its proposed ROCm provider is still unmerged. Document that limitation, the supported CTranslate2 GPU architectures, and the local build and run commands in the README.
CTranslate2 gained ROCm/HIP support (OpenNMT/CTranslate2#1989) with official wheels, so add an AMD image, Dockerfile.ROCm, based on AMD's matched PyTorch/ONNX Runtime stack on Ubuntu 24.04 / Python 3.12. Its GPU packages are pinned so pip does not replace them with CPU builds. Rename Dockerfile.gpu to Dockerfile.CUDA so each vendor has a clear entry point. Expose "rocm" and "rocm:N" to users. PyTorch and CTranslate2 see ROCm through their "cuda" APIs, so translate those to cuda; ONNX Runtime uses MIGraphX instead. sherpa-onnx stays on the CPU while its ROCm provider is unmerged upstream.
Closes #1072
Thanks to the work of everyone at arlo-phoenix/CTranslate2-rocm and the linked issue.
Windows can be compiled with this script: https://github.com/sssshhhhhh/CTranslate2/blob/745f0b46aea94acef514185ed5facbb3fecd6dcd/python/tools/prepare_build_environment_windows.ps1
Linux can follow instructions at: https://github.com/arlo-phoenix/CTranslate2-rocm/blob/rocm/README_ROCM.md
Currently targeting rocm 7.1.1. Passes all tests and successfully outputs for whisper and gemma3. For now, just enough changes to build for amd, specific optimisations like flash attention for the future.
Some questions:
Should having prebuilt whls be a goal or would letting people build themselves be fine?
How should packaging be handled? My windows whls currently need the separate install of rocm_sdk_libraries_custom and include amdhip64_7.dll/amd_comgr0701.dll. Whls are 58MB each, removing the 2 dlls drops it to 12MB.
What should be targeted? Currently I'm doing rocm 7 supported rdna, cdna should work but wave size isn't optimal (nvidia/rdna uses 32). Also unsure about rdna2, this pr should work but its support seems bad and I don't have any to test.