Skip to content

reset_parameters for every model; all-models initialization test - #1452

Merged
bruAristimunha merged 2 commits into
braindecode:masterfrom
bruAristimunha:cleanup/t16-reset-parameters
Oct 17, 2026
Merged

bruAristimunha merged 2 commits into
braindecode:masterfrom
bruAristimunha:cleanup/t16-reset-parameters

Conversation

@bruAristimunha

Copy link
Copy Markdown
Collaborator

Part of #1442.

EEGModuleMixin.reset_parameters() draws new initial weights with the model's own scheme: every layer and block is reset (reset_parameters / _reset_parameters, children first), then the model's _init_parameters() runs. Each model's initialization now lives in _init_parameters() (the constructor and the reset both call it) or, for blocks that initialize as they are built (ATCNet, AXON, BENDR, EEGPT, MAPA, MEDFormer, SignalJEPA, STEEGFormer, the PBT encoder), in that block's reset_parameters.

test_model_init.py, over all 85 registered models:

  • seeded construction is reproducible and finite;
  • after reset_parameters() every parameter has the constructor's distribution (std within ±15 %; constant tensors such as zero biases stay constant);
  • a model's own _init_parameters() is not a no-op.

Before the per-model hooks, 37 models drew other weights on reset (lost zero biases, PyTorch defaults instead of Xavier/truncated normal, …); all pass now (168).

Construction unchanged: all 85 models built with the same seed on master and here have bit-identical initial weights (10,480 tensors). init_weights_ now skips lazy layers, as PyTorch's own reset does (CBraMod's lazy head).

PBT: its encoder's GPT-2 proj.weight scaling is overwritten by PBT's own init, exactly as in the reference implementation (src/model.py: the encoder scales, then PBT.__init__ applies _init_weights to every Linear). It is kept and documented, because dropping the draw would change PBT's weights.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bruAristimunha
bruAristimunha merged commit 599b9d5 into braindecode:master Oct 17, 2026
9 checks passed
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.04%. Comparing base (e3d1604) to head (0e6221f).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1452      +/-   ##
==========================================
+ Coverage   91.00%   91.04%   +0.03%     
==========================================
  Files         165      165              
  Lines       21562    21655      +93     
==========================================
+ Hits        19622    19715      +93     
  Misses       1940     1940              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

bruAristimunha added a commit that referenced this pull request Nov 2, 2026
#1515)

#1452 renamed the public LUNA.initialize_weights() to the private
_init_parameters() without a deprecation or a whats_new entry, so 1.8.1
code calling it raises AttributeError in 2.0. Restore it as an alias that
emits a DeprecationWarning pointing to reset_parameters().
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