nemo_automodel.components.models.qwen3_5.layers
nemo_automodel.components.models.qwen3_5.layers
Fused elementwise kernels for the dense Qwen3.5 decoder.
The reference Qwen3.5 decoder runs its norms, residual adds, SwiGLU activation and GatedDeltaNet decay gate as chains of eager elementwise kernels, each a full pass over the activation: about seven forward launches per zero-centered RMSNorm and nine per gated RMSNorm, with more in backward. On CUDA these modules compile the same math into fused Triton kernels for forward and backward. CPU and DTensor inputs keep the eager chain, so results match the reference modules.
Module Contents
Classes
Functions
Data
_add_zero_centered_rms_norm_compiled
_zero_centered_rms_norm_compiled
API
Bases: MLP
Dense SwiGLU MLP whose silu(gate) * up runs as one fused kernel on CUDA.
Project, apply the fused SwiGLU product, and project back.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Returns: torch.Tensor
Tensor of shape […, hidden].
Bases: Qwen3NextRMSNorm
Zero-centered Qwen3.5 RMSNorm computed by one fused kernel on CUDA.
Normalize the last axis in fp32 and scale by 1 + weight.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Optional tensor of x’s shape and dtype. When given, the
residual add is fused into the norm: x + residual is normalized
and returned alongside its normalization.
Returns: torch.Tensor | tuple[torch.Tensor, torch.Tensor]
Tensor of shape […, hidden] in x’s dtype, or, with residual, the
Bases: Qwen3_5MoeRMSNormGated
GatedDeltaNet output norm with SiLU gate computed by one fused kernel on CUDA.
Normalize the last axis, apply the gain, then multiply by silu(gate).
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Tensor of shape […, hidden] holding the output-gate logits.
Returns: torch.Tensor
Tensor of shape […, hidden] in hidden_states’ dtype.
Bases: SSMGate
fp32 GatedDeltaNet decay gate computed by one fused kernel on CUDA.
Compute -exp(A_log) * softplus(a + dt_bias) in fp32.
Parameters:
Tensor of shape […, value_heads] from the decay projection.
Returns: torch.Tensor
fp32 tensor of shape […, value_heads].
Add residual to x and normalize the sum, as an add followed by Qwen3NextRMSNorm.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Tensor of the same shape and dtype as x.
Tensor of shape [hidden] holding the zero-centered gain.
Epsilon added to the mean square.
Returns: torch.Tensor
The sum x + residual and its normalization, both of shape […, hidden]
Compute weight * norm(hidden_states) * silu(gate) as Qwen3_5MoeRMSNormGated.
The normalized activations are rounded to the input dtype before the weight multiply, matching the reference module.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Tensor of shape […, hidden] holding the output-gate logits.
Tensor of shape [hidden] holding the multiplicative gain.
Epsilon added to the mean square.
Returns: torch.Tensor
Tensor of shape […, hidden] in hidden_states’ dtype.
Compute the SwiGLU product silu(gate) * up as the eager MLP does.
Parameters:
Tensor of shape […, intermediate] from the gate projection.
Tensor of the same shape and dtype from the up projection.
Returns: torch.Tensor
Tensor of shape […, intermediate] in gate’s dtype.
Compute the GatedDeltaNet log-decay -exp(A_log) * softplus(a + dt_bias) as SSMGate.
Parameters:
Tensor of shape […, value_heads] from the decay projection.
Tensor of shape [value_heads] holding A_log.
Tensor of shape [value_heads].
Returns: torch.Tensor
fp32 tensor of shape […, value_heads].
Compute norm(x) * (1 + weight) in fp32, exactly as Qwen3NextRMSNorm.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Tensor of shape [hidden] holding the zero-centered gain.
Epsilon added to the mean square.
Returns: torch.Tensor
Tensor of shape […, hidden] in x’s dtype.