attention
std.nn.attention · Level L0Scaled dot-product attention for one head.
softmax(Q·Kᵀ·s)·V
Signature
attention(Q: f64[m, d], K: f64[t, d], V: f64[t, e], scale: f64[]) → f64[m, e]
Structure
The function as NOVA stores it: one box per input, operation and output, and arrows that carry values. A double border marks a call to another library function; select it to open that function.
- input
- operation
- constant
- call
- output
Verification
- Signature proven by NOVA’s shape solver, for every size.
- Agrees with the reference
softmax((Q @ K.T) * scale, axis=-1) @ Vto 80 digits (100-digit arithmetic), on all 40 test cases. - All 680 float64 results inside the running error bound; the closest uses 9% of it.
- Interpreter and NumPy backend return bit-identical results.
Accuracy in detail
- correctly rounded (the float64 nearest the exact value)
- 54%
- bit-equal to the NumPy formula in float64
- 100%
- largest error, in units in the last place
- 175
Large ulp counts appear only where cancellation drives a result toward zero; the absolute error is still inside the bound.
Note
The scale is an input (usually 1/√d): a square root of a symbolic size needs the Size and Sqrt primitives (Round 14).
Identity
Calls
—
Called by
—
sha256:26f7c94b7a02cfa34fdee56bb84e80ff4e812054a5492981eb23a2eab4a5330aThe semantic hash of the graph. It changes when the program changes, and never when only its documentation does.