Skip to content

feat(rocm): serve on AMD GPUs through the HIP toolchain - #137

Open
paralin wants to merge 1 commit into
FlashML-org:mainfrom
paralin:amd
Open

feat(rocm): serve on AMD GPUs through the HIP toolchain#137
paralin wants to merge 1 commit into
FlashML-org:mainfrom
paralin:amd

Conversation

@paralin

@paralin paralin commented Aug 24, 2026

Copy link
Copy Markdown

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:

  • norm.py and activation.py pass launch_pdl to triton only when it is true; the AMD launcher rejects the keyword outright.
  • 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 replaces PTX streaming-load/store inline asm with plain device loads and stores. The cache-policy hints are dropped; correctness is unchanged.

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant