feat(rocm): serve on AMD GPUs through the HIP toolchain - #137
Open
paralin wants to merge 1 commit into
Open
Conversation
paralin
force-pushed
the
amd
branch
3 times, most recently
from
August 24, 2026 08:52
22b6aee to
7e1d742
Compare
FreeToken built and served only against CUDA: setup.py linked its host-side extensions against cudart, the kernel JIT compiled with nvcc-only flags, and several triton call sites passed NVIDIA-only launch options. On an AMD GPU the engine could not even finish booting. Build _pinned_tensor and _cpu_moe against HIP through a shim header that maps every CUDA runtime symbol they use onto its HIP equivalent. Teach the kernel JIT the same trick: drop --expt-relaxed-constexpr (hipcc rejects it; relaxed constexpr is already its default) and force-include a shim, packaged with the kernel csrc tree, that maps the CUDA launch-config surface onto hipLaunchKernelEx. PDL launch attributes have no equivalent on this runtime; every kernel served on AMD builds with use_pdl=false, so the shim drops attributes instead of setting them. Three smaller fixes complete the port: - norm.py and activation.py omit the triton launch_pdl keyword under HIP; the AMD launcher rejects it outright. NVIDIA keeps the upstream launch_pdl=pdl call for both true and false. - attention.py floors block_h at 16 under HIP because RDNA3 WMMA cannot select an instruction for tl.dot below M=16. Padded head lanes were already masked. - fast_index_copy.cuh guards its PTX streaming-load/store inline asm: CUDA keeps it verbatim; HIP has no equivalent asm, so those builds fall back to plain device loads and stores. The cache-policy hints are dropped on HIP only; correctness is unchanged. setup.py detects the backend from torch: ROCm builds of torch take the HIP branch, CUDA builds keep the original cudart link and nvcc toolchain check unchanged, and anything else fails with a clear error. Every other edit is gated on HIP detection at run time. ROCm installs should resolve torch from the ROCm wheel index first; the pinned PyPI triton conflicts with the ROCm-bundled one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FreeToken built and served only against CUDA: setup.py linked its host-side extensions against cudart, the kernel JIT compiled with nvcc-only flags, and several triton call sites passed NVIDIA-only launch options. On an AMD GPU the engine could not even finish booting.
Build _pinned_tensor and _cpu_moe against HIP through a shim header that maps every CUDA runtime symbol they use onto its HIP equivalent. Teach the JIT the same trick: drop --expt-relaxed-constexpr (hipcc rejects it; relaxed constexpr is already its default) and force- include a shim that maps the CUDA launch-config surface onto hipLaunchKernelEx. PDL launch attributes have no equivalent on this runtime; every kernel served on AMD builds with use_pdl=false, so the shim drops attributes instead of setting them.
Three smaller fixes complete the port:
Drop the explicit triton==3.6.0 pin so the ROCm-bundled AMD-backend triton survives installation; torch's own wheels already constrain their matching triton build. Every edit is gated on HIP detection at build or run time, so NVIDIA paths are unchanged.