Rectangular attention with a Boolean mask #
Query and key lengths are independent. The mask is fixed, and every row may have its own allowed keys, including no allowed keys at all. The statements below concern the actual attention JVP and backward specifications, with their existing scale and zero-row conventions.
The pairing theorem identifies the transpose relation between these two implementations. The
analytic derivative of the row normalization comes from HardMaskedSoftmax; identifying the
whole attention JVP with the derivative of the forward map additionally requires composing the
matrix and row maps.
Each query row is normalized against its own row of the Boolean mask.
The weighted-centering helper acts independently on each query row.
The concrete masked row helper is symmetric for rectangular score matrices.
There is no requirement that a row contain an allowed key. The all-false case is already part of the row derivative theorem, so summing its inner-product identity over query rows preserves it.
The spec SDPA JVP and backward formulas have the exact Frobenius transpose relation.
The three terms keep query, key, and value gradients separate. In particular, the key term uses
the rectangular transposition dictated by Q Kᵀ; no equality of query and key lengths is assumed.
This algebraic identity is stated separately from differentiability of the forward map.