Skip to content

The transposed score band has neither a mask origin nor a per-column statistic #178

Closed

Description

@feitreim

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 u32 there, and the difference is negative for every band above the diagonal — the fully-masked ones — so a u32 subtraction 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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions