Repository navigation
Description
Found writing the flash-attention backward rewrite (feitreim/oxide-train#69), which is the first kernel in either repo to score K·Qᵀ. Everything the library has for an attention band assumes the band's rows are queries; the key-parallel half of a backward pass has rows that are keys, and both of the things a band needs turn out to exist on one diagonal only.
1. make_causal_t has no _at form (§3.4)
§3.4's claim is not that the masks exist but that every one takes "a coordinate origin TK's signatures do not have", and make_causal_at's own doc says plainly why:
Prefer this to computing the difference at the call site. Both origins are
u32there, and the difference is negative for every band above the diagonal — the fully-masked ones — so au32subtraction wraps to a huge positive number and masks nothing.
make_causal_t has only the origin-free diagonal. The argument is stronger on that side: a CTA owning a block of keys streams the queries at and after them, so key_base - query_base is negative on every visit but the first — not on the edge case, on the common one.
2. A saved row statistic cannot reach the column axis (§2.2)
global::load_row_vec (#130/#170) reads attention's log-sum-exp out of the head's own column of [rows, heads] into a RegVec. The key-parallel backward wants the same numbers as a ColVec, because in K·Qᵀ the queries are the band's columns — sub_col_assign's operand, not sub_row_assign's.
Nothing spells that:
load_cols(A per-column operand in global memory has no way into registers:load_cols, the global twin ofldst::load_vec#172/A per-column operand in global memory reaches registers without a tile's worth of them (#172) #173) also returns aColVec, but readsNconsecutive elements of one row. The statistic is a column at strideheads, so it is the wrong walk.ldst::load_vecreads aColVecout of aSharedVec, so it would need the kernel to stage 64 floats per streamed tile into shared memory and publish them — and aSharedVeccannot be sliced (§1.4), so a ring of them is carved by hand.- Open-coding it is the scatter RegVec cannot reach memory, SharedVec cannot be sliced, and neither can be folded in place #130 was filed to delete, on the other axis.
The addresses are load_row_vec's exactly. Only the axis they land on differs, and that is a property of the band, not of the statistic.
What it costs
Both are small. The mask is a wrapper; the mover is load_row_vec's loop with col_of for row_of, and it needs its own device case rather than a line in global column map — two movers returning one type off one argument list is precisely the confusion worth pinning, and a mover that took the wrong walk passes the other case.
Activity