Why is a large negative value such as negative infinity used for masked positions in the attention score matrix?
Last updated
Masked logits are exponentiated, so −∞ yields exp = 0 (zero probability) and the softmax renormalizes over the rest. A logit of 0 gives exp(0) = 1, an ordinary weight, so 0 means neutral, not blocked.
True −∞ makes fully masked rows produce NaN (−∞ − (−∞)). Many implementations use
torch.finfo(dtype).minor −1e9 instead, giving a uniform distribution on such rows.Use a dtype-aware minimum: −1e9 overflows to −∞ in fp16 (max about 65504).