Skip to content

Accumulate generic tile flash attention directly into att_out. - #1065

Open
copybara-service[bot] wants to merge 1 commit into
devfrom
test_1003900950
Open

copybara-service[bot] wants to merge 1 commit into
devfrom
test_1003900950

Conversation

@copybara-service

Copy link
Copy Markdown

Accumulate generic tile flash attention directly into att_out.

att_out is now an IN/OUT parameter: the generic
TileFlashAttentionReturnExpSumsAndMaxLogits kernel uses it directly as the
online-softmax accumulator instead of a separate C accumulator buffer.

  • Remove the C accumulator region from TileFlashAttentionWorkspaceLayout
    (saves padded_q_count * qkv_dim * 4 bytes of per-worker workspace).
  • Drop the per-call zero fill of C and the final C -> att_out copy.
  • Address att_out via Row()/Stride() so padded layouts work.
  • LoadAndMulUpTo8Times2/StoreUpTo8Times2 now use unaligned loads/stores,
    since att_out rows are caller-provided and not guaranteed aligned.
  • Document that att_out must be zero-initialized before the first call
    (tiled_attention.cc already does this); fix the MixedRanges test and the
    attention benchmark, which passed uninitialized att_out.
  • Add TestTiledFlashAttentionChainedCalls with a kernel-agnostic helper,
    CheckChainedCallsMatchSingleCall, verifying that chaining calls over
    sub-ranges of the KV (carrying att_out, exp_sums and max_logits) matches a
    single call over the full range.

att_out is now an IN/OUT parameter: the generic
TileFlashAttentionReturnExpSumsAndMaxLogits kernel uses it directly as the
online-softmax accumulator instead of a separate C accumulator buffer.

- Remove the C accumulator region from TileFlashAttentionWorkspaceLayout
  (saves padded_q_count * qkv_dim * 4 bytes of per-worker workspace).
- Drop the per-call zero fill of C and the final C -> att_out copy.
- Address att_out via Row()/Stride() so padded layouts work.
- LoadAndMulUpTo8Times2/StoreUpTo8Times2 now use unaligned loads/stores,
  since att_out rows are caller-provided and not guaranteed aligned.
- Document that att_out must be zero-initialized before the first call
  (tiled_attention.cc already does this); fix the MixedRanges test and the
  attention benchmark, which passed uninitialized att_out.
- Add TestTiledFlashAttentionChainedCalls with a kernel-agnostic helper,
  CheckChainedCallsMatchSingleCall, verifying that chaining calls over
  sub-ranges of the KV (carrying att_out, exp_sums and max_logits) matches a
  single call over the full range.

PiperOrigin-RevId: 1003900950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant