Skip to content

Add BrainOmni, the downstream classifier on BrainTokenizer - #1231

Merged
bruAristimunha merged 12 commits into
braindecode:masterfrom
bruAristimunha:w41/brainomni-3-classifier
Oct 6, 2026
Merged

bruAristimunha merged 12 commits into
braindecode:masterfrom
bruAristimunha:w41/brainomni-3-classifier

Conversation

@bruAristimunha

Copy link
Copy Markdown
Collaborator

Split 3/3 of #1043, stacked on #1230 (its diff shrinks to the classifier once #1230 merges). Adds BrainOmni, the downstream classifier on a frozen BrainTokenizer (RoPE spatiotemporal transformer blocks + pooled head), strictly loading the authors' raw tiny and base checkpoints. reset_head goes through _set_n_outputs/_update_init_kwargs so a re-serialized model reports its real head. license="mit".

Licence: MIT.
Replication: PhysioNet-MI test balanced accuracy 0.5796 ± 0.0164 vs the paper's 0.580 ± 0.019 (BrainOmni tiny, released protocol, 30/30 cells).

BrainOmni is ported from OpenTSLab/BrainOmni (MIT); its SEANet codec from
Meta's EnCodec (MIT) and its residual VQ from lucidrains/vector-quantize-pytorch
(MIT). Per the model-port convention a port links to its licence rather than
bundling the text, so add only the file lines for brainomni.py and the shared
modules/quantization.py under the existing MIT section (the MIT link is already
present) and leave pyproject.toml/MANIFEST.in untouched.
Port of the OpenTSLab BrainOmni tokenizer (MIT) with strict loading of the
authors' raw BrainTokenizer.pt beside the architecture
(BrainTokenizer.from_opentslab_config + load_state_dict key mapping).

Sensor geometry, SEANet codec, residual VQ (EMA codebooks, K-means init,
rotation trick) and the cross-attention bridges stay private in
braindecode/models/brainomni.py; no public braindecode.modules or
models.util API is added. Tests live in test/unit_tests/models/test_brainomni.py
(Hub checks are marked network). Registration: models export, summary.csv,
util registry lists, docs/api.rst, whats_new, NOTICE, TorchScript skip.
BrainOmni (MIT, OpenTSLab) wraps the frozen BrainTokenizer with the released
spatial-temporal factored attention blocks and a downstream head, and strictly
loads the authors' raw tiny/base Stage-2 checkpoints (pretraining head and
RoPE caches dropped, RoPE recomputed in float32).

The RoPE attention stays private in braindecode/models/brainomni.py; no public
braindecode.modules API is added. Tests extend test_brainomni.py (Hub checks
marked network). Registration: models export, summary.csv, util registry,
docs/api.rst, whats_new, TorchScript skip.
Resolved NOTICE.txt by keeping both MIT entries.
Resolved docs/whats_new.rst by keeping both entries.
Copilot AI balanced review requested due to automatic review settings October 5, 2026 13:12
@bruAristimunha bruAristimunha added needs-replication Model PR: paper number must be replicated (NeuralBench) before merge model Adds a new model labels Oct 5, 2026

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 3 Medium severity

Open (4)
What changed in this PR

Adds BrainOmni’s downstream classifier and its BrainTokenizer backbone, including shared residual vector quantization utilities and focused tests to ensure strict parity with the authors’ released checkpoints/configs.

Changes:

  • Introduce BrainTokenizer (VQ-VAE tokenizer) and BrainOmni (frozen-tokenizer classifier) with OpenTSLab config/key translation and strict checkpoint loading.
  • Add shared EMA-based residual vector quantization module under braindecode.modules.
  • Add extensive unit + network parity tests, plus documentation/API registry updates.
File Description
braindecode/​models/​brainomni.py New BrainTokenizer/BrainOmni implementations, config translation, strict key remapping, geometry derivation, and model internals.
braindecode/​modules/​quantization.py New shared EMA residual vector quantization implementation used by the tokenizer.
test/​unit_tests/​models/​test_brainomni.py New focused tests (geometry, SEANet, quantization, strict-load parity) including network-gated checkpoint parity checks.
test/​unit_tests/​models/​test_integration.py Excludes BrainOmni/BrainTokenizer from TorchScript integration test.
braindecode/​models/​__init__.py Exposes BrainOmni and BrainTokenizer in the public models API.
braindecode/​modules/​__init__.py Exposes quantization modules in the public modules API.
braindecode/​models/​util.py Registers model signatures and marks BrainTokenizer as non-logit-returning.
braindecode/​models/​summary.csv Adds summary entries for BrainOmni and BrainTokenizer.
docs/​whats_new.rst Documents new BrainTokenizer and BrainOmni additions.
docs/​api.rst Adds BrainOmni/BrainTokenizer to the generated API docs.
NOTICE.txt Adds attributions for BrainOmni/EnCodec/vector-quantize-pytorch derived components.

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

Comment thread braindecode/modules/quantization.py
Comment thread braindecode/models/brainomni.py
Comment thread braindecode/models/brainomni.py
Comment thread test/unit_tests/models/test_brainomni.py
Copilot AI balanced review requested due to automatic review settings October 5, 2026 20:46

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.62500% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.27%. Comparing base (5e00a5b) to head (47945af).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1231      +/-   ##
==========================================
+ Coverage   87.99%   88.27%   +0.28%     
==========================================
  Files         151      153       +2     
  Lines       17628    18428     +800     
==========================================
+ Hits        15511    16268     +757     
- Misses       2117     2160      +43     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

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.

Comment thread braindecode/models/brainomni.py
@bruAristimunha
bruAristimunha merged commit 6d9800c into braindecode:master Oct 6, 2026
19 of 21 checks passed
bruAristimunha added a commit to bruAristimunha/braindecode that referenced this pull request Oct 6, 2026
whats_new: keep both; refs for NeuroRVQ (braindecode#1218), BrainTokenizer (braindecode#1230), BrainOmni (braindecode#1231) point to the merged PRs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Adds a new model needs-replication Model PR: paper number must be replicated (NeuralBench) before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants