Loading...
Implement causal (autoregressive) masked attention.
In causal attention, each position can only attend to itself and previous positions. This is achieved by masking future positions with -infinity before softmax.
Given Q, K, V matrices, compute attention with a causal mask:
Input:
Output: The masked attention output, values rounded to 4 decimal places.
2 2 1 0 0 1 1 0 0 1 1 0 0 1
[1.0000 0.0000] [0.2689 0.7311]