Skip to content

[models] Add Guetschel2026 - #1260

Merged
PierreGtch merged 31 commits into
masterfrom
add-guetschel2026
Oct 10, 2026
Merged

PierreGtch merged 31 commits into
masterfrom
add-guetschel2026

Conversation

@PierreGtch

@PierreGtch PierreGtch commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Adds Guetschel2026, the encoder shared by the 58 MAE/JEPA checkpoints of
What masking geometry works best for EEG foundation models?.
The checkpoints load with from_pretrained directly from the original Hugging Face
repositories (PierreGtch/eeg-fm-masking_*); hub_repo_id() builds their names.

  • Adapted from PierreGtch/eeg-fm-masking (MIT).
  • Optional fixed Gaussian random projection in the head (random_projection=5000, off by default), as in the OpenEEGBench ridge probe.
  • The shared model-test fixtures now use real channel names and positions from an MNE montage (separate commit); no test outcome changes in test/unit_tests/models.

Parity with the reference implementation. With the same released weights, the backbone features of braindecode and of the original ContextualEncoderBenchmarkWrapper are identical (torch.equal) in all 3722 comparisons: 4 checkpoints (final and epochs 1, 5, 9), 7 montages, windows of 200 to 12000 samples, float32 and float64. In CI, test_guetschel2026.py checks golden values computed with the original code.

Encoder shared by the 58 MAE/JEPA checkpoints of the EEG masking-geometry
study (Guetschel et al., 2026, arXiv:2609.33487), adapted from
PierreGtch/eeg-fm-masking (MIT). The module tree keeps the original
attribute names, so the released Hugging Face repositories load directly
with from_pretrained. Optional Gaussian random-projection head
(random_projection, random_projection_seed) and hub_repo_id helper.
The default 3-channel chs_info, the DANCE entry and the chs_info generated
by _get_signal_params used uniform random locs in [0, 1)^3. They now use
real channel names and head-frame positions (metres) from colin27_1005
(standard_1005 on MNE < 1.13), loaded lazily. The module-level _rng stream
is consumed as before.
…Figure 1

Every channel must lie between 5 cm and 20 cm from the head-frame origin,
which rejects positions in centimetres or millimetres and channels without
a position. The figure now shows both panels of Figure 1 of the paper.
Short sections in the style of REVE: architecture, the 58 checkpoints,
usage, random projection head, input requirements and differences from
the reference implementation.
@PierreGtch
PierreGtch requested review from bruAristimunha and a balanced review from Copilot October 8, 2026 22:20

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.

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.76%. Comparing base (b378bb1) to head (7332e45).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1260      +/-   ##
==========================================
+ Coverage   89.64%   89.76%   +0.12%     
==========================================
  Files         163      164       +1     
  Lines       20346    20584     +238     
==========================================
+ Hits        18239    18478     +239     
+ Misses       2107     2106       -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…dit false positives

The frequencies of the coordinate encoding are computed once into a
non-persistent buffer, so a float64 forward has no float32 tensor
(test_forward_in_dtype); a float32 to float64 cast is exact, so the features
stay bit-identical to the reference. nosec on the cls_token=None return
(B105) and on the subprocess of the fixture import test (B404, B603).
The channel-strategy guide now counts 24 pretrained EEG models.
Copilot AI balanced review requested due to automatic review settings October 9, 2026 07:29

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.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 10:12

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.

… errors

- Inline the one-use private constants (_PRETRAIN_SFREQ, _MAX_SECONDS,
  _SCALE_EPS, _N_STORED_TIME_PATCHES, _HUB_NAMESPACE, _MIN/_MAX_CH_DIST,
  _MAX_LISTED_CHANNELS) with their one-line reason; keep the data tables.
- Fold _check_channel_distances (one caller) into __init__ and shorten its
  error and the missing-location error; the tests follow the new wording.
- Call warn_if_sfreq_differs without the try/except around the mixin's
  sfreq; it warns in the same cases (sfreq given or derivable).
- Docstring: License link line. NOTICE: the file line only.
- channel_strategies.rst: no model count (it goes stale with every port).

Forward outputs, gradients and state_dict keys are bit-identical to 94c1598.
Copilot AI balanced review requested due to automatic review settings October 9, 2026 11:47

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 default projection can consume gigabytes of memory, and two validation/test dependency issues remain.

3 open findings

🧠 Review effort: Balanced

Comment thread braindecode/models/guetschel2026.py Resolved
Comment thread braindecode/models/guetschel2026.py Resolved
Copilot AI balanced review requested due to automatic review settings October 9, 2026 11:53

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.

🔵 Needs a closer look

Constructor validation and excessive memory use in generic contract tests remain unresolved.

1 open finding
2 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Validate num_heads before division

braindecode/​models/​guetschel2026.py:458

Validate num_heads before using it as a divisor. With num_heads=0, this public constructor currently raises ZeroDivisionError at the modulo operation, and negative or non-integral values fail later with opaque tensor-shape errors instead of the ValueError used for other invalid architecture arguments.

Medium severity Use lightweight projection in registry contract tests

braindecode/​models/​util.py:796

This registry entry exercises the 5000-dimensional default head in every generic model-contract test. With the default registry geometry (3 channels, 5 patches), each instance owns a 38.4M-element (~154 MB) projection buffer; test_registered_model_serialization_contract then retains the original, reconstructed, deep-copied, and pickled models simultaneously, so this single case consumes well over 800 MB before pickle's temporary bytes. Provide a lightweight projection override for registry-driven tests, as the dedicated return-feature and pretrained-compat cases already do, while retaining the explicit default-head test.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 9, 2026 12:03

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.

🔵 Needs a closer look

The substantial new architecture and external-checkpoint compatibility warrant final human validation despite strong test coverage.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:37

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

Explicit non-head coordinate frames can pass validation and silently produce incorrect spatial encodings.

1 open finding

🧠 Review effort: Balanced

Comment thread braindecode/models/guetschel2026.py Resolved
Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:54

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.

🔵 Needs a closer look

The new pretrained architecture and external checkpoint parity warrant final human verification despite extensive tests.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:59

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.

🔵 Needs a closer look

The float64 spatial encoding does not preserve the claimed bitwise parity with the reference implementation.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Medium severity Spatial encoding uses float64, breaking reference bitwise parity

braindecode/​models/​guetschel2026.py:48

After model.double(), ch_pos is converted to float64, so new_empty makes the spatial encoding float64. The copied reference implementation in test_guetschel2026.py:330-339 always allocates this result as float32, then quantizes the sine/cosine values before they are added to a float64 residual. Consequently the float64 path is not bit-identical to the reference despite the PR's parity claim (the current test only checks it within 1e-3). Keep this helper's output float32 and let _ContextualEncoder cast it when adding it to the features.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 10, 2026 08:43

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.

🔵 Needs a closer look

Pretrained-checkpoint compatibility and numerical parity across this substantial model implementation warrant final human validation.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 10, 2026 10:00

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

Checkpoint loading can silently discard unexpected pretrained backbone layers when using a truncated architecture.

1 open finding

🧠 Review effort: Balanced

Comment thread braindecode/models/guetschel2026.py Resolved
Copilot AI balanced review requested due to automatic review settings October 10, 2026 10:09

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.

🔵 Needs a closer look

The large numerical-parity-sensitive model and external checkpoint integration warrant final human validation despite extensive tests.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@PierreGtch
PierreGtch merged commit 8a2c4a8 into master Oct 10, 2026
17 checks passed
@bruAristimunha
bruAristimunha deleted the add-guetschel2026 branch October 14, 2026 15:55
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.

3 participants