Skip to content

[Feature] Adding pip install Support for sgl-kernel for ROCm#1

Closed
RohitNagraj wants to merge 171 commits intohubertlu-tw:mainfrom
RohitNagraj:rocm-pip-install-dev
Closed

[Feature] Adding pip install Support for sgl-kernel for ROCm#1
RohitNagraj wants to merge 171 commits intohubertlu-tw:mainfrom
RohitNagraj:rocm-pip-install-dev

Conversation

@RohitNagraj
Copy link
Copy Markdown

@RohitNagraj RohitNagraj commented Sep 24, 2025

Motivation

To enable pip install sgl-kernel support for ROCm.

Test package is uploaded on Test PyPi here: sgl-kernel-rocm630 and sgl-kernel-rocm700.

Modifications

  1. Added sgl-kernel/CMakeLists_rocm.txt that would be used by CMake for building wheel for ROCm, similar to NVIDIA's CMakeLists.txt.
  2. Added sgl-kernel/build_rocm.sh similar to NVIDIA's sgl-kernel/build.sh that builds the ROCm wheel inside a docker image (used by Github Workflows).
  3. Added sgl-kernel/rename_wheels_rocm.sh similar to existing NVIDIA's sgl-kernel/rename_wheels.sh to rename wheels to the standard format.
  4. Added sgl-kernel/rocm_hipify.py that hipifies the sources using PyTorch's built in hipify module. This is required by CMake for build. Did not use hipify-clang inside CMakeLists_rocm.txt as it requires CUDA to be available.
  5. Modified scripts/ci/amd_ci_install_dependency.sh to use sgl-kernel-rocm<version> hosted on TestPyPi for CI.
  6. Updated .github/workflows/release-whl-kernel.yml to build and push ROCm 6.3 and ROCm 7.0 wheels to SGLang's index (https://docs.sglang.ai/whl/)
  7. Added ROCm support to scripts/ci/update_kernel_whl_index.py to update sgl-kernel wheel index.

Testing

Procedure

  1. Run the docker container using scripts/ci/amd_ci_start_container.sh (modifying the image name when required)
  2. Install dependencies with scripts/ci/amd_ci_install_dependency.sh (using sgl-kernel from TestPyPi as the changes show in this PR. )
  3. Run sgl-kernel unit tests from .github/workflows/pr-test-amd.yml using the command docker exec -w /sglang-checkout/sgl-kernel/tests ci_sglang python3 -m pytest test_moe_align.py test_moe_topk_softmax.py test_apply_token_bitmask_inplace.py test_activation.py test_kvcacheio.py speculative/test_eagle_utils.py
  4. Run a small E2E test test/srt/test_mla.py using the command docker exec -w /sglang-checkout/test/srt ci_sglang bash -c "SGLANG_AMD_CI=1 SGLANG_IS_IN_CI=1 SGLANG_USE_AITER=1 python3 run_suite.py --suite per-commit-amd --range-begin 46 --range-end 47". The Range picks only test_mla.py to run.

Checklist

  • Format your code according to the Format code with pre-commit.
  • Add code support to build ROCm wheels for sgl-kernel
  • Test pip install functionality inside docker for ROCm 6.3 and ROCm 7.0 on MI300x and MI350x.
  • Run e2e test using test_mla.py.
  • Add wheel release as part of the Github Workflow.
  • Test functionality on Python 3.10, 3.11, 3.12 and 3.13 with install from TestPyPi.
  • Update documentation according to Write documentations.

@RohitNagraj RohitNagraj changed the title Adding pip install support for ROCm with pre-built wheels [Feature] Adding pip install support for ROCm with pre-built wheels Sep 24, 2025
@RohitNagraj RohitNagraj changed the title [Feature] Adding pip install support for ROCm with pre-built wheels [Feature] Adding pip install support for ROCm Sep 24, 2025
Comment thread sgl-kernel/rocm_hipify.py
Comment thread sgl-kernel/build_rocm.sh Outdated
#!/bin/bash
set -ex

DOCKER_IMAGE=lmsysorg/sglang:v0.5.3rc0-rocm630-mi30x
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require regular updates. Any better way to handle it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Ideally we should have a sglang:rocm-latest tag on dockerhub. But since that wasn't available, I took inspiration from Dockerfile.rocm to hardcode the latest. Any suggestions to do it better?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this script for building docker images for CI test? If yes, please check how NVIDIA’s CI test sgl_kernel: https://github.com/sgl-project/sglang/blob/main/.github/workflows/pr-test.yml

Copy link
Copy Markdown
Author

@RohitNagraj RohitNagraj Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is for CI build. In NVIDIA's build.sh, they use PyTorch image as the base. However, for AMD, we need dependencies like AITER installed, ROCm/PyTorch would not work out of the box as a base-image. Let me change the base-image to PyTorch and install the dependencies within the build script. That way, we avoid hardcoding the image to a specific version.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look into how we run SGLang CI in the confluence page or the scripts in SGLang specifically these two scripts:

For just sgl-kernel tests, there is no aiter dependency. However, we need to find a way to handle it for

pip install --upgrade pip
pip install uv
uv pip install "sglang[all_hip]>=0.5.3rc0"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, the build_rocm.sh is not for CI but for release-whl-kernel.yml github workflow. For CI, the install happens in amd_ci_install_dependency.sh, and just changing a small part in it to use the wheel from pip is enough once the wheel is on pip. However, this build_rocm.sh script is for release-whl-kernel.yml, which needs a docker image to compile and build the wheel.

NVIDIA's equivalent is found in build.sh that is called in the release-whl-kernel.yml.

Turns out we can use rocm/pytorch as the base image for it. So I'll change the base-image to that.

For

pip install --upgrade pip
pip install uv
uv pip install "sglang[all_hip]>=0.5.3rc0"

once we have the sgl-kernel wheel on Pypi, it should be pretty simple.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current flow of how I think about this is:

  1. This PR (sets up scripts to build wheel)
  2. Setup a PyPi repo for official sgl-kernel-rocm
  3. Setup Github Workflow similar to release-whl-kernel.yml for ROCm.
  4. Update the CI scripts amd_ci_install_dependency.sh and sglang/python/pyproject.toml to use these wheels from PyPi with pip install.

@RohitNagraj RohitNagraj reopened this Sep 26, 2025
@RohitNagraj RohitNagraj force-pushed the rocm-pip-install-dev branch 2 times, most recently from 2553eaf to 3ec449a Compare September 26, 2025 18:12
@hubertlu-tw
Copy link
Copy Markdown
Owner

@RohitNagraj please mention sgl-kernel pip install in your PR's title.

@RohitNagraj RohitNagraj changed the title [Feature] Adding pip install support for ROCm [Feature] Adding sgl-kernel Wheel Build Support for ROCm Sep 26, 2025
@RohitNagraj RohitNagraj changed the title [Feature] Adding sgl-kernel Wheel Build Support for ROCm [Feature] Adding pip install Support for sgl-kernel for ROCm Sep 26, 2025
@RohitNagraj RohitNagraj changed the title [Feature] Adding pip install Support for sgl-kernel for ROCm [1/2] [Feature] Adding pip install Support for sgl-kernel for ROCm Sep 28, 2025
@RohitNagraj RohitNagraj changed the title [1/2] [Feature] Adding pip install Support for sgl-kernel for ROCm [Feature] Adding pip install Support for sgl-kernel for ROCm Oct 15, 2025
@RohitNagraj
Copy link
Copy Markdown
Author

Tagged torch versions to build kernel.

@akao-amd akao-amd force-pushed the rocm-pip-install-dev branch from 8fc198a to 3607d66 Compare December 19, 2025 07:14
cocoshe and others added 8 commits December 19, 2025 15:19
…loading on MI325 (sgl-project#13760)

Co-authored-by: Sabre Shao <sabre.shao@amd.com>
Co-authored-by: Yusheng (Ethan) Su <yushengsu.thu@gmail.com>
Co-authored-by: Hubert Lu <Hubert.Lu@amd.com>
Co-authored-by: xsun <sunxiao04@gmail.com>
Co-authored-by: Liangsheng Yin <lsyincs@gmail.com>
Co-authored-by: bingxche <Bingxu.Chen@amd.com>
Co-authored-by: Sai Enduri <saimanas.enduri@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.