Skip to content

[Feature] Support environments built by TheRock build system - #172

Merged
diptorupd merged 19 commits into
AMD-Ecosystem:amd-integrationfrom
eppaneamd:feat/enable_therock
Feb 24, 2026
Merged

[Feature] Support environments built by TheRock build system#172
diptorupd merged 19 commits into
AMD-Ecosystem:amd-integrationfrom
eppaneamd:feat/enable_therock

Conversation

@eppaneamd

@eppaneamd eppaneamd commented Feb 20, 2026

Copy link
Copy Markdown

📌 Description

This PR introduces ROCm/HIP compatibility improvements:

  • Refactor hip_utils.py for supporting environments built by TheRock build system
  • Other minor fixes

OBS!

🧪 Tests

Currently failing tests:

=========================== short test summary info ============================
FAILED tests/test_logits_processor_hip.py::TestLogitsPipeCompilationHIP::test_probs_sample_freq[0.0-normal_distribution(std=1)-32000] - AssertionError: Compiled similarity: tensor([0.9719], device='cuda:0')
assert tensor([0.9719], device='cuda:0') > 0.99
FAILED tests/test_logits_processor_hip.py::TestLogitsPipeCompilationHIP::test_probs_sample_freq[0.0-normal_distribution(std=1)-128256] - AssertionError: Compiled similarity: tensor([0.9895], device='cuda:0')
assert tensor([0.9895], device='cuda:0') > 0.99
============ 2 failed, 589 passed, 12 skipped in 229.71s (0:03:49) =============

=========================== short test summary info ============================
FAILED tests/test_sampling_hip.py::test_sampling_freq[0.0-normal_distribution(std=1)-32000] - AssertionError: similarity: tensor([0.9725], device='cuda:0')
assert tensor([0.9725], device='cuda:0') > 0.99
FAILED tests/test_sampling_hip.py::test_sampling_freq[0.0-normal_distribution(std=1)-128256] - AssertionError: similarity: tensor([0.9894], device='cuda:0')
assert tensor([0.9894], device='cuda:0') > 0.99
============ 2 failed, 772 passed, 18 skipped in 283.44s (0:04:43) =============

Above similarity scores fall just below the 0.99 threshold (< 2% deviation).

Test environment:

OS: Ubuntu 22.04.5 LTS (x86_64)
GPU: AMD Instinct MI300X (gfx942:sramecc+:xnack-)
Python version: 3.11.10

rocm                            7.12.0a20260211
rocm-sdk-core                   7.12.0a20260211
rocm-sdk-libraries-gfx94X-dcgpu 7.12.0a20260211

HIP runtime version: 7.3.53390
ROCM used to build PyTorch: 7.3.53390

[pip3] numpy==2.3.1
[pip3] torch==2.10.0+rocm7.12.0a20260211
[pip3] torchao==0.16.0+git3c1065ca6
[pip3] torchaudio==2.10.0+rocm7.12.0a20260211
[pip3] torchcodec==0.10.0
[pip3] torchvision==0.25.0+rocm7.12.0a20260211
[pip3] triton==3.6.0+rocm7.12.0a20260211
[pip3] amd-aiter==0.1.10.post4.dev13+g439606621

Copilot AI review requested due to automatic review settings February 20, 2026 13:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves ROCm/HIP compatibility (including TheRock-built environments) by refactoring ROCm environment detection, making CUDA-specific imports conditional, and improving HIP compilation/header compatibility, while also adding a test-time GPU memory cleanup fixture.

Changes:

  • Refactor ROCm detection utilities to support TheRock layouts and centralize ROCM_HOME resolution.
  • Make CUDA-only imports in prefill.py conditional to avoid import-time failures on ROCm/CPU-only builds.
  • Update ROCm sampling extension to include the appropriate PyTorch generator header based on availability.
  • Add an autouse pytest fixture to opportunistically clear GPU memory between tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/conftest.py Adds an autouse GPU memory cleanup fixture and adjusts cache-clearing threshold logic.
flashinfer/prefill.py Gates CUDA-only imports behind torch.version.cuda to improve ROCm/CPU importability.
flashinfer/jit/cpp_ext_hip.py Switches ROCm home discovery to flashinfer.hip_utils.get_rocm_home() and simplifies ninja generation.
flashinfer/hip_utils.py Adds TheRock detection + multiple ROCm version detection methods; refactors compatibility matrix construction.
flashinfer/csrc_rocm/sampling.cu Selects HIP vs CUDA generator header using __has_include for better cross-torch compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/conftest.py Outdated
Comment thread tests/conftest.py Outdated
Comment thread flashinfer/prefill.py Outdated
Comment thread flashinfer/hip_utils.py
Comment thread flashinfer/hip_utils.py
Comment thread flashinfer/prefill.py
Comment thread flashinfer/hip_utils.py
Comment thread flashinfer/hip_utils.py
Comment thread tests/conftest.py
Comment thread flashinfer/csrc_rocm/sampling.cu
Copilot AI review requested due to automatic review settings February 23, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

tests/conftest.py:232

  • pytest_runtest_call is implemented as a generator (uses yield) but the hook decorator no longer sets wrapper=True. Without wrapper=True, pytest will not treat this as a hook wrapper and this will break test execution/exception handling. Set wrapper=True again (you can keep tryfirst=True if needed).
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_call(item):
    # skip OOM error and missing JIT cache errors
    try:
        yield
    except (torch.cuda.OutOfMemoryError, RuntimeError) as e:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/conftest.py Outdated
Copilot AI review requested due to automatic review settings February 23, 2026 21:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flashinfer/hip_utils.py
Copilot AI review requested due to automatic review settings February 24, 2026 17:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flashinfer/hip_utils.py
Comment thread flashinfer/hip_utils.py
Comment thread flashinfer/hip_utils.py Outdated
Comment thread flashinfer/hip_utils.py Outdated
Comment thread flashinfer/hip_utils.py Outdated
Copilot AI review requested due to automatic review settings February 24, 2026 20:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flashinfer/hip_utils.py
Comment on lines 16 to +18
import os
import re
import subprocess

# Method 1: Try /opt/rocm/.info/version (most reliable)
rocm_path = os.environ.get("ROCM_PATH", "/opt/rocm")
version_file = os.path.join(rocm_path, ".info", "version")
return os.environ.get("ROCM_PATH") or os.environ.get("ROCM_HOME") or "/opt/rocm"

Copilot AI Feb 24, 2026

Copy link

Choose a reason for hiding this comment

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

get_rocm_home() falls back to /opt/rocm without attempting any discovery when neither ROCM_PATH nor ROCM_HOME is set. This can break environments where ROCm is installed in a non-standard prefix (including TheRock wheel installs) unless users also set one of those env vars. Consider adding an additional fallback that derives the prefix from PYTORCH_AMDCLANG (if set) and/or from a hipcc/amdclang++ found on PATH, before defaulting to /opt/rocm.

Copilot uses AI. Check for mistakes.
Comment thread flashinfer/hip_utils.py
Comment on lines +169 to +174
return version
print(f"ROCm version not found using {method.__name__}. Trying next method...")

return None


Copilot AI Feb 24, 2026

Copy link

Choose a reason for hiding this comment

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

get_system_rocm_version() prints a message for every failed detection method attempt. This function is part of core validation and may run in library contexts where stdout noise is undesirable (e.g., tests, JIT compilation). Please route this through the project's logger at DEBUG level or gate it behind an explicit verbose/env flag instead of unconditional print().

Copilot uses AI. Check for mistakes.

@diptorupd diptorupd left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you @eppaneamd !

@diptorupd
diptorupd merged commit ff0328e into AMD-Ecosystem:amd-integration Feb 24, 2026
1 of 2 checks passed
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.

3 participants