nemo_automodel.components.models.gemma4_moe.attention
nemo_automodel.components.models.gemma4_moe.attention
Composition of document-causal masks with Gemma4’s native attention policy.
Module Contents
Functions
API
Compose native full/sliding attention with an explicit document-causal mask.
Call only for the document-causal contract marked by _packed_seq_ids;
arbitrary custom 4D masks are already complete and must not be interpreted here.
HF otherwise treats a 4D input as complete, bypassing its vision/window policy.
Parameters:
Gemma4 text configuration using eager or SDPA attention.
Boolean-allowed or additive-zero/minimum mask [batch, 1, sequence, sequence]. This carries the caller’s selected document isolation and excludes padding/fake media on both axes.
Processor modality IDs [batch, sequence], or None for text.
Original document IDs [batch, sequence]. These keep image groups separate even when the selected mask allows cross-document attention.
Model floating point dtype for the additive native masks.
Returns: dict[str, torch.Tensor]
Full and sliding masks [batch, 1, sequence, sequence]: boolean for SDPA