Skip to content

Pretrained models compatible by default: input-geometry contract, audits of the 19 pretrained classes, stacked plan #1227

Open

Description

@bruAristimunha

Why

Twenty-one model classes load Hub weights, and each answers the same questions its own way: what is backbone vs head, what "frozen" means, which checkpoint keys may be missing/extra, how to get features, and — the part this issue is about — which input geometry the weights accept (window length, channel count/names/positions, sampling rate). Two downstream projects hit this in one quarter (#1155, #1194, #1195, OpenEEGBench's training_required_parameters).

Proposal in one line, borrowed from timm / HF / KerasHub: adapt where the information allows, refuse loudly where it does not, and prove it for every model with one registry-driven test (timm's test_model_load_pretrained over list_models(pretrained=True) is the model).

Audit 1 — classes with random weights (master 2426ddc3, 19 models × 10 geometries)

G1 canonical montage · G4 permuted · G2 biosemi64 (names+coords) · G3 8 ch coords only · G3b 8 ch names, no coords · 1 s · 30 s · non-divisible window · 100 Hz · 250 Hz. ✔ forwards · ⚠ warning · ✖ raises.

Model G1 G4 G2 G3 G3b 1 s 30 s non-div 100 Hz 250 Hz
Labram ✔ ✔⚠ ✖ ✖ ✖ ✔ ✔ ✖→✔ (#1226) ✔ ✔
EEGPT ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔
BENDR ✔ ✖ ✖ ✖ ✖ ✔ ✔ ✔ ✔ ✔
BIOT ✔⚠ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔⚠ ✔⚠
CBraMod ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✖→✔ (#1226) ✔ ✔
CodeBrain ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔
EEGDINO ✔ ✔ ✖ ✔ ✔ ✔ ✔ ✔⚠ ✔⚠ ✔⚠
LUNA ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✖→✔ (#1226) ✔ ✔
REVE ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔
SignalJEPA ✔ ✔ ✔ ✔ NaN ✖ ✔ ✔ ✔ ✔
STEEGFormer ✔ ✔ ✔ ✔⚠ ✔ ✔ ✔ ✔ – ✔
ZUNA ✔ ✔ ✔ ✔ ✖ ✔ ✔ ✖→✔ (#1226) ✖→✔ ✖→✔
Brant ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ –
BrainBERT ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✖ ✖
BaRISTA ✔ – ✔ ✔ ✖ ✔ ✔ ✔ ✖ ✖
DIVER1 ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔⚠ ✔⚠ ✔
MIRepNet ✔ – ✔ ✔ ✔ ✔ ✔ ✔ ✔ –
MVPFormer ✔ – ✔ ✔ ✔ ✔⚠ ✔ ✔⚠ ✔⚠ ✔⚠
PopT ✔⚠ – ✔⚠ ✔⚠ ✔ – – – – –

Findings: 15/19 accept any sfreq silently (only BIOT, EEGDINO, BrainBERT warn); three different minimum-length errors (SignalJEPA, BrainBERT, BaRISTA); EEGDINO maps input channel i to embedding slot i (silently wrong on a permuted or unnamed montage); SignalJEPA returns NaN for names without coordinates; LUNA/DIVER-1/REVE accept zero coordinates silently where ZUNA/BaRISTA raise; LaBraM needs ch_names at every forward for anything but its 128-name vocabulary; BENDR refuses even a permutation; BIOT/CodeBrain/MIRepNet/Brant accept any channel count structurally although their checkpoints cannot.

Audit 2 — the same grid through from_pretrained (default Hub checkpoints, CPU, 19 repos)

model G1 G1* G4 G2 G3 G3b G5a G5b G5c G6-100 G6-250 ok/total
Labram ok · ok FN FN FN ok ok FS ok ok 6/10
EEGPT FC · FC FC FC FC FC FC FC FC FC 0/10
BENDR ok · FN FC FC FC ok ok ok ok ok 6/10
BIOT ok · ok FC FC FC ok ok ok FW FW 5/10
CBraMod FL · FL FL FL FL FL FL FL FL FL 0/10
CodeBrain FT · FT FC FC FC FT ok FT FT FT 1/10
EEGDINO ok · ok FC FC FC ok ok ok ok ok 7/10
LUNA ok · ok ok ok ok ok ok FS ok ok 9/10
REVE ok · ok ok ok ok ok ok ok ok ok 10/10
SignalJEPA ok · ok FN FN ok FS ok ok ok ok 7/10
STEEGFormer FC · FC FC FC FC FC FC FC · FC 0/9
ZUNA ok · ok ok ok FN ok ok FS FS FS 6/10
Brant FC · FC FC FC FC FC FC FC FC · 0/9
BrainBERT ok · ok FC FC FC ok ok ok FS FS 5/10
BaRISTA · FC · FN FC FC FC FC FC FC FC 0/9
DIVER1 ok · ok ok ok ok ok ok ok ok ok 10/10
MIRepNet · ok · FC FC FC ok ok ok ok · 5/8
MVPFormer · FC · FC FC FC FC FC FC FC FC 0/9
PopT · FC · ok FC FC · · · · · 1/4

FC = from_pretrained rejects a chs_info whose count differs from the checkpoint's n_chans before downloading weights (66 of 100 failures — EEGPT/STEEGFormer/Brant/MVPFormer fail even on their canonical montage because the Hub config.json carries the pretraining dataset's n_chans = 62/22/16/32); FL = CBraMod from_pretrained fails at every geometry with a LazyModule "uninitialized parameter" error (torch 2.14, hf_hub 2.1.1; config.json has n_times: null → LazyLinear head) — separate bug; FW = genuine state-dict size mismatch (BIOT at other rates); FT = CodeBrain's fixed 30 s window; FS = patch/STFT shape at forward (fixed for Labram/LUNA/ZUNA by #1226); FN = channel names/locations required. All 19 repos download without a token; 78/178 cells pass; REVE and DIVER-1 pass everything.

Proposal (stacked, each PR small)

  1. Pad non-divisible windows by default: PatchTokenizer in LaBraM, CBraMod, LUNA; ZUNA default to pad #1226 — pad non-divisible windows by default via the shared PatchTokenizer (LaBraM, CBraMod, LUNA; ZUNA default flip). Done.
  2. Contract test over every pretrained class × the grid above, expected outcome derived from a declared channel strategy, unhandled cells xfail(strict). PR follows (stacked on Pad non-divisible windows by default: PatchTokenizer in LaBraM, CBraMod, LUNA; ZUNA default to pad #1226).
  3. from_pretrained channel-count check → replace the hard n_chans comparison with the model's own channel handling (EEGPT/STEEGFormer/REVE/ZUNA already adapt by names/coords; the config check blocks them).
  4. CBraMod from_pretrained LazyLinear bug (needs a repro with the traceback).
  5. ChannelTokenizer — one module, five strategies (names with a shared alias table and an on_unknown policy, coords with on_missing_loc="error", fixed_order = today's ChannelInterpolationLayer, index_slots for EEGDINO, agnostic), replacing per-model code and the Interpolated* classes; fixes EEGDINO, SignalJEPA NaN, LUNA/DIVER/REVE zero-coords, BENDR permutation.
  6. TimePositionEncoding.resample_to for the table-bound models (LaBraM 16 slots, Brant, MVPFormer).
  7. check_compatibility(model, chs_info, sfreq, n_times) public report + from_pretrained(check_inputs=True); a uniform sampling_rate check (today 3 of 19 models say anything).
  8. Backbone/head contract: backbone_prefixes/head_prefixes, freeze_backbone() with PEFT semantics (every backbone parameter, embeddings included), declared keys_to_ignore_on_load_*, output_loading_info, pinned revision per default repo.

Not proposed: timm's adapt_input_conv for channels (an electrode is not an RGB plane), in-graph resampling, a declarative config the model only warns about.

Activity

  1. BabaSanfour commented on Nov 16, 2026

    @BabaSanfour
    Contributor

    On step 8 (backbone/head contract), some data from using the pretrained models as frozen feature extractors and for fine-tuning, on a 19-channel 10-20 montage, braindecode main (1e3f4258).

    With the provenance from #1558, I listed the parameters that from_pretrained leaves at their initial values:

    Model Not loaded
    CBraMod, LUNA, SignalJEPA_Contextual, BIOT, BENDR the head (final_layer.*) only
    Labram, use_mean_pooling=False the head only
    Labram, default use_mean_pooling=True the head and fc_norm.*
    EEGPT, chan_proj_type="none" the head only (102/102 checkpoint tensors load)
    EEGPT, default chan_proj_type the head and chan_proj.proj.*

    LaBraM's fc_norm and EEGPT's chan_proj are new by design, as in the original fine-tuning recipes. For frozen features, though, they stay at their initialization in front of or after the pretrained encoder, and nothing says so. from_pretrained only warns when no parameter at all is loaded.

    Since #1558 already records what was loaded, step 8 could be:

    • each model declares the parameters that may be new (head, plus e.g. fc_norm or chan_proj);
    • from_pretrained warns for any other parameter not loaded from the checkpoint;
    • the docs of the frozen use say which settings keep everything pretrained (use_mean_pooling=False, chan_proj_type="none").

    One small related point: CBraMod, LUNA and SignalJEPA_Contextual.from_pretrained raise n_outputs not specified without n_outputs, so a headless feature extractor needs a dummy head.

    Happy to help with step 8 if useful.

  2. lindicaphxag-tech commented on Nov 17, 2026

    @lindicaphxag-tech
    Contributor

    Hi @bruAristimunha, I'd like to help with the backbone/head provenance portion of #1227. I saw that #1558 already records loaded parameters and test_pretrained_compat.py covers the input-geometry grid, so I would avoid duplicating either.

    A remaining failure mode seems worth a focused regression: frozen feature extraction can retain newly initialized non-head layers (e.g. fc_norm or chan_proj) after a checkpoint otherwise loads successfully. I've built and locally tested a small, read-only CPU prototype that classifies parameter provenance as loaded, adapted, new, or uninitialized, and flags unexpected frozen new/adapted layers after accounting for declared heads/adapters. Its synthetic tests also cover tied parameters and lazy modules. This is a prototype, not a Braindecode CI result or a claim of checkpoint parity.

    Would a narrowly scoped, test-first follow-up for that specific contract fit the plan? I'd preserve default from_pretrained behavior initially and hold off on warnings or public API changes until the model-specific expected-new declarations are agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions