-
Couldn't load subscription status.
- Fork 701
[ET-VK][Ops] dequantize ops skeleton test framework #11480
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
57b311a
[ET-VK][Ops] dequantize ops skeleton test framework
0405f9f
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
9674a13
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
48738a6
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
70c0e79
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
cbc4dd2
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
7c95b40
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
1f2ff32
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
4a3add0
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
d330d23
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
44c1328
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
b0ca7eb
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
8005443
Update on "[ET-VK][Ops] dequantize ops skeleton test framework"
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| /* | ||
| * 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 <ATen/ATen.h> | ||
|
|
||
| #include <executorch/backends/vulkan/runtime/api/api.h> | ||
| #include <executorch/backends/vulkan/runtime/graph/ComputeGraph.h> | ||
| #include <executorch/backends/vulkan/runtime/graph/ops/OperatorRegistry.h> | ||
|
|
||
| #include <executorch/extension/aten_util/make_aten_functor_from_et_functor.h> | ||
| #include <executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h> | ||
|
|
||
| #include "test_utils.h" | ||
|
|
||
| #include <cassert> | ||
| #include <iostream> | ||
|
|
||
| namespace torch { | ||
| namespace executor { | ||
| namespace native { | ||
|
|
||
| // Forward declarations of the functions we're testing | ||
| Tensor& dequantize_per_tensor_out( | ||
| const Tensor& input, | ||
| double scale, | ||
| int64_t zero_point, | ||
| int64_t quant_min, | ||
| int64_t quant_max, | ||
| ScalarType dtype, | ||
| executorch::aten::optional<ScalarType> out_dtype, | ||
| Tensor& out); | ||
|
|
||
| Tensor& dequantize_per_token_out( | ||
| const Tensor& input, | ||
| const Tensor& scale, | ||
| const Tensor& zero_points, | ||
| int64_t quant_min, | ||
| int64_t quant_max, | ||
| ScalarType dtype, | ||
| ScalarType out_dtype, | ||
| Tensor& out); | ||
|
|
||
| // Wrapper function for dequantize_per_tensor_out without context | ||
| Tensor& dequantize_per_tensor_out_no_context( | ||
| const Tensor& input, | ||
| double scale, | ||
| int64_t zero_point, | ||
| int64_t quant_min, | ||
| int64_t quant_max, | ||
| ScalarType dtype, | ||
| executorch::aten::optional<ScalarType> out_dtype, | ||
| Tensor& out) { | ||
| return torch::executor::native::dequantize_per_tensor_out( | ||
| input, scale, zero_point, quant_min, quant_max, dtype, out_dtype, out); | ||
| } | ||
|
|
||
| // Wrapper function for dequantize_per_token_out without context | ||
| Tensor& dequantize_per_token_out_no_context( | ||
| const Tensor& input, | ||
| const Tensor& scale, | ||
| const Tensor& zero_points, | ||
| int64_t quant_min, | ||
| int64_t quant_max, | ||
| ScalarType dtype, | ||
| ScalarType out_dtype, | ||
| Tensor& out) { | ||
| return torch::executor::native::dequantize_per_token_out( | ||
| input, scale, zero_points, quant_min, quant_max, dtype, out_dtype, out); | ||
| } | ||
|
|
||
| // ATen wrapper for dequantize_per_tensor | ||
| at::Tensor dequantize_per_tensor_aten( | ||
| const at::Tensor& input, | ||
| double scale, | ||
| int64_t zero_point, | ||
| int64_t quant_min, | ||
| int64_t quant_max, | ||
| at::ScalarType dtype, | ||
| at::ScalarType out_dtype) { | ||
| auto out = at::empty_like(input, out_dtype); | ||
| // Convert at::ScalarType to executorch::ScalarType | ||
| ScalarType et_dtype = at_scalartype_to_et_scalartype(dtype); | ||
| ScalarType et_out_dtype = at_scalartype_to_et_scalartype(out_dtype); | ||
|
|
||
| executorch::aten::optional<ScalarType> opt_et_out_dtype(et_out_dtype); | ||
|
|
||
| WRAP_TO_ATEN(dequantize_per_tensor_out_no_context, 7) | ||
| (input, | ||
| scale, | ||
| zero_point, | ||
| quant_min, | ||
| quant_max, | ||
| et_dtype, | ||
| opt_et_out_dtype, | ||
| out); | ||
| return out; | ||
| } | ||
|
|
||
| // ATen wrapper for dequantize_per_token | ||
| at::Tensor dequantize_per_token_aten( | ||
| const at::Tensor& input, | ||
| const at::Tensor& scale, | ||
| const at::Tensor& zero_points, | ||
| int64_t quant_min, | ||
| int64_t quant_max, | ||
| at::ScalarType dtype, | ||
| at::ScalarType out_dtype) { | ||
| auto out = at::empty_like(input, out_dtype); | ||
| // Convert at::ScalarType to executorch::ScalarType | ||
| ScalarType et_dtype = at_scalartype_to_et_scalartype(dtype); | ||
| ScalarType et_out_dtype = at_scalartype_to_et_scalartype(out_dtype); | ||
|
|
||
| WRAP_TO_ATEN(dequantize_per_token_out_no_context, 7) | ||
| (input, | ||
| scale, | ||
| zero_points, | ||
| quant_min, | ||
| quant_max, | ||
| et_dtype, | ||
| et_out_dtype, | ||
| out); | ||
| return out; | ||
| } | ||
|
|
||
| } // namespace native | ||
| } // namespace executor | ||
| } // namespace torch | ||
|
|
||
| void check_dequantize_args( | ||
| int64_t quant_min, | ||
| int64_t quant_max, | ||
| c10::ScalarType in_dtype, | ||
| c10::ScalarType out_dtype) { | ||
| using namespace vkcompute; | ||
|
|
||
| // Check that quant_min <= quant_max | ||
| VK_CHECK_COND( | ||
| quant_min <= quant_max, | ||
| "quant_min must be <= quant_max, got quant_min: ", | ||
| quant_min, | ||
| " quant_max: ", | ||
| quant_max); | ||
|
|
||
| // Check that input dtype is a quantized type | ||
| switch (in_dtype) { | ||
| case c10::kByte: | ||
| case c10::kChar: | ||
| case c10::kShort: | ||
| case c10::kInt: | ||
| case c10::kLong: | ||
| break; | ||
| default: | ||
| VK_THROW( | ||
| "Unsupported input dtype: ", | ||
| scalar_type_name(in_dtype), | ||
| " (", | ||
| static_cast<int>(in_dtype), | ||
| ")"); | ||
| } | ||
|
|
||
| // Check that output dtype is a floating point type | ||
| switch (out_dtype) { | ||
| case c10::kHalf: | ||
| case c10::kFloat: | ||
| case c10::kDouble: | ||
| break; | ||
| default: | ||
| VK_THROW( | ||
| "Unsupported output dtype: ", | ||
| scalar_type_name(out_dtype), | ||
| " (", | ||
| static_cast<int>(out_dtype), | ||
| ")"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you use this conversion here two times, and also in the quantized tests, please refactor into a utility function