Add support for ConstantPad1d and ConstantPad2d layers in PyTorch con… #1322
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.
Description
This change adds support for
nn.ConstantPad1d
andnn.ConstantPad2d
with zero padding by mapping them to the existingZeroPadding1D
andZeroPadding2D
layers inhls4ml
. It allows PyTorch models using constant zero padding to be converted without error. Only zero padding values are currently supported.Type of change
Tests
I verified the new padding layer support by implementing and converting two minimal PyTorch models using
nn.ConstantPad1d
andnn.ConstantPad2d
. These tests check whetherhls4ml
correctly parses, configures, and converts both 1D and 2D constant padding operations into valid HLS models.To reproduce:
Pad1DModel
withnn.ConstantPad1d((2, 3), 0)
andPad2DModel
withnn.ConstantPad2d((1, 2, 3, 4), 0)
.config_from_pytorch_model()
on each with appropriate input shapes.convert_from_pytorch_model()
..write()
to generate the HLS project.These tests were run using Python 3.10, PyTorch 2.1, and the latest
hls4ml
version on a Microsoft environment. Only model generation (.write()
) was executed; no synthesis or simulation was performed.Test Configuration:
Checklist
pre-commit
on the files I edited or added.