-
Notifications
You must be signed in to change notification settings - Fork 422
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
base: main
Are you sure you want to change the base?
Conversation
hls4ml/converters/pytorch_to_hls.py
Outdated
input_layers.append(input_layer['name']) | ||
n_inputs += 1 | ||
if 'const' in node.name: | ||
pytorch_class = "Constant" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.
Tests
Checklist
pre-commit
on the files I edited or added.