How statement and proof provenance work
The first chip identifies the source of the statement or construction; the second identifies the source of its local proof or verification.
- Literature-sourced: the exact statement appears in a cited source; only wording and notation differ.
- AI-adapted: a semantically identical restatement of literature-sourced material, modulo indexing, notation, and boundary cases adopted by the library.
- AI-generated: a genuinely novel statement formulated by AI, with no source for the claim itself.
These labels describe origin, not correctness: citations and verification chips remain separate evidence.
Exact tiled attention and memory-aware differentiation
1 · Prerequisites
- Attention, transformer universality, and sequence limits
- Automatic differentiation and backpropagation
- Automatic differentiation and computational graphs
- Binary Operations, Monoids, Groups and Subgroups
- Compactness in Metric Spaces
- Completeness, Completion, and Uniform Continuity
- Construction of the Natural Numbers
- Construction of the Real Numbers via Cauchy Sequences
- Construction of the Real Numbers via Dedekind Cuts
- Continuity, IVT, EVT, and Uniform Continuity
- Countability and Uncountability
- Filters and Ultrafilters
- Foundations of the Real Numbers for Analysis
- Limits of Real Functions
- limsup, liminf, and Subsequential Limits
- Linear Independence, Bases and Dimension
- Linear Transformations, Rank-Nullity and Quotient Spaces
- Metric Spaces
- Monotone Functions, Discontinuities, and Continuity Sets
- Monotone Sequences, Bolzano-Weierstrass, and Cauchy Completeness
- Order, Zorn's Lemma, and the Axiom of Choice
- Properties of the Integral and the Working FTC
- Relations, Functions, and Quotients
- Rings, Subrings, Integral Domains and Fields
- Rⁿ as a Normed Space; Vector-Valued Functions
- Roots, Rational Powers, and Classical Inequalities
- Sequences and Limits
- Suprema and Infima
- The Derivative and the Mean Value Theorems
- The Inverse and Implicit Function Theorems
- The Riemann Integral: Definition and Integrability
- The Total Derivative in ℝᵐ → ℝⁿ
- The ZFC Axioms and the Basic Set Constructions
- Topology of ℝ
- Vector Spaces, Linear Subspaces, Span and Direct Sums
2 · Logical flowchart
3 · Definitions, theorems and proofs
Stable summary of an attention key block
Definition
Let be positive integers, let and , let , and for each query row let be a nonempty set of allowed keys. Write for row of , for row of , for row of , and for . For a nonempty finite set , its attention summary is
The empty set has the separate state and has no maximum or numeric summary coordinates. For disjoint nonempty , define their merge by
and set . This summary stores the maximum score, a positive shifted normalizer, and the correspondingly shifted weighted value sum; dividing its third coordinate by its second gives the attention output on .
Exact tiled softmax attention with block-recomputed vector-Jacobian products
Definition
Inputs: Positive integers , finite real matrices and , a real scale , a positive integer key-block size , and fixed nonempty allowed-key sets . The algorithm reads membership in each on demand; any caller-owned representation of the mask is input storage. All operations below are in exact real arithmetic. Set for .
Forward procedure:
- For each query row , set the current summary to .
- For , form . If , skip this block and leave the summary unchanged. Otherwise compute . If the current summary is , copy ; otherwise merge the current summary with using .
- After the final block, write and retain the final and for a later reverse pass.
- Return and the retained row statistics.
Reverse procedure: Given a forward run with the same and an upstream matrix , initialize to zero. For each query row , compute . For every block and each , recompute from and set
Then, for , add to the query and key gradient arrays, and for , add to the value gradient array:
Return . Do not store a full score or probability matrix: the reverse procedure recomputes one block's scores from the same inputs and fixed allowed-key sets. The prescribed reverse procedure treats the forward maxima and normalizers as frozen scaling statistics; it does not differentiate a maximum operation. The base algorithm has no dropout. Any dropout extension must replay the same realized dropout mask in its reverse pass.
Definition references
Summary state and merge convention
Masked scaled dot-product attention
Addition of contributions from repeated uses of shared inputs
Exact reverse-mode differentiation of a finite smooth real-arithmetic graph
Milakov and Gimelshein, §§2–3: stable online softmax normalizer
MIT OCW, Chapter 8 §§8.3–8.4: reverse-mode chain rule and accumulation at shared inputs
Tiled attention and its recomputed reverse pass are exact
Statement
Let be positive integers, and be finite real matrices, , a positive integer, and a fixed nonempty set of allowed keys for every query row . Write for row of , and for row of . Let be the forward outputs and row statistics of the exact tiled softmax attention algorithm, and fix an upstream matrix . Then each row of equals the dense masked attention row
and the algorithm's recomputed reverse procedure returns the Euclidean gradients of the scalar function with respect to , while holding , the sets , and fixed. Its reverse rule treats the stored maxima as fixed normalization shifts, so the conclusion also holds when scores tie at a row maximum. Every row is defined because is nonempty; no convention for an all-masked row is asserted.
Statement references
Dao et al., §3.1 and Appendix C: exactness of the online tiled attention recurrence
Dao et al., Appendix B.2–B.4: reverse-mode derivatives and block recomputation
Milakov and Gimelshein, §3: online normalizer recurrence and its induction proof
MIT OCW, Chapter 8 §§8.3–8.4: finite-graph reverse-mode chain rule
Facts & Assumptions
Given: The finite real inputs, the fixed nonempty allowed-key sets, the positive block size, the forward and reverse procedures, and the upstream matrix .
Scaled dot-product attention: masked attention uses row softmax of the scaled query-key scores and is defined only when each row has an allowed key.
Stable summary of an attention key block: for nonempty , the summary coordinates are , , and ; the empty set is the separate symbol .
Exact tiled softmax attention with block-recomputed vector-Jacobian products: the forward pass skips empty allowed blocks, copies the first nonempty block summary, merges later summaries, and the reverse pass recomputes and accumulates the stated entries.
Finite straight-line computational programs and real-arithmetic tapes: a finite topologically ordered real-arithmetic graph has differentiable primitive maps on open domains and repeated input uses are separate parent slots.
Reverse mode computes the exact gradient of the real-arithmetic graph: for a finite program with one scalar output on a fixed strict branch, reverse mode returns the exact derivative of that output.
The chain rule for total derivatives: : for totally differentiable finite-dimensional maps, the derivative of a composition is the ordered composition of the derivatives.
Backpropagation through a finite shared-parameter recurrence: the same parameter vector is supplied to every transition.
Reverse accumulation sums gradients over shared parameter uses: the gradient formula includes a pullback term for each transition using the shared parameter.
Proof
Fix a query row and let be the union of the allowed keys in the blocks processed so far. Initially and the algorithm's state is . An empty allowed block leaves both and the state unchanged. If and the next allowed block is nonempty, copying gives the defining summary of . If and are both nonempty, the merged maximum is , and while . The same two identities with inside each sum give the merged coordinate. Disjoint blocks therefore preserve the summary invariant.
The key blocks partition , so after the last block . The maximum is finite and at least one term in equals , hence . Dividing by and multiplying numerator and denominator by gives the displayed dense masked attention row. This also proves every retained is defined.
With the allowed sets fixed, every score is a polynomial in the entries of ; finite exponentials, sums, and division by the strictly positive dense denominator make the dense row map smooth on all of . Its scalarization is therefore a finite real-arithmetic graph. The reverse-mode theorem and chain rule apply to this dense graph; the maximum used only to scale the tiled forward computation is not a primitive of this graph.
For , write , as justified by step 2.1. Direct quotient differentiation gives . Thus for the score derivative is . The direct value derivative is .
Since , its coordinate derivatives are and . The chain rule therefore gives the row- contributions to , to , and to . Entries of other query rows receive no contribution from this row.
Set , , , for , and terminal loss . Step 3.1 makes every continuously differentiable on the open domain . By induction on , the recurrence state after transitions is : the formula holds at because , and adding the th transition term proves it at from its value at . Thus its scalar output is . The same parameter is supplied at every transition, and the shared-parameter gradient formula sums each transition's parameter pullback. It therefore adds each row's pullback at the common inputs, while the row-specific pullbacks occupy their corresponding rows. There is no direct loss or initial-state parameter term because is and is constant. Thus the algorithm's reverse updates give .
At the forward values, the summary invariant in steps 1.1–2.1 gives . Therefore, for each , This is the dense softmax probability evaluated at the current scores. Steps 4.1–6.1 differentiate the smooth dense attention map and show that substituting these probabilities into the reverse updates gives its exact gradient at these inputs. The stored and are used as normalization shifts in those updates; no derivative of either statistic is needed. The argument applies whether or not the maximum score is tied.
Tiled attention uses linear retained memory and quadratic arithmetic
Statement
In the unit-cost real-arithmetic model where scalar arithmetic, exponential evaluation, comparisons, and one allowed-key membership query each cost , the forward and reverse procedures of the exact tiled softmax attention algorithm use arithmetic operations. The forward procedure retains the inputs, the output, and two scalar statistics per query, requiring stored input and output scalars, with at most additional live scalars for one block's scores and weighted-value summary. The reverse procedure additionally takes and returns ; counting these as input and output arrays, it also uses stored input and output scalars and at most additional live scalars. Neither procedure materializes an score or probability array. Storage for a caller-owned mask representation is input storage and is not part of the additional workspace; if it is a dense array, its own entries must be counted separately. The exactness of the forward and reverse outputs is the assertion of the tiled-attention exactness theorem. No hardware I/O or floating-point operation count is asserted.
Statement references
Facts & Assumptions
Given: The positive integers , fixed allowed-key sets, and the two procedures of the exact tiled softmax attention algorithm.
Exact tiled softmax attention with block-recomputed vector-Jacobian products: the forward procedure processes one query row and one key block at a time, while the reverse procedure recomputes each permitted score and accumulates gradients into output arrays.
Stable summary of an attention key block: a nonempty block summary stores one scalar maximum, one scalar normalizer, and one vector in ; an empty block stores no numeric state.
Tiled attention and its recomputed reverse pass are exact: the two procedures return the dense masked attention and its exact vector-Jacobian product.
Exact tiled softmax attention with block-recomputed vector-Jacobian products: the reverse procedure recomputes each block's scores and does not store a full score or probability matrix.
The mask membership accessor is read-only, has query cost, and any storage for its representation is caller-owned input storage rather than algorithmic scratch.
The operation count is scalar arithmetic, exponential evaluation, comparisons, and mask membership queries; all are unit cost in this model.
Proof
The forward procedure retains and . Their scalar counts are because . At any query and key block it stores at most scores and the current and block weighted-value vectors of length , plus a constant number of scalars. This is extra live storage, and it discards the block workspace before moving to the next block.
The forward loops examine at most query-key pairs. For each pair, the score dot product uses operations; its normalized exponential and weighted-value contribution use operations. Block maxima, membership queries, and scalar loop overhead cost in total. There are at most block visits, each summary copy or merge costs , and final row divisions cost . Thus forward arithmetic is . Only one block's scores and weighted-value summaries are live, so no score or probability array is allocated.
The reverse procedure's retained arrays are and the row statistics. Their scalar counts are all . For one row and one key it recomputes one score and one probability, forms scalar inner products, and updates entries in the already allocated gradient arrays; it needs only a constant number of additional scalars, which is within . It does not store the recomputed probabilities across pairs.
Each query-key pair in the reverse pass costs operations: one score, one inner product with , and vector updates with lengths and . There are at most pairs, and the finite loop overhead is at most , so reverse arithmetic is . Since scores and probabilities are recomputed one at a time, this pass also creates no array. The separate exactness claim is supplied by [F3].
The scalar workspace result is not a hardware I/O bound
Remarks
The workspace theorem counts scalar storage and operations for the explicitly defined real-arithmetic procedure. It does not count reads and writes between GPU high-bandwidth memory and on-chip SRAM, and it gives no hardware speedup claim. The FlashAttention paper's HBM-access result assumes its stated memory model, block schedule, and range ; its endpoint input-size argument is not a lower bound for every fixed memory size. Neither claim follows from the scalar workspace theorem here.
The maximum shift makes every exact-real exponent argument nonpositive, but this does not specify rounded arithmetic or rule out underflow of very small finite-precision terms. Different floating-point accumulation orders can return different bit patterns. The base procedure includes no dropout; if an extension uses dropout, its fixed realized mask must be reused in the reverse pass because a different mask changes the differentiated function.
4 · Examples, counterexamples and false statements
None yet.
Sources
- Tri Dao et al., FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness, §3.1 and Appendix C
- Maxim Milakov and Natalia Gimelshein, Online normalizer calculation for softmax, §3
- Tri Dao et al., FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness, §§2–3, Appendix B.2–B.4, and Appendix C
- Maxim Milakov and Natalia Gimelshein, Online normalizer calculation for softmax, §§2–3
- MIT OpenCourseWare 18.S096, Matrix Calculus for Machine Learning and Beyond, Chapter 8 §§8.3–8.4
- Tri Dao et al., FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness, §§3.1, Appendix B.2–B.4, and Appendix C
- Tri Dao et al., FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness, §3.1, Appendix B.2–B.4, and Appendix C
- Tri Dao et al., FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness, §§2.1–3.2 and Appendix B