Skip to content

FIX Accept tensor inputs in amplitude attribution - #1464

Merged
bruAristimunha merged 1 commit into
braindecode:masterfrom
antonsoo:fix/amplitude-gradient-tensor-input
Oct 18, 2026
Merged

bruAristimunha merged 1 commit into
braindecode:masterfrom
antonsoo:fix/amplitude-gradient-tensor-input

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

Summary

amplitude_gradients accepts torch.Tensor inputs in its documented API, but passes them straight to NumPy FFT. CUDA tensors and tensors with requires_grad=True raise before attribution runs.

Changes

Convert through the existing to_numpy helper before rfft. Add CPU/CUDA regressions with and without tracked input gradients, plus the changelog entry.

Testing

Using Python 3.12, PyTorch 2.7.0+cu128 and NumPy 2.5.4:

  • pytest test/unit_tests/visualization -q: 34 passed, 1 skipped. Three added cases fail on unchanged master; the ordinary CPU-tensor control passes.

  • pre-commit run --files braindecode/visualization/frequency.py test/unit_tests/visualization/test_gradients.py docs/whats_new.rst: all applicable hooks pass.

  • Recorded PhysioNet EEG S001R04 with an analytic energy model and initialized ShallowFBCSPNet, odd/even signal lengths, CPU and RTX 5070: all 24 input-form calls work, versus 12 failures before. All 12 previously working outputs stay byte-identical.

  • Broad CPU/offline attempt (pytest test/ -q --maxfail=3, HF_HUB_OFFLINE=1) on unchanged master and this branch gives the same 3 model-export failures, 1852 passes and 381 skips: LUNA pytree arity, TFMTokenizer/BrainTokenizer sub(out=...) autograd errors. This is not a complete green suite.

  • Regression tests cover the changed behavior

  • Style checks recorded

  • docs/whats_new.rst updated

Notes for reviewers

The existing NumPy FFT and transfer to the model's device remain in place. The input tensor is detached for analysis; its .grad remains unset. Checkpoint/reset_head/mixed-mode tests are N/A because no model definition or state handling changes.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T23:36:30.849791Z 11f22b3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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.04%. Comparing base (47912a9) to head (11f22b3).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1464   +/-   ##
=======================================
  Coverage   91.04%   91.04%           
=======================================
  Files         165      165           
  Lines       21653    21653           
=======================================
  Hits        19714    19714           
  Misses       1939     1939           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bruAristimunha bruAristimunha left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: to_numpy before np.fft.rfft is the one-line fix; the CPU/CUDA × grad parametrization covers the documented inputs. Merging.

@bruAristimunha
bruAristimunha merged commit e1bdb41 into braindecode:master Oct 18, 2026
10 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