Skip to content

Route Pytorch Conv1D/2D with groups == channels to depthwise conv - #1524

Merged
JanFSchulte merged 1 commit into
fastmachinelearning:mainfrom
HamzaEzzRa:torch-sepconv
Aug 12, 2026
Merged

Route Pytorch Conv1D/2D with groups == channels to depthwise conv#1524
JanFSchulte merged 1 commit into
fastmachinelearning:mainfrom
HamzaEzzRa:torch-sepconv

Conversation

@HamzaEzzRa

@HamzaEzzRa HamzaEzzRa commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

Similar to the Keras issue solved in #1486, Pytorch Conv1D/2D where groups == in_channels == out_channels is not routed to the correct DepthwiseConv codegen path. Since Pytorch doesn't have a built-in DepthwiseConv layer, the only way I know to express this operation is to change a standard Conv groups to match in_channels and out_channels, which the pytorch_to_hls.py converter strictly rejects.

This patch relaxes the condition in pytorch_to_hls.py to include groups > 1 and groups == in_channels == out_channels as a valid configuration, then routes to the correct DepthwiseConv1D/2D graph layer inside convolution.py and reshapes to (depth_multiplier, n_chan, *kernel_size) with depth_multiplier = 1 for the depthwise conv.

Type of change

  • Bug fix (non-breaking change that fixes an issue)

Tests

Added two tests:

  • test/pytest/test_depthconv1d_pytorch.py
  • test/pytest/test_depthconv2d_pytorch.py

Both are similar to the existing test_depthconv1d.py and test_depthconv2d.py, with code adapted from test_pytorch_api.py for Pytorch compatibility. Vivado and Vitis tests passed, but I don't have Catapult installed in my system to verify its backend.

Test Configuration:

Same pytest configuration as the existing test_depthconv1d.py and test_depthconv2d.py respectively.

pytest test/pytest/test_depthconv*d_pytorch.py

Checklist

  • I have read the guidelines for contributing.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have installed and run pre-commit on the files I edited or added.
  • I have added tests that prove my fix is effective or that my feature works.

@HamzaEzzRa
HamzaEzzRa marked this pull request as ready for review August 11, 2026 16:16
@JanFSchulte JanFSchulte added enhancement please test Trigger testing by creating local PR branch labels Aug 11, 2026
@JanFSchulte JanFSchulte self-assigned this Aug 11, 2026
@JanFSchulte
JanFSchulte merged commit ce4b78d into fastmachinelearning:main Aug 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement please test Trigger testing by creating local PR branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants