Repository navigation
One FlexAttention core attention; shift blocks in the processor - #84
Merged
Merged
Conversation
AmitMY
force-pushed
the
test/labels-mask-oracle
branch
from
October 11, 2026 09:40
d522c92 to
8aa3598
Compare
… shift blocks in the processor Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015Xm62qoeaTunFSU5GYCQ1f
AmitMY
force-pushed
the
simplify/one-attention
branch
from
October 11, 2026 09:40
6ca3813 to
a75f2f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #83.
One FlexAttention core attention
WeLT had two core attention classes:
PackedAttentionfor packed short sequences (the encoders and the bytes decoder), andMaskedAttentionfor 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:run_packed_transformer(..., causal=)putspacked_block_mask(...)on thePackedSeqParams.latent()putslatent_block_mask(...)on the attention mask tensor, which Megatron passes through its layers.latent_block_masknow returns theBlockMaskitself.build_transformerloses itsattentionargument ("arbitrary"/"causal"/"bidirectional"): every transformer gets the same attention.Shift blocks in the processor
welt/attention.pyheld onlyget_shift_blocks, so it moves intowelt/processor.py, its main user. Its warnings are shorter. Its tests move fromtests/test_attention.pytotests/test_processor.py.Verification
Full suite: 96 passed, 1 skipped, including the packed and latent attention tests against SDPA, Tests: labels and the latent mask against oracles of the words #83's oracles, and vLLM matching Megatron.
Same training, bit for bit: machine translation (10,000 steps, seed 42) on this stack plus utf8-tokenizer's special token ids instead of copies; AutoConfig directly; FLOPs on collated batches #85 matches Experiment: labels and the latent mask from the words, in the model #82's runs exactly:
Generation differs slightly with the same weights: vLLM's batched generation is not bit-deterministic. Experiment: labels and the latent mask from the words, in the model #82's two runs, also with identical weights, gave chrF 45.8 and 45.9.
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
FlexCoreAttentionthat handles both packed (THD) and batched (S,B) layouts. Callers attach the FlexAttentionBlockMaskonce per forward—packed_block_maskonPackedSeqParams(with explicitcausalinrun_packed_transformer) orlatent_block_maskon the attention-mask tensor—instead ofPackedAttention/MaskedAttentionbuilding or caching masks inside every layer.build_transformerdrops itsattentionmode switch;latent_block_maskreturns aBlockMaskdirectly (no_welt_block_maskcarrier).Moves shift-block parsing from deleted
welt/attention.pyintowelt/processor.py(get_shift_blocks, shorter warning text); tests move fromtests/test_attention.pytotests/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.