nemo_automodel.components.models.glm5_next.optimized_kernels
nemo_automodel.components.models.glm5_next.optimized_kernels
Optional model-owned mHC and RMSNorm compilation for GLM-5.3-Flash.
Module Contents
Classes
Functions
Data
API
Bases: NamedTuple
The three mHC functions selected together for one model instance.
Precision-preserving options for the installed Inductor, or None if it cannot honor them.
Inductor options that preserve the eager BF16 truncation points between fused operations.
Parameters:
Option names of the installed Inductor config.
Returns: dict[str, bool] | None
Option mapping for torch.compile(options=...), or None when
Name Inductor’s eager division-rounding control as the given PyTorch spells it.
Newer PyTorch spells it eager_numerics.division_rounding; older releases
such as 2.10 only accept the legacy emulate_divison_rounding key, and
releases such as 2.8 have neither. torch.compile rejects unknown keys.
Parameters:
Option names of the installed Inductor config.
Returns: str | None
The division-rounding option name present in known_options, or
Fuse four-stream BF16 mixing with the expansion’s existing cast boundaries.
Parameters:
BF16 tensor of shape [batch, sequence, hidden].
BF16 tensor of shape [batch, sequence, streams, hidden].
FP32 tensor of shape [batch, sequence, streams].
FP32 tensor of shape [batch, sequence, streams, streams], indexed [source_stream, destination_stream].
Returns: torch.Tensor
Updated streams of shape [batch, sequence, streams, hidden], in the
Accumulate FP32 pre-weighted streams, then round the output once.
Parameters:
Tensor of shape [batch, sequence, streams, hidden].
FP32 tensor of shape [batch, sequence, streams].
Returns: torch.Tensor
Tensor of shape [batch, sequence, hidden] in the residual-stream dtype.
Keep coefficient, product, BMM output and sum rounding in GLM’s order.
Parameters:
Tensor of shape [batch, sequence, hidden] in the residual dtype, the sublayer output.
Tensor of shape [batch, sequence, streams, hidden].
FP32 tensor of shape [batch, sequence, streams].
FP32 tensor of shape [batch, sequence, streams, streams], indexed [source_stream, destination_stream].
Returns: torch.Tensor
Tensor of shape [batch, sequence, streams, hidden] in the residual
Normalize and sigmoid-gate KDA output, preserving eager cast boundaries.
Parameters:
Tensor of shape [batch, sequence, heads, head_dim].
Tensor of shape [batch, sequence, heads, head_dim].
Tensor of shape [head_dim] in hidden_states’s dtype.
Additive RMS normalization epsilon.
Returns: torch.Tensor
Tensor of shape [batch, sequence, heads, head_dim] in
Select per-instance mHC functions without changing eager model instances.
Static shapes match the model-owned DeepSeek V4.1 compilation pattern. Past Dynamo’s recompile limit, its normal eager fallback remains available. Base/scale parameters and their FSDP holder are outside these functions. PyTorch without the precision controls also keeps the eager functions.
Round normalized values before multiplying the norm weight, as GLM does.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Tensor of shape [hidden] in the input dtype.
Additive RMS normalization epsilon.
Returns: torch.Tensor
Tensor with the input shape and dtype. The FP32 normalized values are
Normalize the flattened streams in FP32 before the coefficient GEMM.
Parameters:
Tensor of shape [batch, sequence, streams, hidden],
where streams is config.hc_mult.
Tensor of shape [streams * (2 + streams), streams * hidden], the projection weight.
Additive RMS normalization epsilon.
Returns: torch.Tensor
FP32 tensor of shape [batch, sequence, streams * (2 + streams)],
Select the decoder/final RMSNorm core, retaining GLM’s cast order.
Select the KDA gated norm core with the same cast policy as decoder norms.