Signed-off-by: hello-args <args.sarkar@gmail.com>
This commit is contained in:
@@ -25,9 +25,6 @@ rms_no_var_size = lambda x, weight, epsilon, variance_size=None: (
|
||||
def rms_norm(
|
||||
x: Tensor, weight: Tensor | None, epsilon: float, variance_size: int | None = None
|
||||
) -> Tensor:
|
||||
if weight is None:
|
||||
# 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
|
||||
@@ -64,10 +61,6 @@ def fused_add_rms_norm(
|
||||
epsilon: float,
|
||||
variance_size: int | None = None,
|
||||
) -> tuple[Tensor, Tensor]:
|
||||
if weight is None:
|
||||
# Kernel requires weight tensor, pass ones
|
||||
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(
|
||||
|
||||
+13
-7
@@ -29,10 +29,12 @@ rms_no_var = lambda x, weight, epsilon, variance_size=None: variance_size is Non
|
||||
def rms_norm(
|
||||
x: Tensor, weight: Tensor | None, epsilon: float, variance_size: int | None = None
|
||||
) -> Tensor:
|
||||
if weight is None:
|
||||
# Kernel requires weight tensor, pass ones
|
||||
weight = torch.ones(x.shape[-1], device=x.device, dtype=x.dtype)
|
||||
assert variance_size is None
|
||||
if weight is None:
|
||||
# Weightless _C ops are CUDA-only; native skips the multiply on XPU.
|
||||
return ir.ops.rms_norm.impls["native"].impl_fn(
|
||||
x, weight, epsilon, variance_size
|
||||
)
|
||||
output = torch.empty(x.shape, device=x.device, dtype=x.dtype)
|
||||
torch.ops._C.rms_norm(output, x, weight, epsilon)
|
||||
return output
|
||||
@@ -57,10 +59,14 @@ def fused_add_rms_norm(
|
||||
epsilon: float,
|
||||
variance_size: int | None = None,
|
||||
) -> tuple[Tensor, Tensor]:
|
||||
if weight is None:
|
||||
# Kernel requires weight tensor, pass ones
|
||||
weight = torch.ones(x.shape[-1], device=x.device, dtype=x.dtype)
|
||||
|
||||
assert variance_size is None
|
||||
if weight is None:
|
||||
# Weightless _C ops are CUDA-only; native skips the multiply on XPU.
|
||||
output, residual = ir.ops.fused_add_rms_norm.impls["native"].impl_fn(
|
||||
x, x_residual, weight, epsilon, variance_size
|
||||
)
|
||||
x.copy_(output)
|
||||
x_residual.copy_(residual)
|
||||
return x, x_residual
|
||||
torch.ops._C.fused_add_rms_norm(x, x_residual, weight, epsilon)
|
||||
return x, x_residual
|
||||
|
||||
Reference in New Issue
Block a user