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]. Positioniis allowed to attend to positionsj <= i; entries withj > iare set toblockValue(default-1e9). Non-trainable.