Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions python/sglang/kernels/kda_kernels/residual_gate_add_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def _rga_transposed(


def _residual_gate_add_triton(residual, update, gate):
if not can_use_residual_gate_add_cuda(residual, update, gate):
raise RuntimeError("unsupported input for residual_gate_add CUDA")
# Both callers validate the inputs first; repeating the predicate here cost
# ~2.7us of host time on every call.
out = torch.empty_strided(
residual.shape, residual.stride(), dtype=residual.dtype, device=residual.device
)
Expand Down Expand Up @@ -420,7 +420,12 @@ def _residual_gate_add_custom_op(
residual: torch.Tensor, update: torch.Tensor, gate: torch.Tensor
) -> torch.Tensor:
with torch.cuda.device(residual.device):
return _residual_gate_add_triton(residual, update, gate)
# Take the Triton path only for the transposed-dense layout it was
# benchmarked on. For the contiguous layouts every other diffusion model
# uses, the existing JIT CUDA kernel is faster at every measured shape.
if _is_transposed_dense_residual(residual, update, gate):
return _residual_gate_add_triton(residual, update, gate)
return _residual_gate_add_cuda_impl(residual, update, gate)


def _gate_mode(residual: torch.Tensor, gate: torch.Tensor) -> int:
Expand Down Expand Up @@ -513,7 +518,7 @@ def residual_gate_add(
and can_use_residual_gate_add_cuda(residual, update, gate)
):
try:
return residual_gate_add_cuda(residual, update, gate)
return _residual_gate_add_custom_op(residual, update, gate)
except Exception as exc:
if torch.compiler.is_compiling():
raise
Expand Down
Loading