nemo_automodel.components.attention.idlm_mask
nemo_automodel.components.attention.idlm_mask
I-DLM block-diffusion attention mask (Yu et al., 2026; arXiv:2604.11035).
Built over the concatenated [x_t (L) | x_0 (L)] input, where x_t is the
noisy (masked) copy and x_0 the clean copy. It combines three components
(paper Appendix E):
M_BD— causal self-attention within each noisyx_tblock.M_OBC— eachx_ttoken cross-attends cleanx_0tokens in strictly earlier blocks (the clean ground-truth prefix the decode is conditioned on).M_BC— strict token-causal attention within the cleanx_0copy.
With block_size == 1 each x_t token attends only to itself plus the clean
tokens strictly before it, and x_0 is plain autoregressive.
Module Contents
Functions
API
Build a sparse FlexAttention :class:BlockMask for I-DLM training.
Same semantics as :func:create_idlm_sdpa_mask but avoids materialising the
dense 2L x 2L mask — preferred at scale. Consumed by transformers’
flex_attention backend when _attn_implementation="flex_attention";
pass it via the attention_mask kwarg.
Parameters:
Length L of one copy (concatenated length is 2L).
Diffusion block size.
Padding-validity mask over one copy, shape [B, L].
torch device.
Reuse a cached torch.compile’d create_block_mask.
Returns: 'BlockMask'
class:torch.nn.attention.flex_attention.BlockMask.
Build the dense additive [x_t | x_0] block-diffusion mask for SDPA.
The x_0 region is always strict token-causal, matching the paper (§3.1)
and every released I-DLM checkpoint.
Parameters:
Length L of one copy (the concatenated length is 2L).
Diffusion block size (block_length in the paper).
Padding-validity mask over one copy, shape [B, L]
(1 = real token); padded keys are blocked in both copies.
torch device.
dtype for the additive mask (typically the model dtype).
Returns: torch.Tensor
[B, 1, 2L, 2L] float tensor: 0 at attended positions, -inf