Skip to content

functional: rotary_frequencies, rotary_angles, apply_rotary, rotate_half; six models use them - #1456

Merged
bruAristimunha merged 3 commits into
braindecode:masterfrom
bruAristimunha:cleanup/t20-rotary
Oct 18, 2026
Merged

bruAristimunha merged 3 commits into
braindecode:masterfrom
bruAristimunha:cleanup/t20-rotary

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1455 (its commit is included until it merges; this PR adds one commit).

Part of #1442, Tier 1 of the consolidation plan (dedupe the computation, keep every parameter where it is).

Eight models carried their own rotary embedding. The frequency table 1 / base ** (2i / d), the angle layout (interleaved pairs or two halves) and the rotation x * cos + rotate(x) * sin are now four public functions in braindecode.functional, next to the existing rotate_pairs:

  • rotary_frequencies(head_dim, base, device, dtype)
  • rotary_angles(positions, inv_freq, interleaved)
  • apply_rotary(x, cos, sin, interleaved)
  • rotate_half(x) (the half-split layout, used by BaRISTA)

BaRISTA, BrainOmni, DIVER-1, EpiNT, LUNA and TCFormer call them; their buffers and parameters (LUNA's persistent freqs, BrainOmni's freqs/rotate) stay where they are, so released weights load unchanged. The arithmetic is the same op sequence as before. TCFormer keeps its reference quirk (half-split angles with pair rotation), commented. ZUNA's four-axis rotary is unchanged.

EEGPT's _rotate_half, _apply_rotary_emb and use_rope plumbing were never enabled (use_rope=False at the only call site); removed, with their three tests.

Characterization against master (same seed): BaRISTA, BrainOmni, DIVER-1, EpiNT, LUNA, TCFormer and EEGPT have identical state_dict keys and weights and bit-identical outputs. 477 model tests pass (test_model_exported[LUNA] fails the same way on master with local torch); 14 functional tests incl. TorchScript. The helpers avoid keyword-only arguments so TCFormer, which builds its table in forward, still scripts.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 20: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.

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 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.03%. Comparing base (47912a9) to head (1767d20).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1456      +/-   ##
==========================================
- Coverage   91.04%   91.03%   -0.01%     
==========================================
  Files         165      165              
  Lines       21653    21621      -32     
==========================================
- Hits        19714    19683      -31     
+ Misses       1939     1938       -1     
🚀 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 18, 2026 00: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.

@bruAristimunha
bruAristimunha merged commit 0c2ffe5 into braindecode:master Oct 18, 2026
7 checks passed
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