Repository navigation
iEEG foundation models: return the per-token output, padded channels zeroed - #1540
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1540 +/- ##
==========================================
+ Coverage 91.38% 91.39% +0.01%
==========================================
Files 170 170
Lines 22137 22155 +18
==========================================
+ Hits 20229 20249 +20
+ Misses 1908 1906 -2 🚀 New features to boost your workflow:
|
bruAristimunha
left a comment
There was a problem hiding this comment.
The change is small and well tested: each recording's tokens match it run alone, padded tokens are zero, and the scripted paths are covered. I checked the reshapes:
- the BaRISTA patch-major unflatten;
- the MVPFormer
(batch, segment, channel, d)transpose; - the Brant
emblayout; - the BrainBERT unpack-then-crop, which gives the same pooled value as before.
P2: one layout for tokens
PopulationTransformer returns (batch, n_chans, hidden), while the six others return (batch, n_chans, n_tokens, dim). A probe written once for all models has to special-case PopT. tokens.unsqueeze(2) (one token per channel) keeps the contract uniform.
P2: the contract should cover REVE and Labram too
On the alternative you mention: keeping "features" as the pooled embedding and adding "tokens" is the better choice. REVE and Labram currently return token-level "features", and changing that right after 2.0 would be breaking. Instead, REVE and Labram (#1539) can also return "tokens" in the same (batch, n_chans, n_patches, dim) layout, with padded tokens zeroed. Then "tokens" means the same thing in every foundation model, and "features" can converge later with a deprecation.
P3
- BrainBERT now unpacks every frame before cropping to
pool_n_frames, so the zero padding is allocated for all frames. That's fine; just noting it is intentional. - Codacy reports 1 new minor issue. It is probably one of the long
return {...} # nosec B105lines; wrapping the dict over several lines clears it.
|
Thanks!
|
|
Thanks for the updates, they address the review. Two things before merging:
|
|
Merged master: took its |
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.
return_features=Truealso returns"tokens", the per-token encoder output before pooling,(batch, n_chans, n_tokens, dim)(PopT: one token per channel), with the tokens of padded channels (ch_mask) exactly zero, for the iEEG foundation models of #1487 (BrainBERT, EpiNT, Brant, PopulationTransformer, BaRISTA, DIVER1, MVPFormer). Register and class tokens are left out of"tokens". DIVER1 gainsreturn_features.This lets a downstream probe pool or attend over the tokens of real channels only, by skipping all-zero tokens, without the mask.
pack_channels), sounpack_channelsalready returns zeros for the padded ones; Brant, PopT, BaRISTA, DIVER1 and MVPFormer attend across the padded grid, so their padded tokens are zeroed explicitly."features"stays the pooled embedding: returning the tokens there instead, as REVE and Labram do, would change it right after 2.0. REVE and Labram also return"tokens", same layout, in REVE, Labram: accept ch_mask #1539.Testing
test_ch_mask_tokens_match_each_recording_alone(fails without the change): each recording's tokens match it alone, padded tokens are zero, scripted wherereturn_featuresis honoured (DIVER1, MVPFormer);pytest test/unit_tests/models/test_ch_mask.py: 33 passedpytest test/unit_tests/models -k "<the seven models>": 409 passed, 16 skippedpre-commit run --files <changed files>: passed