-
Notifications
You must be signed in to change notification settings - Fork 742
Using generic implementation for 16-bit activations and 8 bit weights for linear in backends #15997
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| #include <executorch/backends/cadence/hifi/kernels/kernels.h> | ||
| #include <executorch/backends/cadence/hifi/operators/operators.h> | ||
| #include <executorch/runtime/kernel/kernel_includes.h> | ||
| #include <on_device_ai/Assistant/Jarvis/min_runtime/operators/generic/op_quantized_linear.h> | ||
| #include <xa_nnlib_kernels_api.h> | ||
| #include <xtensa/tie/xt_datacache.h> | ||
| #include <algorithm> | ||
|
|
@@ -218,7 +219,22 @@ void quantized_linear_out( | |
| int64_t out_zero_point, | ||
| __ET_UNUSED const optional<Tensor>& offset, | ||
| Tensor& out) { | ||
| if (out.scalar_type() == executorch::aten::ScalarType::Byte) { | ||
| 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); | ||
| } else if (out.scalar_type() == executorch::aten::ScalarType::Byte) { | ||
| _quantized_linear_asym8u( | ||
| in, | ||
| weight, | ||
|
|
@@ -260,7 +276,22 @@ void quantized_linear_per_tensor_out( | |
| int64_t out_zero_point, | ||
| __ET_UNUSED const optional<Tensor>& offset, | ||
| Tensor& out) { | ||
| if (out.scalar_type() == executorch::aten::ScalarType::Byte) { | ||
| 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); | ||
| } else if (out.scalar_type() == executorch::aten::ScalarType::Byte) { | ||
|
Comment on lines
+279
to
+294
|
||
| _quantized_linear_per_tensor_asym8u( | ||
| in, | ||
| weight, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -87,7 +87,6 @@ OPERATORS = [ | |||
| "quantized_fully_connected_asym8sxasym8s_asym8s_per_tensor_out", | ||||
| "quantized_fully_connected_asym8uxasym8u_asym8u_per_tensor_out", | ||||
| "quantized_layer_norm", | ||||
| "quantized_linear_out", | ||||
| "quantized_linear_asym8sxasym8s_asym8s_per_tensor_out", | ||||
| "quantized_linear_asym8uxasym8u_asym8u_per_tensor_out", | ||||
| "quantized_matmul_out", | ||||
|
|
@@ -122,3 +121,7 @@ def define_common_targets(): | |||
| # Define build targets for all operators registered in the tables above. | ||||
| for op in OPERATORS: | ||||
| define_operator(op) | ||||
|
|
||||
| # quantized_linear_out and quantized_linear_per_tensor_out needs additional dependency for int16 support | ||||
| 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"]) | ||||
|
||||
| define_operator("quantized_linear_per_tensor_out", deps=["fbcode//on_device_ai/Assistant/Jarvis/min_runtime/operators/generic:op_quantized_linear"]) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,132 @@ | ||||||
| /* | ||||||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||||||
| * All rights reserved. | ||||||
| * | ||||||
| * This source code is licensed under the BSD-style license found in the | ||||||
| * LICENSE file in the root directory of this source tree. | ||||||
| */ | ||||||
|
|
||||||
| #include <gtest/gtest.h> | ||||||
| #include <sys/times.h> | ||||||
|
|
||||||
| #include <executorch/kernels/test/TestUtil.h> | ||||||
| #include <executorch/runtime/core/error.h> | ||||||
| #include <executorch/runtime/core/exec_aten/exec_aten.h> | ||||||
| #include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h> | ||||||
| #include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h> | ||||||
| #include <executorch/runtime/platform/runtime.h> | ||||||
|
|
||||||
| #include <executorch/backends/cadence/hifi/operators/operators.h> | ||||||
|
|
||||||
| namespace impl { | ||||||
| namespace HiFi { | ||||||
| namespace native { | ||||||
| namespace { | ||||||
|
|
||||||
| using ::executorch::aten::Scalar; | ||||||
| using ::executorch::aten::ScalarType; | ||||||
| using ::executorch::aten::Tensor; | ||||||
| using ::executorch::aten::TensorImpl; | ||||||
| using ::executorch::runtime::Error; | ||||||
| using ::executorch::runtime::KernelRuntimeContext; | ||||||
| using ::executorch::runtime::runtime_init; | ||||||
| using ::executorch::runtime::testing::TensorFactory; | ||||||
| using std::optional; | ||||||
| using std::string_view; | ||||||
|
|
||||||
| class HiFiQuantizedLinearTest : public OperatorTest { | ||||||
| public: | ||||||
| protected: | ||||||
| void quantized_linear_out( | ||||||
| const Tensor& input, | ||||||
| const Tensor& weight, | ||||||
| const Tensor& bias, | ||||||
| int64_t in_zero_point, | ||||||
| const Tensor& weight_zero_point, | ||||||
| const Tensor& out_multiplier, | ||||||
| const Tensor& out_shift, | ||||||
| int64_t out_zero_point, | ||||||
| const optional<Tensor>& offset, | ||||||
| Tensor& output) { | ||||||
| return ::impl::HiFi::native::quantized_linear_out( | ||||||
| context_, | ||||||
| input, | ||||||
| weight, | ||||||
| bias, | ||||||
| in_zero_point, | ||||||
| weight_zero_point, | ||||||
| out_multiplier, | ||||||
| out_shift, | ||||||
| out_zero_point, | ||||||
| offset, | ||||||
| output); | ||||||
| } | ||||||
|
|
||||||
| void quantized_linear_per_tensor_out( | ||||||
| const Tensor& input, | ||||||
| const Tensor& weight, | ||||||
| const Tensor& bias, | ||||||
| int64_t in_zero_point, | ||||||
| int64_t weight_zero_point, | ||||||
| int64_t out_multiplier, | ||||||
| int64_t out_shift, | ||||||
| int64_t out_zero_point, | ||||||
| const optional<Tensor>& offset, | ||||||
| Tensor& output) { | ||||||
| return ::impl::HiFi::native::quantized_linear_per_tensor_out( | ||||||
| context_, | ||||||
| input, | ||||||
| weight, | ||||||
| bias, | ||||||
| in_zero_point, | ||||||
| weight_zero_point, | ||||||
| out_multiplier, | ||||||
| out_shift, | ||||||
| out_zero_point, | ||||||
| offset, | ||||||
| output); | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| // Test quantized_linear_out with int16 activations (asym8s) | ||||||
|
||||||
| // Test quantized_linear_out with int16 activations (asym8s) | |
| // Test quantized_linear_out with int16 activations and int8 weights |
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.
Inconsistent namespace qualification. Lines 222-224 use fully qualified
::executorch::aten::ScalarType::while line 237 uses justexecutorch::aten::ScalarType::(without leading::). For consistency and clarity, use the same namespace qualification pattern throughout the function. The fully qualified form (with leading::) is preferred to avoid potential ambiguity.