Repository navigation
FIX FilterBankLayer TorchScript with PyTorch 2.15 (master CI) - #1501
Merged
Merged
Conversation
PyTorch 2.15 added torch.autograd.Function.input_grad_buffers, annotated tuple[Tensor | None, ...], which TorchScript cannot parse. Scripting FilterBankLayer compiles torchaudio's lfilter, whose DifferentiableFIR and DifferentiableIIR are autograd.Function subclasses, so FBCNet, FBMSNet, FBLightConvNet and IFNet no longer script. Eager filtering keeps calling torchaudio. The scripted path runs the ops torchaudio's own scripted path runs (FIR conv1d, then its IIR core loop), so scripted outputs are unchanged. _apply_iir calls lfilter or filtfilt in an if/else, since the helpers no longer take torchaudio's clamp argument.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the TorchScript filtering changes.
No open issues 🎉
What changed in this PR
This PR addresses the PyTorch 2.15 TorchScript failure affecting FIR FilterBankLayer instances and models that use them, while preserving eager filtering through torchaudio.
Changes:
- Adds private scriptable filtering helpers that bypass torchaudio’s incompatible autograd classes.
- Routes
FilterBankLayerthrough the helpers with explicit causal and bidirectional branches. - Adds output-parity and scripting regression tests, plus a changelog entry.
| File | Description |
|---|---|
test/unit_tests/models/test_modules.py |
Tests filtering parity with torchaudio and FIR filter-bank scripting. |
docs/whats_new.rst |
Documents the PyTorch 2.15 scripting fix and affected models. |
braindecode/modules/filter.py |
Uses the private filtering helpers and explicit IIR branches. |
braindecode/functional/_lfilter.py |
Implements scriptable filtering paths while retaining torchaudio for eager execution. |
Review effort: Balanced
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1501 +/- ##
==========================================
+ Coverage 91.19% 91.20% +0.01%
==========================================
Files 168 169 +1
Lines 21862 21916 +54
==========================================
+ Hits 19937 19989 +52
- Misses 1925 1927 +2 🚀 New features to boost your workflow:
|
Coverage cannot trace code that only runs inside TorchScript. Call the scripted ops directly as well and check them against torchaudio bit for bit, and check the Python core-loop fallback against torchaudio's loop.
bruAristimunha
added a commit
to bruAristimunha/braindecode
that referenced
this pull request
Nov 2, 2026
Patch release of the 1.8 series: version 1.8.2 and its whats_new section. Backports braindecode#1501 (TorchScript of the filter-bank models on PyTorch 2.15) and braindecode#1164 (MNE >= 1.13 montage renames: FutureWarning at import, error from MNE 1.14).
bruAristimunha
added a commit
to bruAristimunha/braindecode
that referenced
this pull request
Nov 2, 2026
Patch release of the 1.8 series: version 1.8.2 and its whats_new section. Backports braindecode#1501 (TorchScript of the filter-bank models on PyTorch 2.15) and braindecode#1164 (MNE >= 1.13 montage renames: FutureWarning at import, error from MNE 1.14).
This was referenced Nov 2, 2026
Merged
bruAristimunha
added a commit
that referenced
this pull request
Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Master's
testsjob has been red since CI started resolving PyTorch 2.15.0 (with torchaudio 2.11.0):test_torch_scriptfails for FBCNet, FBMSNet, FBLightConvNet and IFNet. The last green run of the same commit range used torch 2.14.1.Cause
PyTorch 2.15 added a property to
torch.autograd.Function:TorchScript cannot parse the
...(Expression of type dots cannot be used in a type expression). ScriptingFilterBankLayercompilestorchaudio.functional.lfilter, whoseDifferentiableFIR/DifferentiableIIRareautograd.Functionsubclasses, so TorchScript compiles them as classes and hits that property. This breakstorch.jit.scripton these four models for every user on torch 2.15, not only in CI.Fix
braindecode/functional/_lfilter.py(private) provideslfilter/filtfilt(clamp=False, 1-D coefficients):@torch.jit.unused;ts_applycallsforwarddirectly when scripting): the FIR part asconv1d, the IIR recursion through torchaudio's_lfilter_core_loop. Scripted outputs are unchanged.It is a separate module because
torch.jit.unusedneeds real annotations andfilter.pyusesfrom __future__ import annotations(same reason as_real_dft.py).FilterBankLayer._apply_iirnow callslfilter/filtfiltin anif/elseinstead of through a function-valued variable.Evidence (CPU Jobs on Voyager)
test_torch_scriptcases (90 passed, 1 skipped).test_torch_scriptcases (90 passed, 1 skipped) andtest_modules.py.FilterBankLayer(zero-phase and causal), every scripted output is bit-identical to master's scripted output, and every eager output is bit-identical to master's, except FBCNet eager, which already differs by up to 1.2e-5 between three identical runs on master itself (run-to-run nondeterminism on its FFT path, untouched here).lfilter/filtfiltequal torchaudio's eager output bit for bit (torch.equal, FIR and IIR); FIRFilterBankLayer(zero-phase and causal) scripts and matches eager.Not changed: an IIR
FilterBankLayerdoes not script on master either (an unrelated empty-list typing error in the FIR-bank branch), before and after this PR.