[ROCm] Use silu_and_mul_with_clamp's torch._C op (#52052)

Signed-off-by: Tres Popp <tres.popp@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Shanshan Shen <467638484@qq.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
Tres
2026-09-22 18:30:14 -05:00
committed by GitHub
co-authored by Cursor Shanshan Shen Claude Sonnet 5 Andreas Karatzas
parent 1c0eee919d
commit d110c2f19c
2 changed files with 54 additions and 13 deletions
+6 -6
View File
@@ -233,12 +233,8 @@ class SiluAndMulWithClamp(CustomOp):
self.swiglu_limit = float(swiglu_limit)
self.alpha = float(alpha)
self.beta = float(beta)
if current_platform.is_rocm() or current_platform.is_xpu():
self._forward_method = self.forward_native
elif current_platform.is_cuda_alike():
if current_platform.is_cuda_alike():
self.op = torch.ops._C.silu_and_mul_with_clamp
elif current_platform.is_cpu():
self._forward_method = self.forward_native
def forward_native(self, x: torch.Tensor) -> torch.Tensor:
d = x.shape[-1] // 2
@@ -253,7 +249,11 @@ class SiluAndMulWithClamp(CustomOp):
self.op(out, x, self.swiglu_limit, self.alpha, self.beta)
return out
def forward_xpu(self, x: torch.Tensor) -> torch.Tensor:
def forward_hip(self, x: torch.Tensor) -> torch.Tensor:
# Limit the ROCm _C path to the default case to avoid the
# precision loss MiniMax saw without fp32 intermediates.
if self.alpha == 1.0 and self.beta == 0.0:
return self.forward_cuda(x)
return self.forward_native(x)
def extra_repr(self) -> str: