-
Notifications
You must be signed in to change notification settings - Fork 966
NXP backend: added support for aten.conv_transpose1 and refactored convolution_converter
#19004
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,32 @@ def get_bias_qparams( | |
| return bias_scale, bias_zero_point | ||
|
|
||
|
|
||
| def get_padded_bias_qparams( | ||
| obs_or_fqs: List[ObserverOrFakeQuantize], | ||
| out_channels: int | None = None, | ||
| ) -> Tuple[torch.Tensor, torch.Tensor]: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function name doesn't explain what the function does. So I think some docstring here explaining it is specifically designed for transpose conv would be useful. Or perhaps the function name could mention the transpose conv? |
||
| act_scale, _ = obs_or_fqs[0].calculate_qparams() | ||
| weight_scale, _ = obs_or_fqs[1].calculate_qparams() | ||
|
|
||
| # It may happen that `torch.ao` incorrectly sets the weight qparams, not matching bias qparams. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the weight qparams really set incorrectly by torchao? After our discussions, I thought that that's how it's supposed to work, and just the function which derives the bias qparams was wrong. |
||
| # If `out_channels` is given, ensure bias qparams are per-output-channel: | ||
| # So for example w = [w1, w2, w3] -> [w1, w2, w3, w1, w2, w3, ...] | ||
| if out_channels is not None: | ||
| weight_scale = weight_scale.flatten() | ||
| if weight_scale.numel() != out_channels: | ||
| if out_channels % weight_scale.numel() != 0: | ||
| raise RuntimeError( | ||
| "Weight qparams cannot be repeated if not divisible by `out_channels`." | ||
| ) | ||
| weight_scale = weight_scale.repeat(out_channels // weight_scale.numel()) | ||
|
|
||
| act_scale = act_scale.flatten()[0] | ||
|
|
||
| bias_scale = act_scale * weight_scale | ||
| bias_zero_point = torch.zeros_like(bias_scale, dtype=torch.int64) | ||
| return bias_scale, bias_zero_point | ||
|
|
||
|
|
||
| def get_aten_node_target_partitions( | ||
| graph: torch.fx.Graph, | ||
| wanted_original_aten_op: List[OpOverload], | ||
|
|
||
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.
Nit:
List->listto minimize imports.Same for
Tuplebelow.