Skip to content

FIX BENDR contextualizer output to match the pretrained reference - #1498

Merged
bruAristimunha merged 1 commit into
braindecode:masterfrom
antonsoo:fix/1495-bendr-reference-norm
Nov 1, 2026
Merged

bruAristimunha merged 1 commit into
braindecode:masterfrom
antonsoo:fix/1495-bendr-reference-norm

Conversation

@antonsoo

@antonsoo antonsoo commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Address the final LayerNorm part of #1495. The original contextualizer projects the transformer outputs directly; Braindecode normalizes them first. The maintainer confirmed that difference in the issue.

Changes

Remove the extra normalization. Retain its state-dict keys so existing checkpoints load strictly, and freeze those unused parameters so training does not expect their gradients. Add an analytic regression covering all sequence positions, start-token settings and train/eval modes, plus a changelog entry.

Testing

  • Six new regression cases fail on master and pass here.

  • Affected BENDR model/channel/geometry/feature checks: 50 passed; one unchanged torch 2.7 meta-kernel failure also reproduced on master. Integration, export, TorchScript and dtype checks: 11 passed, 1 skipped.

  • pre-commit run --files braindecode/models/bendr.py test/unit_tests/models/test_bendr.py docs/whats_new.rst: passed.

  • Original release tensors, 12 recorded PhysioNet EEG windows, CPU/CUDA: public features match the original contextualizer's start-token output exactly; full sequences agree within 1.8e-8. Repeated from the built wheel. Strict trained-checkpoint/Adam loading, exact resumed training, encoder-only controls and three single-process DDP reducer steps pass.

  • New or changed behavior is covered by relevant regression tests

  • Style checks recorded

  • docs/whats_new.rst updated

Notes for reviewers

The separate Hub projection-weight mismatch remains: these numerical comparisons use the original release tensors. This changes outputs of the full contextualizer, including previously fine-tuned models. Encoder-only outputs are unchanged. No downstream accuracy claim is made.

Rebased on current master, including its separate filter TorchScript repair. The BENDR implementation and regression-test blobs are unchanged by the rebase. A newly built wheel matches all 170 tracked package files. The complete 157,142,075-parameter EEGClassifier resume on all 15 recorded PhysioNet S001R04 trials reproduces the previous five-update final model, prediction hashes and loss exactly; final gradients and all 306 Adam tensors are finite. The six focused regressions pass again.

The complete local suite and documentation build have not been rerun after this documentation-conflict repair. The new hosted run is pending; earlier hosted results describe the previous head.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-30T04:34:06.083185Z
We couldn’t complete this review. Comment @codex review to try again.
25568a8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

The reference defines a final norm but does not call it. Keep its state keys for existing checkpoints and freeze the unused parameters so default training does not acquire unused gradients.
@antonsoo
antonsoo force-pushed the fix/1495-bendr-reference-norm branch from 25568a8 to 54370fa Compare October 31, 2026 01:17
@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.20%. Comparing base (05b764d) to head (54370fa).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1498      +/-   ##
==========================================
+ Coverage   91.19%   91.20%   +0.01%     
==========================================
  Files         168      169       +1     
  Lines       21862    21915      +53     
==========================================
+ Hits        19937    19988      +51     
- Misses       1925     1927       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bruAristimunha
bruAristimunha merged commit 1e3f9ab into braindecode:master Nov 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants