nemo_automodel.components.moe.swiglu_triton
nemo_automodel.components.moe.swiglu_triton
Triton kernels for the clamped SwiGLU expert activation (DeepSeek-V4 style, swiglu_limit > 0).
The routed experts apply silu(clamp(gate, max=L)) * clamp(up, -L, L) * probs to the grouped-GEMM output
x = [gate | up] (bf16, [rows, 2 * inter]) with fp32 routing probabilities probs ([rows, 1]). The
compiled PyTorch version (experts._swiglu_clamped_deepep_compiled) is one inductor kernel forward, but its
autograd-derived backward concatenates d_gate and d_up and ran at about a quarter of HBM bandwidth on
GB200 (0.7 ms for a 1.1 GB pass at the 16-node shape). These kernels do one pass each:
- forward: a 2-D tile per program, fp32 math, result rounded to
x.dtype; - backward: one program per block of rows looping over the columns, writing
d_gate/d_upstraight into the two halves ofgrad_xand accumulating the per-row probability gradient in registers.
Clamp gradients follow torch.clamp (inclusive range masks on the input values). The dispatcher in
experts.swiglu_clamped_deepep uses these kernels on contiguous CUDA inputs when Triton is importable and
falls back to the compiled version otherwise.
Module Contents
Classes
Functions
Data
API
Bases: Function
silu(clamp(gate)) * clamp(up) * probs with the Triton forward and backward kernels.
Apply the clamped SwiGLU with the Triton kernels; callers check uses_triton_kernel first.
Whether the Triton kernels can take these inputs (contiguous 2-D CUDA x, one probability per row).