Skip to content

feat(attention): emit forward LSE and harden matmul tuning - #428

Draft
ppodolsky wants to merge 4 commits into
tracel-ai:mainfrom
ppodolsky:feat/attention-forward-lse
Draft

feat(attention): emit forward LSE and harden matmul tuning#428
ppodolsky wants to merge 4 commits into
tracel-ai:mainfrom
ppodolsky:feat/attention-forward-lse

Conversation

@ppodolsky

@ppodolsky ppodolsky commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add an opt-in accelerated attention launch that emits per-row softmax log-sum-exp alongside the existing output
  • thread the FP32 LSE tensor through the batch, global, stage, and Bounce tile layers without changing existing launch signatures
  • extend the existing LSE oracle with an accelerated-kernel comparison
  • prevent matmul autotune keys from sharing an async-copy winner between aligned and unaligned tensors in the same anchored shape bucket
  • pin the consolidated CubeCL accelerator PR for downstream compatibility validation

This PR absorbs the temporary compatibility-only draft #429 so CubeK has one upstream review thread.

The LSE output is flat [batch * heads, seq_q], uses natural log, and writes negative infinity for fully masked rows. Existing launch_ref and component signatures retain their behavior.

The matmul key keeps anchored M/N/K buckets and bounded cardinality. It adds only two stride-legality classes per operand: 16-byte aligned or not aligned. This prevents a cached async-copy/TMA candidate from failing when a later raw shape in the same bucket has incompatible strides.

Dependency validation

Validation

  • cargo fmt --all -- --check
  • cargo test -p cubek-matmul strategy::tune_key --lib
  • cargo check -p cubek-attention
  • cargo test -p cubek-attention --no-run
  • A100 attention CPU-reference parity and end-to-end BF16 loss/gradient checks
  • A100 299.9M-parameter MoE training smoke: five optimizer steps completed after reproducing the former invalid async-copy autotune selection

The current Linux CI failure occurred in runner setup: Microsoft's Ubuntu apt repositories returned HTTP 403 before checkout/build tests began. Code-quality and documentation jobs passed.

The flash forward's running (max, sum) state was discarded after the
rescale; a FlashAttention backward needs the per-row log-sum-exp to
recompute probabilities without materializing scores. New additive path:

- BounceTile::store_row_lse writes m + ln(l) per absolute row through the
  whitebox fragment layout (the unit owning a row's first column writes;
  rows below the fully-masked threshold receive exactly -inf, matching
  the CPU reference convention), with a Tile-level dispatcher.
- StageAttention::write_lse / GlobalAttention::execute_with_lse /
  BatchAttention::execute_with_lse thread a flat [batch * heads, seq_q]
  FP32 tensor through the existing layers; the global layer emits before
  the rescale consumes the state.
- attention_with_lse entry point + BatchAttentionFamily::
  launch_unchecked_with_lse + public launch_ref_with_lse /
  launch_attention_with_lse. Only the cmma (BlackboxAccelerated) routine
  emits LSE; the unit routine reports InvalidConfig loudly.

Every existing signature is untouched.
@ppodolsky
ppodolsky force-pushed the feat/attention-forward-lse branch from d3b1bce to 17fcf4a Compare August 1, 2026 07:52
@ppodolsky ppodolsky changed the title feat(attention): emit forward LSE and validate CubeCL feat(attention): emit forward LSE and harden matmul tuning Aug 1, 2026
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