core/nn/masks library

Attention masks — helpers that build the additive [N, N] masks consumed by scaledDotProductAttention.

The convention across the library is additive masks: 0 for allowed positions and a large negative value (default -1e9) for blocked positions. The mask is added to the pre-softmax scores.

Functions

causalMask(int n, {double blockValue = -1e9, Device device = Device.CPU}) Tensor
Upper-triangular (strict) causal mask of shape [n, n]. Position i is allowed to attend to positions j <= i; entries with j > i are set to blockValue (default -1e9). Non-trainable.