fix(ROCm): remove fix_rocm_triton_key_error — based on a false premise (#4125)

The function (introduced in #3923) assumed that the absence of
`triton.runtime.triton_key` on ROCm means torch.compile will crash.
Investigation shows this is incorrect:

1. `triton.runtime.triton_key` was renamed/removed in the ROCm Triton
   fork — it does not exist at that path.  However,
   `triton.compiler.compiler.triton_key` (the path torch._inductor
   actually imports) EXISTS and works correctly on ROCm.

2. Both call-sites in torch._inductor (codecache.py and
   async_compile.py) already wrap the import in try/except, so even a
   genuinely missing triton_key would be handled gracefully.

3. Comprehensive testing on ROCm 7.1 + Triton 3.4.0 + gfx1100 confirms
   torch.compile works correctly for matmul, cross-entropy, RMSNorm,
   multi-layer transformer forward+backward, and LoRA — all without
   triton.runtime.triton_key.

The original code was also ineffective (environment variables set after
torch import have no effect on torch._dynamo config), so removing it
has zero behavioral change on existing installations.

Supersedes the compile-disable portion of #3923.
This commit is contained in:
金黄色葡萄球君君 2026-03-01 15:59:12 +08:00 committed by GitHub
commit cd37a10a2a
2 changed files with 0 additions and 36 deletions

View file

@ -139,7 +139,6 @@ from .import_fixes import (
fix_vllm_guided_decoding_params,
fix_vllm_pdl_blackwell,
fix_triton_compiled_kernel_missing_attrs,
fix_rocm_triton_key_error,
patch_trunc_normal_precision_issue,
ignore_logger_messages,
patch_ipykernel_hf_xet,
@ -161,7 +160,6 @@ check_vllm_torch_sm100_compatibility()
fix_vllm_guided_decoding_params()
fix_vllm_pdl_blackwell()
fix_triton_compiled_kernel_missing_attrs()
fix_rocm_triton_key_error()
patch_trunc_normal_precision_issue()
ignore_logger_messages()
patch_ipykernel_hf_xet()
@ -181,7 +179,6 @@ del check_vllm_torch_sm100_compatibility
del fix_vllm_guided_decoding_params
del fix_vllm_pdl_blackwell
del fix_triton_compiled_kernel_missing_attrs
del fix_rocm_triton_key_error
del patch_trunc_normal_precision_issue
del ignore_logger_messages
del patch_ipykernel_hf_xet

View file

@ -941,39 +941,6 @@ def fix_triton_compiled_kernel_missing_attrs():
)
def fix_rocm_triton_key_error():
"""
ROCm + torch.compile can fail if Triton lacks `triton_key`.
Disable Inductor/compile only on ROCm when that symbol is missing.
"""
try:
import torch
except (ImportError, ModuleNotFoundError):
return
if not getattr(torch.version, "hip", None):
return
try:
import triton
except (ImportError, ModuleNotFoundError):
return
try:
from triton.runtime import triton_key # noqa: F401
return
except ImportError:
pass
os.environ.setdefault("TORCHINDUCTOR_DISABLE", "1")
os.environ.setdefault("TORCH_COMPILE_DISABLE", "1")
logger.info(
"Unsloth: ROCm detected and Triton lacks triton_key; "
"disabling torch.compile/Inductor to avoid backend crash."
)
def patch_trunc_normal_precision_issue():
"""
Patch torch.nn.init.trunc_normal_ for low precision tensors to run init in fp32.