Skip to content

LUNA: accept ch_mask - #1543

Merged
bruAristimunha merged 29 commits into
braindecode:masterfrom
bruAristimunha:chmask-luna
Nov 5, 2026
Merged

bruAristimunha merged 29 commits into
braindecode:masterfrom
bruAristimunha:chmask-luna

Conversation

@bruAristimunha

Copy link
Copy Markdown
Collaborator

LUNA accepts ch_mask, so a batch can mix recordings with different channel counts. Each recording gets the output it gets when run alone, given per-recording channel_locations.

  • Padded channels are left out of the three GroupNorm statistics over the (channel × patch) rows (masked_group_norm), out of the min/max normalisation of the channel locations, and out of the keys of the channel cross-attention.
  • LUNA now scripts without a first eager forward: an empty _channel_location_cache needed a type annotation. The matching xfail in test_foundation_models.py now passes.
  • With ch_mask=None nothing changes: outputs, gradients and scripted outputs are bit-identical to master. No parameter or state-dict key changes.

Please merge after #1539 and #1540.

Testing

  • test_ch_mask.py: LUNA added to _CASES with per-recording channel_locations, eager and scripted, with no gradient into padding.
  • Existing LUNA tests pass, with no new failures.

julien-gadonneix and others added 4 commits November 5, 2026 00:35
Padded channels are zero-filled, never attended to (key mask before the
key softmax of the linear attention) and not pooled (masked_mean).
Masked GroupNorm in the patch embedding, location range over real
channels, key padding mask in the channel cross-attention. A class-level
annotation lets LUNA script with an empty location cache.
Copilot AI balanced review requested due to automatic review settings November 5, 2026 14: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.

🟡 Changes recommended

In reconstruction mode, the channel padding mask never reaches the decoder, allowing padded-channel queries to affect real-channel reconstructions even during evaluation.

1 open issue
What changed in this PR

Adds channel-mask support to LUNA so batches can contain recordings with different channel counts, extending the foundation models’ padded-channel handling.

Changes:

  • Excludes padded channels from patch-embedding normalization, location normalization, and channel cross-attention.
  • Adds a cache type annotation for scripting before an eager forward.
  • Extends shared channel-mask tests to LUNA and documents the enhancement.
File Description
test/​unit_tests/​models/​test_ch_mask.py Adds LUNA with per-recording channel locations to shared mask tests.
docs/​whats_new.rst Documents LUNA channel-mask support and scripting improvement.
braindecode/​models/​luna.py Threads channel masks through normalization and attention; types the location cache.

Review effort: Balanced

Comment thread braindecode/models/luna.py Resolved
Copilot AI balanced review requested due to automatic review settings November 5, 2026 14:14

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

In reconstruction mode, the channel-padding mask is not propagated to decoder self-attention, allowing padded channel queries to alter real-channel reconstructions.

1 open issue

Review effort: Balanced

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.46%. Comparing base (b40e1cc) to head (35e081f).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1543      +/-   ##
==========================================
+ Coverage   91.39%   91.46%   +0.06%     
==========================================
  Files         170      170              
  Lines       22155    22226      +71     
==========================================
+ Hits        20249    20329      +80     
+ Misses       1906     1897       -9     
🚀 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 November 5, 2026 15:08

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.

🟢 Approval recommended

No active review issues remain for the LUNA channel-masking changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 5, 2026 18:10

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.

🟢 Approval recommended

No active review issues are recorded for the LUNA and BIOT channel-mask support changes.

No open issues 🎉

Review effort: Balanced

@bruAristimunha
bruAristimunha merged commit cc5375a into braindecode:master Nov 5, 2026
10 checks passed
bruAristimunha added a commit to bruAristimunha/braindecode that referenced this pull request Nov 9, 2026
Brings in the ch_mask series (braindecode#1545 braindecode#1548 braindecode#1540 braindecode#1549 braindecode#1542 braindecode#1543 braindecode#1544 braindecode#1550), braindecode#1557 and braindecode#1559 (master dba9d42). No conflicts; NOTICE.txt and docs/whats_new.rst carry only this PR's additions over master.
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