Closed sei-jgwohlbier closed 1 month ago
hls4ml doesn't parse modules/operations directly, it parses the torch.fx trace graph. sometimes this corresponds to the operation/module/layer you use directly, sometimes it's a lower-level operation you don't know. we need to investigate if the operation only ever appears as view
(implying current behavior is a bug), or there's View
and view
with somewhat different semantics and we need support for both. View
could be the result of nn.Flatten
, but I'm not sure, needs checking.
I have seen this difference in capitalization when the same operation is implemented both as a layer object and as a function. I'll have a look to confirm.
Yes, the differences in capitalization between classes and functions are common. e.g., Conv2d
vs conv2d
. I don't think PyTorch has a View
class.
I remembered how we handled this. We basically decided to follow the capitalization of the classes, so first letter capitalized, and have this map https://github.com/fastmachinelearning/hls4ml/blob/main/hls4ml/converters/pytorch_to_hls.py#L84-L98 to map the lower-case functions to the right name. In this case it's a little bit meaningless, but for consistency, the solution is to add a mapping of view
to View
here. I can make the PR for that.
Prerequisites
Please make sure to check off these prerequisites before submitting a bug report.
Quick summary
In
hls4ml/converters/pytorch/reshape.py
there isand the matching code in
def parse_reshape_layer
. If one tries to use, e.g.,variable.View(-1,N)
the PyTorch fails to compile. ChangingView
toview
seems to work. Below is the code diff and a reproducer.Details
Steps to Reproduce
Expected behavior
Success.
Actual behavior
Optional
Possible fix
Apply this patch:
Results in success. If this fix seems correct I can make a PR.