Repository navigation
LUNA: accept ch_mask - #1543
Merged
Merged
LUNA: accept ch_mask#1543
Conversation
Padded channels are zero-filled, never attended to (key mask before the key softmax of the linear attention) and not pooled (masked_mean).
Masked GroupNorm in the patch embedding, location range over real channels, key padding mask in the channel cross-attention. A class-level annotation lets LUNA script with an empty location cache.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
In reconstruction mode, the channel padding mask never reaches the decoder, allowing padded-channel queries to affect real-channel reconstructions even during evaluation.
1 open issue
What changed in this PR
Adds channel-mask support to LUNA so batches can contain recordings with different channel counts, extending the foundation models’ padded-channel handling.
Changes:
- Excludes padded channels from patch-embedding normalization, location normalization, and channel cross-attention.
- Adds a cache type annotation for scripting before an eager forward.
- Extends shared channel-mask tests to LUNA and documents the enhancement.
| File | Description |
|---|---|
| test/unit_tests/models/test_ch_mask.py | Adds LUNA with per-recording channel locations to shared mask tests. |
| docs/whats_new.rst | Documents LUNA channel-mask support and scripting improvement. |
| braindecode/models/luna.py | Threads channel masks through normalization and attention; types the location cache. |
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1543 +/- ##
==========================================
+ Coverage 91.39% 91.46% +0.06%
==========================================
Files 170 170
Lines 22155 22226 +71
==========================================
+ Hits 20249 20329 +80
+ Misses 1906 1897 -9 🚀 New features to boost your workflow:
|
This was referenced Nov 5, 2026
…-mask # Conflicts: # test/unit_tests/models/test_ch_mask.py
…fail (no ch_names routing)
…a local position bank
bruAristimunha
added a commit
to bruAristimunha/braindecode
that referenced
this pull request
Nov 9, 2026
Brings in the ch_mask series (braindecode#1545 braindecode#1548 braindecode#1540 braindecode#1549 braindecode#1542 braindecode#1543 braindecode#1544 braindecode#1550), braindecode#1557 and braindecode#1559 (master dba9d42). No conflicts; NOTICE.txt and docs/whats_new.rst carry only this PR's additions over master.
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.

LUNAacceptsch_mask, so a batch can mix recordings with different channel counts. Each recording gets the output it gets when run alone, given per-recordingchannel_locations.masked_group_norm), out of the min/max normalisation of the channel locations, and out of the keys of the channel cross-attention._channel_location_cacheneeded a type annotation. The matching xfail intest_foundation_models.pynow passes.ch_mask=Nonenothing changes: outputs, gradients and scripted outputs are bit-identical to master. No parameter or state-dict key changes.Please merge after #1539 and #1540.
Testing
test_ch_mask.py: LUNA added to_CASESwith per-recordingchannel_locations, eager and scripted, with no gradient into padding.