Repository navigation
BIOT: accept ch_mask - #1542
BIOT: accept ch_mask#1542
Conversation
Padded channels are zero-filled, never attended to (key mask before the key softmax of the linear attention) and not pooled (masked_mean).
There was a problem hiding this comment.
🟡 Changes recommended
BIOT’s missing tokens output will break the parametrized test after the required merge, while non-native channel adaptation leaves masks misaligned and can spread NaN padding into real channels.
2 open issues
What changed in this PR
This PR adds channel-mask support to BIOT, extending the foundation models’ support for batching recordings with different channel counts while preserving the unmasked execution path.
Changes:
- Passes optional masks through linear attention to exclude padded keys.
- Clears padded BIOT inputs before spectral processing and excludes padded tokens from pooling.
- Adds BIOT to shared channel-mask regression tests and documents the enhancement.
| File | Description |
|---|---|
test/unit_tests/models/test_ch_mask.py |
Adds BIOT to shared masking tests. |
docs/whats_new.rst |
Announces BIOT channel-mask support. |
braindecode/modules/linear_attention.py |
Adds optional attention key masking. |
braindecode/models/biot.py |
Accepts channel masks and applies masked attention and pooling. |
Review effort: Balanced
| ``(out, emb)`` tuple (ignored when ``return_features=True``). | ||
| """ | ||
| emb = self.encoder(x) | ||
| emb = self.encoder(x, ch_mask=check_ch_mask(ch_mask, x)) |
There was a problem hiding this comment.
Right, and this applies to every model, not just BIOT: the channel layer in EEGModuleMixin._channel_forward mixes every input channel, padded ones included, into each target channel. Fixed once there (bbd1a76): any model built with a non-native channel_strategy now raises ValueError("ch_mask needs channel_strategy='native' ..."). Test: test_ch_mask_is_refused_under_a_channel_strategy.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1542 +/- ##
=======================================
Coverage 91.39% 91.40%
=======================================
Files 170 170
Lines 22155 22204 +49
=======================================
+ Hits 20249 20295 +46
- Misses 1906 1909 +3 🚀 New features to boost your workflow:
|
…-mask # Conflicts: # test/unit_tests/models/test_ch_mask.py
…fail (no ch_names routing)
…a local position bank
Brings in the ch_mask series (braindecode#1545, braindecode#1548, braindecode#1540, braindecode#1542-braindecode#1544, braindecode#1549, braindecode#1550) and braindecode#1557/braindecode#1559. No conflicts.
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.


BIOTacceptsch_mask, the(batch, n_chans)mask of real channels that the iEEG foundation models of #1487 take. A batch can then mix recordings with different channel counts, and each recording gets the output it gets when run alone.LinearAttentionTransformer(braindecode/modules/linear_attention.py) takes an optional key mask: padded keys are left out of the key softmax. TFMTokenizer, which shares the module, passes nothing and is unchanged.masked_mean.ch_mask=Nonenothing changes: in a Voyager job, 1,157 of 1,157 tensors weretorch.equalbetween master and this change. That covered BIOT, LUNA, CBraMod, CSBrain and TFMTokenizer (outputs, input and parameter gradients, scripted outputs). No parameter or state-dict key changes, so the Hub weights load as before.Part of making
ch_maskwork for the foundation models where masking can be exact (BIOT, LUNA and CBraMod first). Please merge after #1539 and #1540, which settle the refusal message and thetokensoutput.Testing
test_ch_mask.py: BIOT added to_CASES(each recording matches it alone, eager and scripted; no gradient into padding). Together with the LUNA and CBraMod PRs: 29 passed.