Repository navigation
ZUNA: registers option (False = encoder on the patch tokens only) - #1468
Merged
bruAristimunha merged 2 commits intoOct 19, 2026
Merged
bruAristimunha merged 2 commits into
bruAristimunha merged 2 commits into
Conversation
bruAristimunha
added a commit
to bruAristimunha/braindecode
that referenced
this pull request
Oct 18, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1468 +/- ##
=======================================
Coverage 91.01% 91.02%
=======================================
Files 167 167
Lines 21621 21629 +8
=======================================
+ Hits 19679 19687 +8
Misses 1942 1942 🚀 New features to boost your workflow:
|
registers=True (default) is the published ZUNA1.1 encoder, unchanged. registers=False drops the learned register before each patch: half the tokens, each patch keeps its rotary position, and the head reads the patch outputs. The parameters are the same, so pretrained weights load unchanged; the register parameter is then unused and does not require gradients.
bruAristimunha
force-pushed
the
feat/zuna-registers-option
branch
from
October 18, 2026 12:25
33a46bc to
99fcaea
Compare
bruAristimunha
commented
Oct 18, 2026
bruAristimunha
left a comment
Collaborator
Author
There was a problem hiding this comment.
Rebased on master (changelog conflict only). ZUNA with the default registers=True re-characterized against master: identical keys, weights and outputs. Queued.
bruAristimunha
added a commit
that referenced
this pull request
Oct 19, 2026
* ZUNA: registers option (False = the encoder on the patch tokens alone) registers=True (default) is the published ZUNA1.1 encoder, unchanged. registers=False drops the learned register before each patch: half the tokens, each patch keeps its rotary position, and the head reads the patch outputs. The parameters are the same, so pretrained weights load unchanged; the register parameter is then unused and does not require gradients. * DOC whats_new: ZUNA registers option (#1468) * ZUNA: rotary embedding through Gaudi's fused RoPE kernel on HPU On HPU, _RotaryPositionEmbedding runs the bridge's pairwise RoPE kernel (hpex.kernels.apply_rotary_pos_emb, PAIRWISE) as a custom op instead of the flip/cast/multiply formula: same float32 arithmetic and identical outputs; the kernel has no gradient, so the backward is the kernel at the opposite angle (gradients rounded to the input dtype once instead of per term). A custom op stays one node inside torch.compile. CPU and other devices unchanged. * DOC whats_new: ZUNA fused rotary on HPU (#1461) * ZUNA: fused rotary in HPU eager mode and compiled regions only, not lazy In lazy mode the graph compiler fuses the formula itself and the kernel made the Gaudi2 train step slower (2.47 -> 2.86 s at 21 channels x 1280 samples, batch 64): _hpu_fused_rotary returns None there and the formula runs. * DOC whats_new: ZUNA fused rotary is eager/compiled only
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.
Adds
registers: bool = Truetobraindecode.models.ZUNA.registers=True(default): the published ZUNA1.1 encoder. The forward code, buffers and outputs don't change (the only addition on this path is theifon the flag).registers=False: the encoder runs on the patch tokens only. The learned register before each patch is dropped, so the sequence has half as many tokens. Each patch keeps its rotary position (the patch rows of the default tables,rotary_cosine[1::2]), and the head reads the patch outputs instead of the register outputs.registers=Falsethe register parameter is still loaded but not used, and it hasrequires_grad=False, so DDP doesn't flag it as unused.This changes the model, so it is not the published encoder, and the docstring says so. It's the efficient fine-tuning variant we use for ZUNA fine-tuning in the NeuralBench paper campaign. On one Gaudi2 card at batch 64 with the full 16 blocks and full fine-tuning, the train step is about 3.5-4x faster than with registers (TUAB 21 ch x 1280 samples). We measured accuracy against the full model on several studies over 3 seeds; those results will be reported in the paper.
Tests (
test_foundation_models.py):registers=True);registers=Falseuses the patch rows of the rotary tables, and its output matches the encoder applied by hand to the patch tokens;Voyager CPU Job:
test_{foundation_models,models,integration,return_features}.py -k "zuna and not compiled": 28 passed, 2 skipped. pre-commit is clean.Relation to #1461 (fused rotary on HPU): this branch starts from master and doesn't depend on #1461. The two merge cleanly in either order (checked with
git merge-tree). With both merged,registers=Falseuses the fused rotary kernel as well, because the kernel reads the same per-token buffers.