-
Notifications
You must be signed in to change notification settings - Fork 741
Using generic implemntation for 16-bit activations and 8 bit weights for Conv2D in Backends #16007
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?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16007
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit d9f4835 with merge base e38734e ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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.
Pull request overview
This PR adds support for 16-bit activations with 8-bit weights (W8A16) in quantized operations for the Cadence HiFi backend. Previously, 16-bit support required both activations and weights to be 16-bit.
- Extends
quantized_linear_out,quantized_linear_per_tensor_out,quantized_conv2d_nchw_out, andquantized_conv2d_nhwc_outto handle W8A16 heterogeneous types by delegating to generic implementations - Adds comprehensive unit tests for the new W8A16 support in linear and conv2d operations
- Updates build configuration to include necessary dependencies for generic implementations
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| backends/cadence/hifi/operators/tests/test_op_quantized_linear_out.cpp | Adds unit test for quantized linear with int16 activations and int8 weights |
| backends/cadence/hifi/operators/tests/test_op_quantized_conv2d_out.cpp | Adds unit tests for quantized conv2d (NCHW/NHWC) with int16 activations and int8 weights |
| backends/cadence/hifi/operators/targets.bzl | Updates build targets to add generic implementation dependencies for W8A16 support |
| backends/cadence/hifi/operators/op_quantized_linear_out.cpp | Adds W8A16 type check and delegates to generic implementation for linear operations |
| backends/cadence/hifi/operators/op_quantized_conv2d_nhwc_out.cpp | Adds W8A16 type check and delegates to generic implementation for NHWC conv2d |
| backends/cadence/hifi/operators/op_quantized_conv2d_nchw_out.cpp | Adds W8A16 type check and delegates to generic implementation for NCHW conv2d |
| backends/cadence/aot/quantizer/quantizer.py | Adds new quantizer class for 16-bit conv activations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| else if (out.scalar_type() == executorch::aten::ScalarType::Byte) { |
Copilot
AI
Nov 28, 2025
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.
[nitpick] The else if should be on the same line as the closing brace according to standard C++ formatting conventions. Change to } else if for consistency with typical C++ style.
| } | |
| else if (out.scalar_type() == executorch::aten::ScalarType::Byte) { | |
| } else if (out.scalar_type() == executorch::aten::ScalarType::Byte) { |
| } | ||
| else if (out.scalar_type() == executorch::aten::ScalarType::Byte) { |
Copilot
AI
Nov 28, 2025
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.
[nitpick] The else if should be on the same line as the closing brace according to standard C++ formatting conventions. Change to } else if for consistency with typical C++ style.
| } | |
| else if (out.scalar_type() == executorch::aten::ScalarType::Byte) { | |
| } else if (out.scalar_type() == executorch::aten::ScalarType::Byte) { |
…for Conv2D in Backends (pytorch#16007) Summary: # Context We continue from D84284794 to add support for 16-bit activations. Note that right now, all though they support 16-bit activations already, it's only if the weights are also 16-bits. To do this, we need to change the way we template some functions. # Current Behavior Right now, we're composing two macros together, the `ET_FORALL_JARVIS_QUANTIZED_TYPES_WITH_INT16` macro: https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/operators.h?lines=22-25 and the function macro(`quantized_linear` chosen for example): https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/quantized_linear_out.cpp?lines=30-41 so together, it just becomes a switch statement, calling the `quantized_linear` function with the correct template parameter. However, note that it assumes that both the input activations and weights are the same dtype, which is not the case. # This Diff We finish by using the generic implementation for all the backends and adding e2e tests as well as unit tests. Differential Revision: D87993325
…for Conv2D in Backends (pytorch#16007) Summary: # Context We continue from D84284794 to add support for 16-bit activations. Note that right now, all though they support 16-bit activations already, it's only if the weights are also 16-bits. To do this, we need to change the way we template some functions. # Current Behavior Right now, we're composing two macros together, the `ET_FORALL_JARVIS_QUANTIZED_TYPES_WITH_INT16` macro: https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/operators.h?lines=22-25 and the function macro(`quantized_linear` chosen for example): https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/quantized_linear_out.cpp?lines=30-41 so together, it just becomes a switch statement, calling the `quantized_linear` function with the correct template parameter. However, note that it assumes that both the input activations and weights are the same dtype, which is not the case. # This Diff We finish by using the generic implementation for all the backends and adding e2e tests as well as unit tests. Differential Revision: D87993325
a8e37d4 to
dcc29dd
Compare
…for Conv2D in Backends (pytorch#16007) Summary: # Context We continue from D84284794 to add support for 16-bit activations. Note that right now, all though they support 16-bit activations already, it's only if the weights are also 16-bits. To do this, we need to change the way we template some functions. # Current Behavior Right now, we're composing two macros together, the `ET_FORALL_JARVIS_QUANTIZED_TYPES_WITH_INT16` macro: https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/operators.h?lines=22-25 and the function macro(`quantized_linear` chosen for example): https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/quantized_linear_out.cpp?lines=30-41 so together, it just becomes a switch statement, calling the `quantized_linear` function with the correct template parameter. However, note that it assumes that both the input activations and weights are the same dtype, which is not the case. # This Diff We finish by using the generic implementation for all the backends and adding e2e tests as well as unit tests. Differential Revision: D87993325
This PR needs a
|
…for Conv2D in Backends (pytorch#16007) Summary: # Context We continue from D84284794 to add support for 16-bit activations. Note that right now, all though they support 16-bit activations already, it's only if the weights are also 16-bits. To do this, we need to change the way we template some functions. # Current Behavior Right now, we're composing two macros together, the `ET_FORALL_JARVIS_QUANTIZED_TYPES_WITH_INT16` macro: https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/operators.h?lines=22-25 and the function macro(`quantized_linear` chosen for example): https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/quantized_linear_out.cpp?lines=30-41 so together, it just becomes a switch statement, calling the `quantized_linear` function with the correct template parameter. However, note that it assumes that both the input activations and weights are the same dtype, which is not the case. # This Diff We finish by using the generic implementation for all the backends and adding e2e tests as well as unit tests. Differential Revision: D87993325
dcc29dd to
7392370
Compare
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.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| define_operator("quantized_linear_out", deps=["fbcode//on_device_ai/Assistant/Jarvis/min_runtime/operators/generic:op_quantized_linear"]) | ||
| define_operator("quantized_linear_per_tensor_out", deps=["fbcode//on_device_ai/Assistant/Jarvis/min_runtime/operators/generic:op_quantized_linear"]) | ||
|
|
||
| # quantized_conv2d_nchw_out and quantized_conv2d_nhwc_out need additional dependency for int16 support |
Copilot
AI
Dec 1, 2025
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.
Incorrect indentation: This line has extra leading spaces (6 spaces) compared to the surrounding code (4 spaces). The comment should be aligned with the other comments in the file.
| # quantized_conv2d_nchw_out and quantized_conv2d_nhwc_out need additional dependency for int16 support | |
| # quantized_conv2d_nchw_out and quantized_conv2d_nhwc_out need additional dependency for int16 support |
| if (out.scalar_type() == ::executorch::aten::ScalarType::Short && | ||
| in.scalar_type() == ::executorch::aten::ScalarType::Short && | ||
| weight.scalar_type() == ::executorch::aten::ScalarType::Char) { | ||
| ::impl::generic::native::quantized_linear_out( | ||
| ctx, | ||
| in, | ||
| weight, | ||
| bias, | ||
| in_zero_point, | ||
| weight_zero_point, | ||
| out_multiplier, | ||
| out_shift, | ||
| out_zero_point, | ||
| offset, | ||
| out); |
Copilot
AI
Dec 1, 2025
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.
[nitpick] Consider adding an explicit return; statement after line 236 to make the control flow clearer and more consistent with the conv2d implementations (e.g., op_quantized_conv2d_nhwc_out.cpp:463). This would also allow changing the subsequent else if statements to simple if statements.
| if (out.scalar_type() == ::executorch::aten::ScalarType::Short && | ||
| in.scalar_type() == ::executorch::aten::ScalarType::Short && | ||
| weight.scalar_type() == ::executorch::aten::ScalarType::Char) { | ||
| ::impl::generic::native::quantized_linear_per_tensor_out( | ||
| ctx, | ||
| in, | ||
| weight, | ||
| bias, | ||
| in_zero_point, | ||
| weight_zero_point, | ||
| out_multiplier, | ||
| out_shift, | ||
| out_zero_point, | ||
| offset, | ||
| out); |
Copilot
AI
Dec 1, 2025
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.
[nitpick] Consider adding an explicit return; statement after line 293 to make the control flow clearer and more consistent with the conv2d implementations (e.g., op_quantized_conv2d_nhwc_out.cpp:463). This would also allow changing the subsequent else if statements to simple if statements.
| } | ||
| }; | ||
|
|
||
| // Test quantized_linear_out with int16 activations (asym8s) |
Copilot
AI
Dec 1, 2025
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 comment incorrectly mentions "(asym8s)" which typically refers to asymmetric 8-bit signed integers. However, this test uses int16 activations with int8 weights (W8A16). Consider updating the comment to: "Test quantized_linear_out with int16 activations and int8 weights (W8A16)"
| // Test quantized_linear_out with int16 activations (asym8s) | |
| // Test quantized_linear_out with int16 activations and int8 weights (W8A16) |
… for linear in backends (pytorch#15997) Summary: # Context We continue from D84284794 to add support for 16-bit activations. Note that right now, all though they support 16-bit activations already, it's only if the weights are also 16-bits. To do this, we need to change the way we template some functions. # Current Behavior Right now, we're composing two macros together, the `ET_FORALL_JARVIS_QUANTIZED_TYPES_WITH_INT16` macro: https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/operators.h?lines=22-25 and the function macro(`quantized_linear` chosen for example): https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/quantized_linear_out.cpp?lines=30-41 so together, it just becomes a switch statement, calling the `quantized_linear` function with the correct template parameter. However, note that it assumes that both the input activations and weights are the same dtype, which is not the case. # This Diff We finish by using the generic implementation for all the backends and adding e2e tests as well as unit tests. Reviewed By: hsharma35 Differential Revision: D87946776
…for Conv2D in Backends (pytorch#16007) Summary: # Context We continue from D84284794 to add support for 16-bit activations. Note that right now, all though they support 16-bit activations already, it's only if the weights are also 16-bits. To do this, we need to change the way we template some functions. # Current Behavior Right now, we're composing two macros together, the `ET_FORALL_JARVIS_QUANTIZED_TYPES_WITH_INT16` macro: https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/operators.h?lines=22-25 and the function macro(`quantized_linear` chosen for example): https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/quantized_linear_out.cpp?lines=30-41 so together, it just becomes a switch statement, calling the `quantized_linear` function with the correct template parameter. However, note that it assumes that both the input activations and weights are the same dtype, which is not the case. # This Diff We finish by using the generic implementation for all the backends and adding e2e tests as well as unit tests. Reviewed By: hsharma35 Differential Revision: D87993325
7392370 to
d9f4835
Compare
Summary:
Context
We continue from D84284794 to add support for 16-bit activations. Note that right now, all though they support 16-bit activations already, it's only if the weights are also 16-bits. To do this, we need to change the way we template some functions.
Current Behavior
Right now, we're composing two macros together, the
ET_FORALL_JARVIS_QUANTIZED_TYPES_WITH_INT16macro:https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/operators.h?lines=22-25
and the function macro(
quantized_linearchosen for example):https://www.internalfb.com/code/fbsource/[9e8c6d8466107f58aa3de1b9e4ec71c49d670a8f]/fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/quantized_linear_out.cpp?lines=30-41
so together, it just becomes a switch statement, calling the
quantized_linearfunction with the correct template parameter.However, note that it assumes that both the input activations and weights are the same dtype, which is not the case.
This Diff
We finish by using the generic implementation for all the backends and adding e2e tests as well as unit tests.
Differential Revision: D87993325