-
Notifications
You must be signed in to change notification settings - Fork 450
Add an optimizer to replace SeparableConv by Depthwise + Conv (pointwise) #1022
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
Add an optimizer to replace SeparableConv by Depthwise + Conv (pointwise) #1022
Conversation
I am somewhat torn as to whether to remove the regular accum_t and reuse_factor, which are not used if the separable is split, which is the default. |
I decided that it was cleaner to remove the unused attributes. |
Comment for reviewers: Note the changes in graph.py for easier passing of the configuration from one layer to child layers after transformations. This is used also in the qonnx PR. It's probably useful to check here. |
There are some template changes in the Vivado backend from when I thought I would make this PR handle multiplier factors != 1. In particular, I changed n_chan to n_filt in some places, which for multiplier_factor == 1 are identical. In the end I added an assert that the multiplier factor == 1. I did not put those in other backends, though all only work with multiplier factor == 1. I figured that would be taken up by the multiplier_factor != 1 PR. |
Description
When looking at automatic type inference, reuse factor setting, stream buffer optimization, and eventual oneAPI implementation with task sequences, it became clear that treating separable convolutions as two layers instead of one was easier. The different layers can have different accumulator precisions, reuse factors, etc.
This optimizer converts a
SeperableConv*D
layer to aDepthwiseConv*D
layer followed by aConv*D
layer for the pointwise convolution. (For backends that have an explicit pointwise implementation, a subsequent optimizer changes theConv*D
toPointwiseConv*D
.) Layer-wise configurations are also created for the new depthwise and pointwise convolutions so that type inference can be done on the individual layers. Hence, this optimizer should be run before the automatic type inference. (The qonnx PR #979 adds a number of other optimizers than also need to run before the type inference, so this will be a common feature.)In this PR I added parameters but did not remove any. In particular, reuse factor and accumulator type are ambiguous, and unused in the new implemenation, being split between depthwise and pointwise reuse factors and accumulators. However, if this optimizer is disabled, the old scheme should still work, with care by the user.Decided it was cleaner to remove the unused parameters.
I believe this PR also adds support for multiplier factors other than 1, but it's untested. It was motivated by #1008 .Multiplier factors other than 1 will come in a separate PR. This implements some parsing but at the end an assert is added for the Vitis/Vivado templates asserting that only a multiplier factor of 1 is currently supported.
Type of change
Updated implementation that
Note: Please delete options that are not relevant.
Tests
This should not cause changes to the standard depth_multiplier=1 separable convolutions not using automatic type inference, so the default tests should be fine. The automatic type inference will be tested in a following PR that makes auto the default.
Checklist
pre-commit
on the files I edited or added.