Skip to content

One FlexAttention core attention; shift blocks in the processor - #84

Merged
AmitMY merged 1 commit into
mainfrom
simplify/one-attention
Oct 11, 2026
Merged

AmitMY merged 1 commit into
mainfrom
simplify/one-attention

Conversation

@AmitMY

@AmitMY AmitMY commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #83.

One FlexAttention core attention

WeLT had two core attention classes: PackedAttention for packed short sequences (the encoders and the bytes decoder), and MaskedAttention for the latent transformer's mask. Both ran FlexAttention. They differed only in input layout and in where the block mask came from, and each built or cached its mask inside the layers.

Now there is one FlexCoreAttention, and the caller builds the block mask once for all layers:

  • Packed sequences: run_packed_transformer(..., causal=) puts packed_block_mask(...) on the PackedSeqParams.
  • The latent transformer: latent() puts latent_block_mask(...) on the attention mask tensor, which Megatron passes through its layers. latent_block_mask now returns the BlockMask itself.

build_transformer loses its attention argument ("arbitrary" / "causal" / "bidirectional"): every transformer gets the same attention.

Shift blocks in the processor

welt/attention.py held only get_shift_blocks, so it moves into welt/processor.py, its main user. Its warnings are shorter. Its tests move from tests/test_attention.py to tests/test_processor.py.

Verification

7 files changed, +82 / −138.

🤖 Generated with Claude Code

https://claude.ai/code/session_015Xm62qoeaTunFSU5GYCQ1f


Note

Medium Risk
Attention wiring and mask lifecycle changed across all transformers; behavior is covered by SDPA/oracle tests and reported bit-identical training, but this is core model forward path.

Overview
Unifies Megatron core attention behind a single FlexCoreAttention that handles both packed (THD) and batched (S,B) layouts. Callers attach the FlexAttention BlockMask once per forward—packed_block_mask on PackedSeqParams (with explicit causal in run_packed_transformer) or latent_block_mask on the attention-mask tensor—instead of PackedAttention / MaskedAttention building or caching masks inside every layer. build_transformer drops its attention mode switch; latent_block_mask returns a BlockMask directly (no _welt_block_mask carrier).

Moves shift-block parsing from deleted welt/attention.py into welt/processor.py (get_shift_blocks, shorter warning text); tests move from tests/test_attention.py to tests/test_processor.py, and inference imports follow.

Reviewed by Cursor Bugbot for commit a75f2f7. Bugbot is set up for automated code reviews on this repo. Configure here.

… shift blocks in the processor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Xm62qoeaTunFSU5GYCQ1f
@AmitMY
AmitMY force-pushed the simplify/one-attention branch from 6ca3813 to a75f2f7 Compare October 11, 2026 09:40
@AmitMY
AmitMY changed the base branch from test/labels-mask-oracle to main October 11, 2026 09:40
@AmitMY
AmitMY merged commit fdbc698 into main Oct 11, 2026
1 check passed
@AmitMY
AmitMY deleted the simplify/one-attention branch October 13, 2026 06:45
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