Repository navigation
Route pad_channels_collate batches by forward signature; test the ch_mask contract in training - #1545
Merged
bruAristimunha merged 2 commits intoNov 5, 2026
Conversation
…mask contract in training
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The adapter inspects the channel-strategy wrapper instead of the backbone’s forward signature, causing extended batches with non-native channel strategies to raise KeyError when resolving the signal argument.
1 open issue
What changed in this PR
This PR routes extended dataset batches by model forward signatures, supporting different signal argument names and clearer errors for unsupported channel metadata.
Changes:
- Route signals by parameter name and validate support for
posandch_mask. - Add training, prediction, gradient, and routing tests for padded-channel batches.
- Share channel-mask test helpers and document the changes.
| File | Description |
|---|---|
test/unit_tests/training/test_ch_mask_training.py |
Adds training integration, gradient equivalence, coverage, and refusal tests. |
test/unit_tests/test_util.py |
Tests signature-based routing and unsupported-input errors. |
test/unit_tests/models/test_ch_mask.py |
Extracts reusable padded-batch and comparison helpers. |
docs/whats_new.rst |
Documents routing fixes and channel-mask test coverage. |
braindecode/util.py |
Adds signature inspection and extended-batch keyword routing. |
Review effort: Balanced
Comment on lines
+425
to
+426
| if self._forward_params is None: | ||
| self._forward_params = inspect.signature(module.forward).parameters |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1545 +/- ##
=======================================
Coverage 91.37% 91.38%
=======================================
Files 170 170
Lines 22123 22137 +14
=======================================
+ Hits 20214 20229 +15
+ Misses 1909 1908 -1 🚀 New features to boost your workflow:
|
This was referenced Nov 5, 2026
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#1542-braindecode#1544, braindecode#1549, braindecode#1550) and braindecode#1557/braindecode#1559. No conflicts.
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.

Bug
ThrowAwayIndexLoaderturned every batch frompad_channels_collate/set_return_ch_posinto{"x": X, "pos": ..., "ch_mask": ...}, and skorch callsmodule_(**x). Training failed with aTypeErrorwhen:x(REVE.forward(eeg, pos),LUNA.forward(X, ...));return_ch_pos=Trueis used with a model that does not takepos;ch_maskreaches a model without it (e.g.ShallowFBCSPNet, orSleepFM, whosechannel_maskuses the opposite polarity).Fix
The loader reads the module's
forwardsignature once per iteration:posandch_maskare passed only under those names, and only to aforwardthat takes them (or takes**kwargs);ValueError, e.g.ShallowFBCSPNet.forward takes no ch_mask: this model needs a constant channel count; do not use pad_channels_collate.It adds no name mapping to
coords,channel_locations,spatial_indicesorchan_metadata, because those mean different things.Tests
test/unit_tests/training/test_ch_mask_training.pyis parametrised over_CASESfromtest_ch_mask.py, so new cases are covered automatically:EEGClassifieris fit withpad_channels_collateon two recordings withn_chans - 1andn_chanschannels. A forward spy checks the per-sample real-channel counts inch_mask.predict_probaon the mixed set must equalpredict_probaof each recording alone. Cases with aposinput get their positions throughset_return_ch_pos.xfail(strict=True, raises=ValueError): they need per-recordingcoords/spatial_indices/chan_metadata, which the loader does not route.braindecode.modelswhoseforwardtakesch_maskmust appear in_CASESor_FIXED_HEADS.ShallowFBCSPNetfit withpad_channels_collateraises the routingValueError.test_util.py: the signal goes undereegandX,**kwargsaccepts everything, and both error messages are checked.test_ch_mask.pymoves its batch building into_padded_batch/_padded_case/_assert_matches_alone. These are the same helpers, under the same names, as in #1539, so that PR merges without a conflict there.Verification (Voyager CPU Job, torch 2.14.1, skorch 1.4.0)
test_ch_mask.py,test_util.py,test_eegneuralnet.pyandtest/unit_tests/traininggive 498 passed, 3 xfailed, 1 skipped (CUDA).plot_heterogeneous_montage_training.pyruns.pre-commit run --files <changed>passes.TypeError.ch_maskPR, merged locally with this branch, passes the new training tests (--run-networkfor REVE):_FIXED_HEADSentry);channel_locations);_FIXED_HEADS).