nemo_automodel.components.models.muse_spark.layers
nemo_automodel.components.models.muse_spark.layers
Text layers for the native Muse Spark Open implementation.
Module Contents
Classes
Functions
Data
API
Bases: Module
Muse GQA with Q/K and output RMSNorm, output gate, RoPE, SDPA, and TE.
Project [B,S,H] or [T,H] states into matching BSHD/THD QKV.
Return TE’s left/right window, treating short packed documents as full causal.
Attend over ordinary or packed states using this layer’s CP transport.
Parameters:
CP-local states [batch, local_sequence, hidden] or packed [local_tokens, hidden].
Rotary cosine/sine tensors [batch, local_sequence, head_dim] or packed [local_tokens, head_dim].
Optional mask broadcastable to [batch, heads, sequence, sequence]; unused for packed THD.
Attention metadata, including qkv_format and global packed document boundaries cu_seqlens [documents + 1].
Returns: torch.Tensor
Attention output with the same local layout as hidden_states.
Bases: GradientCheckpointingLayer
One FP32 residual-stream Muse Spark Open decoder layer.
Expose the checkpoint-named feed-forward through the generic MoE protocol.
Transform batched or packed residual states through attention and MoE.
Parameters:
Residual activations shaped [B, S, H] or [T, H].
Cosine and sine tensors shaped [B, S, head_dim / 2].
Optional mask in the selected attention backend’s layout.
Optional token padding mask shaped [B, S] or [T].
Additional arguments for the selected attention backend.
Returns: torch.Tensor
Independent residual states with the input shape, dtype and device.
Preserve norm compilation limits on the checkpoint recomputation thread.
Parameters:
Existing forward/recompute context factory, if present.
Returns: Callable[[], tuple[AbstractContextManager, AbstractContextManager]] | None
A factory composing the existing contexts with the forward thread’s
Bases: Gate
FP32 MetaP-scaled sigmoid router with bias used for selection only.
Route local [tokens, hidden] states and return FP32 top-k weights.
Bases: MoE
Compressed Muse experts with per-expert norms and grouped-GEMM dispatch.
Route [..., hidden] states through compressed, normalized experts.
Bases: Module
FP32-accumulating RMSNorm with optional zero-centered checkpoint gain.
Return the actual multiplicative gain with shape [hidden].
Normalize activations with the selected eager or compiled core.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Returns: torch.Tensor
Independent normalized tensor with the input shape, dtype and device.
Initialize the serialized gain without changing its effective value.
Bases: Module
Learned norm-preserving residual connection from the Muse checkpoint.
Blend activations while preserving the residual stream dtype.
Parameters:
Residual tensor of shape […, hidden], ordinarily FP32.
Tensor with the same shape and device as stream.
Returns: torch.Tensor
Independent tensor with the stream shape, dtype and device.
Bases: Module
FP32 adjacent-pair rotary frequencies shared by all text layers.
Return cosine/sine tensors shaped [batch, sequence, head_dim / 2].
Recreate FP32 frequencies after meta-device materialization.
Keep pure compiled math and autotuner scratch tensors outside SAC caching.
Muse’s selective checkpoint policy saves routing results, not norm or activation math. Autotuning a new shape during recomputation can execute scratch operations absent from the original forward. Exclude these pure islands from dispatch-mode accounting in both passes; autograd and the enclosing activation checkpoint still run.
Lazily share each of the five pure compiled cores within this process.
The cache retains callables, never model parameters or activations. Eager instances keep their original callables; enabling one model does not change another model’s dispatch. Compilation starts on the first real tensor call.
Apply the effective gain before FP32 RMS normalization.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Optional effective FP32 gain of shape [hidden], on the input device.
Stabilizer added to the mean squared scaled activation.
Returns: torch.Tensor
Independent tensor of shape […, hidden], in the input dtype and device.
Fuse a branch norm and residual blend without changing the branch cast.
Parameters:
Residual tensor of shape […, hidden], ordinarily FP32.
Tensor of shape […, hidden], matching the stream shape and device. Normalization casts back to this dtype before residual blending.
Optional effective FP32 norm gain of shape [hidden].
Trainable residual gate of shape [hidden], on the stream device.
Whether the gain precedes rather than follows normalization.
RMS normalization stabilizer.
Residual gate temperature.
Lower bound on the squared residual coefficient.
Returns: torch.Tensor
Independent tensor of shape […, hidden], in the stream dtype and device.
Fuse parameter-free output RMSNorm and the checkpoint’s sigmoid gate.
Parameters:
Attention output [B,S,Hq,D] or packed [T,Hq,D].
Gate projection with the same shape, dtype and device as output.
FP32 RMS normalization stabilizer.
Returns: torch.Tensor
Gated output in the original dtype. Both normalization and sigmoid
Normalize and rotate Q/K while preserving the checkpoint’s dtype boundaries.
Parameters:
Query tensor [B,S,Hq,D] or packed [T,Hq,D].
Key tensor with matching leading dimensions and Hkv heads.
Rotary cosines [B,S,D/2], or [1,T,D/2] for packed inputs.
Rotary sines with the same shape and dtype as cosine.
FP32 RMS normalization stabilizer.
Multiplier applied after the normalized query’s dtype cast.
Whether this layer uses adjacent-pair rotary embeddings.
Whether rotation uses FP32 (legacy) or the Q/K dtype (v2).
Returns: torch.Tensor
Independent normalized query and key tensors in their original layouts
Repeat BSHD key/value heads from [B,Nkv,S,D] to query-head count.
Blend the residual and branch using the checkpoint’s learned gate.
Parameters:
Residual tensor of shape […, hidden], ordinarily FP32.
Tensor of shape […, hidden], matching the stream shape and device.
Trainable gate of shape [hidden], on the stream device.
Gate temperature.
Lower bound on the squared residual coefficient.
Returns: torch.Tensor
Independent tensor of shape […, hidden], in the stream dtype and device.
Normalize in FP32, then apply the effective gain before the output cast.
Parameters:
Tensor of shape […, hidden], with arbitrary leading dimensions.
Optional effective FP32 gain of shape [hidden], on the input device.
Stabilizer added to the mean squared activation.
Returns: torch.Tensor
Independent tensor of shape […, hidden], in the input dtype and device.
Apply adjacent-pair RoPE with the checkpoint’s arithmetic precision.
The original checkpoint computes the rotation in FP32. The HF release rounds both products in the Q/K dtype before adding them.
Translate the released Muse router and compressed-expert contract.
Return the checkpoint-defined zero-centered RMSNorm gain offset.
Resolve the config’s model dtype without importing recipe utilities.