Repository navigation
Experiment: labels and the latent mask from the words, in the model - #82
Merged
Merged
Conversation
AmitMY
marked this pull request as ready for review
October 10, 2026 13:29
This was referenced Oct 10, 2026
AmitMY
force-pushed
the
simplify/baseline-offsets
branch
from
October 11, 2026 09:40
1732f47 to
4ab190b
Compare
Examples carry each word's bytes, its sequence and shift block ids, and whether it predicts the next word. The model derives the labels (the next word's bytes, already tokenized as an input) and the latent transformer's FlexAttention block mask from them, instead of the processor tokenizing every word twice and building a dense words x words mask. On real packed examples, the labels, label positions and masks are identical to before, and examples are half the size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015Xm62qoeaTunFSU5GYCQ1f
AmitMY
force-pushed
the
experiment/labels-from-words
branch
from
October 11, 2026 09:40
1f969e6 to
b81d8c7
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 #81.
Labels and the latent mask from the words, in the model
Before, the processor tokenized every word twice (once as an input, once as the previous word's label) and built a dense words × words attention mask for every example. Now an example carries:
input_ids)sequence_ids,block_ids)label_mask: not PAD words, nor the words of a shift block before its ShiftIn)From these the model derives:
next_word_labels, the next word's bytes in the same sequence, or an empty word after the last word of a sequencelatent_block_mask, causal within a sequence and bidirectional within a shift blockRemoved: the second tokenization,
get_sequence_labels, the PAD-label loop,get_attention_mask_for_packed_sequence, and theinput_attention_mask,attention_maskandlabels_*batch keys.Verification so far
benchmarks/flops.pycounts the same FLOPs per step (3.078 / 2.504 TFLOPs), so the decoder sees the same label lengths.Training A/B
Machine translation, 10,000 steps, each run twice with the same seed, against the same stack without this change:
9 files changed, +140 / −163.
🤖 Generated with Claude Code
https://claude.ai/code/session_015Xm62qoeaTunFSU5GYCQ1f
Note
Medium Risk
Changes the training/inference batch schema and core forward path (labeling + latent attention), though tests and A/B runs report equivalent behavior.
Overview
Processor batches are slimmer: examples now emit word bytes (
input_ids), packed sequence / shift-block ids (sequence_ids,block_ids), andlabel_mask(who predicts the next word). The old second tokenization pass, denseL×Lattention_mask, andlabels_*/input_attention_maskkeys are gone.The model owns derivation:
next_word_labelsbuilds decoder targets from those fields;latent_block_maskbuilds the latent transformer’s FlexAttention mask (causal per sequence, bidirectional inside shift blocks).WeLTModel.forward,encode_words, andlatenttake the new tensors;MaskedAttentionexpects a pre-built block mask carrier instead of materializing from a dense mask.Benchmarks/tests follow the new contract (
benchmarks/flops.pyusesnext_word_labelsfor decoder token counts; attention tests focus onget_shift_blocksonly).Reviewed by Cursor Bugbot for commit b81d8c7. Bugbot is set up for automated code reviews on this repo. Configure here.