Skip to content

CSBrain: add head_drop_prob; document checkpoint key names - #1247

Merged
bruAristimunha merged 2 commits into
braindecode:masterfrom
bruAristimunha:w41/csbrain-missing
Oct 7, 2026
Merged

bruAristimunha merged 2 commits into
braindecode:masterfrom
bruAristimunha:w41/csbrain-missing

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #1196 and #1240.

  • head_drop_prob (default None = drop_prob): dropout of the task head only. The reference fine-tuning model for BCIC-IV-2a (models/model_for_bciciv2a.py) uses 0.1 in the backbone and --dropout 0.3 in the head; this is now CSBrain(drop_prob=0.1, head_drop_prob=0.3). The docstring note about a subclass workaround is removed.
  • proj_out → nn.Identity() (also in that recipe) is documented as model.proj_out = nn.Identity() after loading the weights; no new argument.
  • Notes: the key renames needed to load the released checkpoints (encoder.layers. → encoder., TemEmbedEEGLayer. → temporal_embed., BrainEmbedEEGLayer. → region_embed., linear1/linear2 → ff_block.0/ff_block.3, strict=False), as asked in Add CSBrain cross-scale spatiotemporal brain foundation model #1196.

Parity vs master f8699847, default arguments, torch.manual_seed(42), CPU fp32, 3 configs (22-ch 2a layout 12 layers; 4 ch no names 2 layers; 5 ch drop_prob=0.3 2 layers):

2a no names drop 0.3
state-dict keys + shapes equal yes (308) yes (71) yes (71)
same-seed init max-abs 0.0 0.0 0.0
eval output max-abs 0.0 0.0 0.0
train output (same seed) max-abs 0.0 0.0 0.0
gradients max-abs 0.0 0.0 0.0

Tests (-k "csbrain and not compiled"): test_models 27 passed, 1 skipped; test_integration 10 passed, 1 skipped; test_return_features 2 passed. New: test_csbrain_head_drop_prob_sets_only_the_head. pre-commit rc=0 twice.

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.62%. Comparing base (f869984) to head (4215bf7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1247   +/-   ##
=======================================
  Coverage   88.62%   88.62%           
=======================================
  Files         159      159           
  Lines       19547    19547           
=======================================
  Hits        17324    17324           
  Misses       2223     2223           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bruAristimunha
bruAristimunha marked this pull request as ready for review October 7, 2026 20:10
Copilot AI balanced review requested due to automatic review settings October 7, 2026 20:10
@bruAristimunha
bruAristimunha merged commit dd103b8 into braindecode:master Oct 7, 2026
14 of 15 checks passed

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.

🟡 Changes recommended

The constructor breaks existing positional calls, and the regression test can miss incorrectly configured dropout layers.

2 open findings
What changed in this PR

Extends CSBrain’s fine-tuning support with independent task-head dropout and checkpoint-loading guidance.

Changes:

  • Adds head_drop_prob, defaulting to drop_prob.
  • Documents checkpoint key remapping and replacing proj_out.
  • Adds a dropout regression test and release note.
File Description
test/​unit_tests/​models/​test_models.py Tests separate head and backbone dropout settings.
docs/​whats_new.rst Announces the option and checkpoint documentation.
braindecode/​models/​csbrain.py Implements head dropout control and documents loading guidance.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

emb_dim: int = 200,
temporal_kernel_sizes: Sequence[int] = (1, 3, 5),
drop_prob: float = 0.1,
head_drop_prob: float | None = None,
Comment on lines +5142 to +5147
ps = {
name.startswith("final_layer"): m.p
for name, m in model.named_modules()
if isinstance(m, nn.Dropout)
}
assert ps == {False: 0.1, True: 0.3}
bruAristimunha added a commit to bruAristimunha/braindecode that referenced this pull request Oct 8, 2026
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