[ROCm][CI] Fix ROCm LoRA Transformers fallback with full CUDA graphs (#41577)

Signed-off-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
Andreas Karatzas
2026-05-23 04:31:32 +00:00
committed by GitHub
parent 84e351555a
commit d28bdf9344
4 changed files with 88 additions and 19 deletions
+34 -6
View File
@@ -10,10 +10,11 @@ current_platform.import_kernels()
CUDA_ALIKE = current_platform.is_cuda_alike()
"""Most kernels in this file are supported on all CUDA-alike platforms."""
IS_ROCM = current_platform.is_rocm()
"""ROCm needs shape normalization before calling some vLLM C kernels."""
rms_no_var_size = (
lambda x, weight, epsilon, variance_size=None: variance_size is None
and (weight is None or weight.dtype == x.dtype)
rms_no_var_size = lambda x, weight, epsilon, variance_size=None: (
variance_size is None and (weight is None or weight.dtype == x.dtype)
)
"""vLLM kernel requires no variance_size override and matching input/weight dtype."""
@@ -28,14 +29,23 @@ def rms_norm(
# Kernel requires weight tensor, pass ones
weight = torch.ones(x.shape[-1], device=x.device, dtype=x.dtype)
assert variance_size is None
# ROCm's vLLM C RMSNorm kernel operates on contiguous 2D tensors.
# Higher-rank callers still normalize over the last dimension, so flatten
# all leading dims. reshape handles strided views from q/k/v splits.
if IS_ROCM and (x.dim() > 2 or not x.is_contiguous()):
original_shape = x.shape
x = x.reshape(-1, original_shape[-1])
output = torch.empty_like(x)
torch.ops._C.rms_norm(output, x, weight, epsilon)
return output.reshape(original_shape)
output = torch.empty(x.shape, device=x.device, dtype=x.dtype)
torch.ops._C.rms_norm(output, x, weight, epsilon)
return output
rms_add_no_var_size = (
lambda x, x_residual, weight, epsilon, variance_size=None: variance_size is None
and (weight is None or weight.dtype == x.dtype)
rms_add_no_var_size = lambda x, x_residual, weight, epsilon, variance_size=None: (
variance_size is None and (weight is None or weight.dtype == x.dtype)
)
"""vLLM Kernel does not support variance_size parameter and requires
matching input/weight dtype."""
@@ -59,5 +69,23 @@ def fused_add_rms_norm(
weight = torch.ones(x.shape[-1], device=x.device, dtype=x.dtype)
assert variance_size is None
if IS_ROCM and (not x.is_contiguous() or not x_residual.is_contiguous()):
output, residual = ir.ops.fused_add_rms_norm.impls["native"].impl_fn(
x, x_residual, weight, epsilon
)
x.copy_(output)
x_residual.copy_(residual)
return x, x_residual
# ROCm's vLLM C RMSNorm kernel operates on contiguous 2D tensors.
# Higher-rank callers still normalize over the last dimension, so flatten
# all leading dims.
if IS_ROCM and x.dim() > 2:
original_shape = x.shape
x = x.view(-1, original_shape[-1])
x_residual = x_residual.view(-1, original_shape[-1])
torch.ops._C.fused_add_rms_norm(x, x_residual, weight, epsilon)
return x.view(original_shape), x_residual.view(original_shape)
torch.ops._C.fused_add_rms_norm(x, x_residual, weight, epsilon)
return x, x_residual