Repository navigation
FIX AttentionBaseNet: size fca and ge attention for even temporal kernels - #1867
Merged
bruAristimunha merged 3 commits intoDec 1, 2026
Merged
Conversation
…nels FCA and GatherExcite(extra_params=True) were sized with the length before the attention block's convolution, which returns one more step when temp_filter_length is even, including the kernels shrunk for n_times below 180.
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.
Summary
AttentionBaseNetwithattention_mode="fca", or"ge"withextra_params=True, fails inforwardwhenever the attention block's temporal kernel is even:With the default parameters this also happens for short windows: below
n_times=180the model shrinkstemp_filter_length, often to an even value (10 atn_times125 and 128), so 84 of the lengths 1 to 180 fail,"se"none.Cause:
FCAandGatherExcite(extra_params=True)are sized withseq_lengths[0], the length at the input of the block's convolution. That convolution pads byk // 2and returnsn + 1 - k % 2steps, one more whenkis even.Changes
braindecode/models/attentionbasenet.py: passseq_lengths[0] + 1 - temp_filter_length % 2asseq_len.test/unit_tests/models/test_models.py:test_attentionbasenet_even_attention_kernel, for"fca"and"ge"withextra_params=True, withtemp_filter_length=16, and withn_times=128(kernel shrunk from 15 to 10).docs/whats_new.rst: entry under Bug fixes.Testing
All runs with
-p no:cacheprovider -n 2 -q -rfEs, on master (92cb203) and on this branch.pytest test/unit_tests/models/ --select-models=AttentionBaseNet -k "AttentionBaseNet or completeness or summary_csv or categorization"pytest test/unit_tests/models/test_model_contract.py --select-models=AttentionBaseNet -k AttentionBaseNetpytest test/unit_tests/models/test_pretrained_compat.py --select-models=AttentionBaseNet -k "AttentionBaseNet or covers_every or no_strategy"pytest test/unit_tests/models/test_models.py -k attentionbasenet(no own test file)pytest --select-models=AttentionBaseNeton the 20 test files listed byscripts/ci_plan.py --base upstream/master --head HEADSkips printed by
-rfEs(same on both):test_config.py(pydantic or numpydantic not installed),test_integration.py:360(torch.compile skipped on Windows),test_integration.py:649(no embedding parameter),test_model_contract.py:651(forward takes no ch_mask),test_input_contract.py:142and:1147(fixed length). Theci_planfiles add: network tests (--run-network), MPS, CUDA, sphinx not installed, EEGNet**kwargsand no embedding parameter.test_config.py --select-models=AttentionBaseNet, run again with numpydantic 2.0.1 installed: 19 passed on master and here.torch 2.6.0 (the floor),
test_integration.py --select-models=AttentionBaseNet -k "AttentionBaseNet and (exported or torch_script)": 2 passed on master and here; the 4 new cases pass.The
ci_planfailures are the same on master and on this branch and come from my Windows setup: 8 pass withPYTHONUTF8=1(test_model_rules.py,test_no_new_private_blocks,test_dependencies.py: files read with the cp1252 codec), and 5test_huggingface.pysymlink tests need a privilege this account lacks (WinError 1314). The 14th on master,test_eegclip_one_empty_rank_nonempty_global_matches_ddp_oracle, passed when run again alone.pre-commit run --fileson the three changed files: all hooks pass. Not run locally: the full suite, the docs build, andtorch.compile(skipped on Windows).Mutation: restoring
seq_len=seq_lengths[0]fails the four cases of the new test.Parity, float64, seed 0,
OMP_NUM_THREADS=1, over 4446 configurations (every attention mode,n_times1 to 200,temp_filter_length1 to 20 at seven usual lengths, even and odd input kernels): the 4138 that run on master give bitwise equal outputs (eval and train), input and parameter gradients,state_dictkeys and shapes, andfrom_config(get_config())outputs; the 308 that fail on master all run. v2.0.0 checkpoints of the default,"fca","ge"withextra_params=Trueand"se"withtemp_filter_length=16models load withstrict=Trueand give bitwise equal outputs.pre-commit run --files <changed files>docs/whats_new.rstupdated (at most 3 lines), or theno changeloglabel, which a maintainer adds, for changes to code that is not released yet (the changelog CI check requires one of the two)Notes for reviewers
The attention weights change shape only for configurations whose
forwardfails on master and on v2.0.0; their v2.0.0 state dicts no longer load, as checked with a script.AttentionBaseNetis not in_V2_MODELS; I did not extend those fixtures here.