-
Notifications
You must be signed in to change notification settings - Fork 929
PACK/UNPACK update #3175
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
PACK/UNPACK update #3175
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
/* Copyright 2025 The TensorFlow Authors. All Rights Reserved. | ||
|
||
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. Please leave the year the file originated. |
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -110,44 +110,11 @@ void TestPackThreeInputsFloat(int* input1_dims_data, const float* input1_data, | |
1e-5f, output_data); | ||
} | ||
|
||
void TestPackTwoInputsQuantized( | ||
int* input1_dims_data, const int8_t* input1_data, int* input2_dims_data, | ||
const int8_t* input2_data, int axis, int* output_dims_data, | ||
const int8_t* expected_output_data, int8_t* output_data) { | ||
TfLiteIntArray* input1_dims = IntArrayFromInts(input1_dims_data); | ||
TfLiteIntArray* input2_dims = IntArrayFromInts(input2_dims_data); | ||
TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data); | ||
const int output_dims_count = ElementCount(*output_dims); | ||
|
||
constexpr int input_size = 2; | ||
constexpr int output_size = 1; | ||
constexpr int tensors_size = input_size + output_size; | ||
TfLiteTensor tensors[tensors_size] = { | ||
// CreateQuantizedTensor needs scale/zero_point values as input, but these | ||
// values don't matter as to the functionality of PACK, so just set as 1.0 | ||
// and 128. | ||
CreateQuantizedTensor(input1_data, input1_dims, 1.0, 128), | ||
CreateQuantizedTensor(input2_data, input2_dims, 1.0, 128), | ||
CreateQuantizedTensor(output_data, output_dims, 1.0, 128)}; | ||
|
||
TfLitePackParams builtin_data = { | ||
.values_count = 2, | ||
.axis = axis, | ||
}; | ||
int inputs_array_data[] = {2, 0, 1}; | ||
TfLiteIntArray* inputs_array = IntArrayFromInts(inputs_array_data); | ||
int outputs_array_data[] = {1, 2}; | ||
TfLiteIntArray* outputs_array = IntArrayFromInts(outputs_array_data); | ||
|
||
ValidatePackGoldens(tensors, tensors_size, builtin_data, inputs_array, | ||
outputs_array, expected_output_data, output_dims_count, | ||
1e-5f, output_data); | ||
} | ||
|
||
void TestPackTwoInputsQuantized32( | ||
int* input1_dims_data, const int32_t* input1_data, int* input2_dims_data, | ||
const int32_t* input2_data, int axis, int* output_dims_data, | ||
const int32_t* expected_output_data, int32_t* output_data) { | ||
template <typename T> | ||
void TestPackTwoInputs(int* input1_dims_data, const T* input1_data, | ||
int* input2_dims_data, const T* input2_data, int axis, | ||
int* output_dims_data, const T* expected_output_data, | ||
T* output_data) { | ||
TfLiteIntArray* input1_dims = IntArrayFromInts(input1_dims_data); | ||
TfLiteIntArray* input2_dims = IntArrayFromInts(input2_dims_data); | ||
TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data); | ||
|
@@ -227,7 +194,7 @@ TF_LITE_MICRO_TEST(PackFloatThreeInputsNegativeAxis) { | |
input3_values, axis, output_shape, golden, output_data); | ||
} | ||
|
||
TF_LITE_MICRO_TEST(PackFloatMultilDimensions) { | ||
TF_LITE_MICRO_TEST(PackFloatMultiDimensions) { | ||
int input_shape[] = {2, 2, 3}; | ||
int output_shape[] = {3, 2, 2, 3}; | ||
const float input1_values[] = {1, 2, 3, 4, 5, 6}; | ||
|
@@ -242,7 +209,7 @@ TF_LITE_MICRO_TEST(PackFloatMultilDimensions) { | |
output_shape, golden, output_data); | ||
} | ||
|
||
TF_LITE_MICRO_TEST(PackQuantizedMultilDimensions) { | ||
TF_LITE_MICRO_TEST(PackInt8MultiDimensions) { | ||
int input_shape[] = {2, 2, 3}; | ||
int output_shape[] = {3, 2, 2, 3}; | ||
const int8_t input1_values[] = {1, 2, 3, 4, 5, 6}; | ||
|
@@ -252,12 +219,27 @@ TF_LITE_MICRO_TEST(PackQuantizedMultilDimensions) { | |
constexpr int output_dims_count = 12; | ||
int8_t output_data[output_dims_count]; | ||
|
||
tflite::testing::TestPackTwoInputsQuantized( | ||
tflite::testing::TestPackTwoInputs<int8_t>(input_shape, input1_values, | ||
input_shape, input2_values, axis, | ||
output_shape, golden, output_data); | ||
} | ||
|
||
TF_LITE_MICRO_TEST(PackInt16MultiDimensions) { | ||
int input_shape[] = {2, 2, 3}; | ||
int output_shape[] = {3, 2, 2, 3}; | ||
const int16_t input1_values[] = {1, 2, 3, 4, 5, 6}; | ||
const int16_t input2_values[] = {7, 8, 9, 10, 11, 12}; | ||
const int16_t golden[] = {1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12}; | ||
const int axis = 1; | ||
constexpr int output_dims_count = 12; | ||
int16_t output_data[output_dims_count]; | ||
|
||
tflite::testing::TestPackTwoInputs<int16_t>( | ||
input_shape, input1_values, input_shape, input2_values, axis, | ||
output_shape, golden, output_data); | ||
} | ||
|
||
TF_LITE_MICRO_TEST(PackQuantized32MultilDimensions) { | ||
TF_LITE_MICRO_TEST(PackInt32MultiDimensions) { | ||
int input_shape[] = {2, 2, 3}; | ||
int output_shape[] = {3, 2, 2, 3}; | ||
const int32_t input1_values[] = {1, 2, 3, 4, 5, 6}; | ||
|
@@ -267,7 +249,7 @@ TF_LITE_MICRO_TEST(PackQuantized32MultilDimensions) { | |
constexpr int output_dims_count = 12; | ||
int32_t output_data[output_dims_count]; | ||
|
||
tflite::testing::TestPackTwoInputsQuantized32( | ||
tflite::testing::TestPackTwoInputs<int32_t>( | ||
input_shape, input1_values, input_shape, input2_values, axis, | ||
output_shape, golden, output_data); | ||
} | ||
|
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
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.
Please leave the year the file originated.