Additive-Bias Multi-Head Attention Core #
This module proves the head-wise fixed-score-bias attention core. The surrounding
projection/split/merge graph lives in MultiHeadSelfAttention.lean; the theorem here is the
reusable additive-bias replacement for the score/probability/value part of that graph:
softmax(c · QKᵀ + bias) V.
The bias has shape (heads × seq × seq). This is not the boolean causal-mask semantics: boolean
attention masks in the spec/runtime path use hard masking, where blocked entries contribute zero
softmax numerator. This file is for intentional finite additive score biases.
Context for a fixed-bias attention core: [Q_heads, Kᵀ_heads, V_heads].
Instances For
Saved tensors for the fixed-bias multi-head attention core.
Instances For
Query-head index in the fixed-bias attention context.
Instances For
Transposed-key index in the fixed-bias attention context.
Instances For
Value-head index in the fixed-bias attention context.
Instances For
Proof-carrying fixed-bias attention core.
The fixed bias is added after scaling the score tensor and before the row-wise softmax.
Instances For
Reverse-mode theorem for the fixed-bias multi-head attention core.
Composition theorem for the additive-bias core after a projection/split stage.
projectPack is the mathematical interface exposed by a full MHA front half: it builds
[Q_heads, Kᵀ_heads, V_heads] from an outer context. The theorem composes that front half with the
proved additive-bias attention core.
Fixed-bias attention composition contract.
The theorem composes:
- a differentiable front half that projects/splits inputs into
Q,Kᵀ, andV; - the proved fixed-bias split-head attention core;
- a differentiable back half that merges/projects outputs or packages residual data for the caller.
Instantiating projectPack and mergePack with the concrete projection/split/merge graphs gives
the corresponding fixed-bias block's differentiability statement. The theorem assumes the two
outer derivative certificates; it does not construct them or prove Boolean causal masking.