Skip to content

Fix Chomp1d zero-size identity for TCN unit kernels - #1219

Merged
bruAristimunha merged 8 commits into
braindecode:masterfrom
lindicaphxag-tech:fix/chomp1d-zero-padding
Oct 5, 2026
Merged

bruAristimunha merged 8 commits into
braindecode:masterfrom
lindicaphxag-tech:fix/chomp1d-zero-padding

Conversation

@lindicaphxag-tech

Copy link
Copy Markdown
Contributor

Summary

Fix Chomp1d(0) returning an empty time axis and restore TCN(kernel_size=1).

Root cause

Chomp1d.forward() currently slices with:

x[:, :, :-self.chomp_size]

For chomp_size == 0, Python interprets :-0 as :0, so a valid zero-chomp operation removes the entire temporal axis.

This is reachable from the public TCN configuration: kernel_size=1 gives causal padding (kernel_size - 1) * dilation == 0, so both temporal blocks construct Chomp1d(0).

Fix

Treat zero chomp as the identity operation. Positive chomp sizes retain the existing slice behavior.

Regression coverage

  • module-level regression: Chomp1d(0) preserves shape and values;
  • model-level regression: TCN(kernel_size=1) completes a forward pass;
  • What's New entry.

I also reproduced the boundary independently on CPU: the current implementation maps an input of shape (2, 3, 11) to (2, 3, 0), and a unit-kernel temporal block then fails at the second convolution because the time dimension is empty. With the zero-chomp identity guard, the block preserves the 17-step reference length and returns finite outputs.

AI assistance was used to audit the boundary condition and prepare the patch; the change is intentionally limited to the zero-chomp contract and its regressions.

@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.84%. Comparing base (ccbbea3) to head (72c001b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1219   +/-   ##
=======================================
  Coverage   87.84%   87.84%           
=======================================
  Files         151      151           
  Lines       17600    17602    +2     
=======================================
+ Hits        15460    15462    +2     
  Misses       2140     2140           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

lindicaphxag-tech and others added 2 commits October 4, 2026 19:52
Resolved docs/whats_new.rst by keeping both changelog entries.

@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.

Thanks. Reproduced the Chomp1d zero-size slice on master, verified the identity path and that every caller's default output is unchanged. CI green.

Resolved docs/whats_new.rst by keeping both changelog entries.

@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.

Thanks. Reproduced the Chomp1d zero-size slice on master, verified the identity path and that every caller's default output is unchanged. CI green.

@bruAristimunha
bruAristimunha merged commit 882ffe4 into braindecode:master Oct 5, 2026
15 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