-
Notifications
You must be signed in to change notification settings - Fork 384
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
Latency Pooling Header Updates #973
base: main
Are you sure you want to change the base?
Conversation
pre-commit.ci autofix |
# Functional | ||
input_layer_name = layer.attributes['inputs'][0] | ||
else: | ||
# Sequential |
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 don't fully understand why the if-else is requried. Can't you always query for the previous node?
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.
If we have a functional model that has A->B, A->C, with C being the pooling layer. As the order of B and C is arbitrary, if we query the precious node, we can get B, the sibling of the current node, instead of A.
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 don't quite follow. Are the node inputs not correctly filled in some cases?
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.
Not sure for now, but they were not as of Nov 2023. Only for the functional model converted graph, the parent names are filed; for sequential models, the fields were missing.
Could check this again quickly.
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.
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 you can use get_input_node
or something similar to get the node. https://github.com/fastmachinelearning/hls4ml/blob/main/hls4ml/model/layers.py#L182-L192
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.
Just checked and cannot get the inputs with current hls4ml master.... weird.
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.
Note that it's self.inputs
, not self.attributes['inputs']
.
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.
(on the Layer object)
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.
Confirmed, modified PR.
There seem to be some real pytest failures associated with this PR. @calad0i, can you take a look? |
Fixed vitis and mnist tests. Pytorch test directly crashed, need some debugging to see what is wrong. |
if isinstance(accum_t.precision, FixedPrecisionType): | ||
accum_t.precision.integer += extra_bits | ||
|
||
if pool_op == 'max': |
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.
This should not be set here. The user can override it, in which case we should follow what the user requests. Otherwise, if this was set to "auto", then the automatic precision inference (#855) will do something similar. We can check if it does the right thing there and fix it if needed (but let me check that my updates that went in that PR first before adding code to it.)
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.
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.
This is the current version that I have: https://github.com/jmitrevs/hls4ml/blob/qonnx-1p0/hls4ml/model/optimizer/passes/infer_precision.py. I will try to extract it and make a PR to 855 with it within the next 2 hours or so.
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 made a PR to Vladimir's branch: vloncar#55 . You can probably do the same. I don't think I explicitly did anything for pooling, but there is the merge Average and Add that probably have the same logic in my PR.
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.
Opened PR at #56. This PR will be updated if that one got merged.
@@ -376,37 +373,14 @@ def init_depconv2d(self, layer): | |||
) # TODO Once we have SeparableConv implementation for io_parallel this should be set properly | |||
layer.set_attr('implementation', layer.model.config.get_conv_implementation(layer).lower()) | |||
|
|||
def _set_pooling_accum_t(self, layer, pool_size): |
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 shouldn't merge this change before we have the subsequent change in auto precision inference. Right now it's removing features that already exist (and catapult customers may be using) without replacing it right away. For Vitis and Vivado it is fine to not add something that doesn't yet exist, but one has to be more careful about removing already existing features. If we want to decouple things, we should move the catapult update to a separate PR.
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.
The current _set_pooling_accum_t
is flawed (overrides default_t
in most cases, doesn't always fix overflow as well; multiple pooling layers will results in a huge default model bitwidth thanks to the +=
operation), and I fixed it in the last iteration of this PR.
This PR will not work without proper accum_t
set, and that's why I fixed it right here in the last iteration. As you suggested, I integrated it with #855, and I have marked #855 as required by this PR.
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 still think it's problematic for us to remove this from the Catapult backend. We can make a separate PR just removing it and ask them to comment and review it. That's why I was not wanting the other stuff to be dependent on the Seimens signoff. It's a user interface change for their users, so they have to be on board and scheduling the change.
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.
Generally, unless they are code maintenance-type changes or purely adding new features, Catapult backend changes need Siemens approval.
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.
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 are hoping to merge #855 soon. The last changes failed the pytests, so after chaging "ave" to "average" we are trying again. Vivado should not have the overrides since it never had them. It should start with the new way of doing things from the beginning. (Actually, I was wrong about Vivado not having had the overrides before.)
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 would probably make the Catapult change a separate PR, though. We do eventually want that.
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.
As #855 does not remove that override, I will remove the Vivado override and leave the Siemens one as-is.
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 hadn't appreciated that there was already some auto precision setting for Vivado. Nevertheless, I believe removing it is the right thing to do since we have the auto precision. I will announce it.
latency pooling overhaul vivado latency pooling overhaul vitis latency pooling overhaul, fix comment fix boundry cond fix syn issues latency pooling overhaul Fix pooling accum_t autoset & avoid global override [pre-commit.ci] auto fixes from pre-commit hooks better way to get inp layer name fix for vitis / input_t fetch torch padding fix avoid name dup in torch api test rm pooling precision override in favor of fastmachinelearning#855
|
Don't worry about the test_weight_writer.py |
I am not sure if our pytest environment is functional. I can try running them again, but they may fail for infrastructure reasons |
The |
Correct. The reason to fail is exactly overflow in the avg pool, which had an overriding mechanism but is now removed. |
Let's add the fix to the test and maybe merge this? I think making auto a default for some layer types could be a different PR, and I think it's really a change in the |
We can fix the failing
|
Precision override moved to Requires #855 now. Expect tests to fail without.
Include and superceeds #917. On the same issue: #947
This PR does the following, for the
vivado
andvitis
backends.io_parallel
mode respect toaccum_t
.io_parallel
.tmp
andscale
in the original avg pool implementation.- Avoid overriding global variable names when automatically overriding precisions; deriveMoved to Automatic precision inference #855accum_t
properly from impending layer'sresult_t
.With the current setting, pooling layers will be bit-accurate if the impending layer's
result_t
is configured properly.Synthesis on some toy models
Type of change
Tests
Will be covered in #914 (WIP).
Checklist
pre-commit
on the files I edited or added.