Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Constant nodes in pytorch parser #1123

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

JanFSchulte
Copy link
Contributor

Fixes #1082.

Constants, for example for multiplications, are recognized and added to the hls4ml model using the Constant layer introduced in the QONNX parser. Thanks to @sei-jgwohlbier for finding the issue and designing the fix.

Type of change

For a new feature or function, please create an issue first to discuss it
with us before submitting a pull request.

Note: Please delete options that are not relevant.

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change which adds functionality)

Tests

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.

@JanFSchulte JanFSchulte added the please test Trigger testing by creating local PR branch label Nov 12, 2024
input_layers.append(input_layer['name'])
n_inputs += 1
if 'const' in node.name:
pytorch_class = "Constant"
Copy link
Contributor

Choose a reason for hiding this comment

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

We use single quotes wherever possible, let's not mix the two styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

def parse_constant_layer(operation, layer_name, node):
assert 'Constant' in operation

layer = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add empty list as inputs here (and do the same in onnx parser)? The Constant node in the IR will override anyway, but it feels like that feature should be a check and an error, otherwise it will silently changing things making it harder to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the suggested change here would just be layer['inputs'] = [], and then we'd add a check to the Constant node to throw an error if the input list is not empty?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here and in qonnx parser. Then the self.inputs = [] in Constant layer could be a check and a warning before setting. This could be better for futureproofing for constant nodes coming from various sources (like optimizers). @jmitrevs what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added it here.

@JanFSchulte JanFSchulte added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please test Trigger testing by creating local PR branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PyTorch: merge layer with a constant input
2 participants