提交 ffd3326d 编写于 作者: A Alan Kelly 提交者: TensorFlower Gardener

Cast Int4->Float32 bench

PiperOrigin-RevId: 561274977
上级 c4f212a0
......@@ -1292,12 +1292,28 @@ cc_test(
],
)
cc_library(
name = "cast_test_common",
testonly = 1,
hdrs = [
"cast_test_common.h",
],
deps = [
":test_util",
"//tensorflow/lite:string",
"//tensorflow/lite/schema:schema_fbs",
"@com_google_absl//absl/types:span",
"@flatbuffers",
],
)
cc_test(
name = "cast_test",
size = "small",
srcs = ["cast_test.cc"],
tags = ["tflite_nnapi"],
deps = [
":cast_test_common",
":test_main",
":test_util",
"//tensorflow/lite/core/c:c_api_types",
......
......@@ -24,6 +24,7 @@ limitations under the License.
#include "absl/types/span.h"
#include "flatbuffers/flatbuffers.h" // from @flatbuffers
#include "tensorflow/lite/core/c/c_api_types.h"
#include "tensorflow/lite/kernels/cast_test_common.h"
#include "tensorflow/lite/kernels/test_util.h"
#include "tensorflow/lite/schema/schema_generated.h"
......@@ -32,28 +33,6 @@ namespace {
using ::testing::ElementsAreArray;
class CastOpModel : public SingleOpModel {
public:
CastOpModel(const TensorData& input, const TensorData& output) {
input_ = AddInput(input);
output_ = AddOutput(output);
SetBuiltinOp(BuiltinOperator_CAST, BuiltinOptions_CastOptions,
CreateCastOptions(builder_).Union());
BuildInterpreter({GetShape(input_)});
}
void Set4BitInput(absl::Span<const int8_t> f) {
PopulateTensor4bit(input_, 0, f.data(), f.data() + f.size());
}
int input() const { return input_; }
int output() const { return output_; }
protected:
int input_;
int output_;
};
TEST(CastOpModel, CastInt4ToFloat) {
CastOpModel m({TensorType_INT4, {2, 3}}, {TensorType_FLOAT32, {2, 3}});
m.Set4BitInput({1, 2, 3, 4, 5, 6});
......
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_KERNELS_CAST_TEST_COMMON_H_
#define TENSORFLOW_LITE_KERNELS_CAST_TEST_COMMON_H_
#include <stdint.h>
#include <vector>
#include "absl/types/span.h"
#include "tensorflow/lite/kernels/test_util.h"
#include "tensorflow/lite/schema/schema_generated.h"
namespace tflite {
using ::testing::ElementsAreArray;
class CastOpModel : public SingleOpModel {
public:
CastOpModel(const TensorData& input, const TensorData& output) {
input_ = AddInput(input);
output_ = AddOutput(output);
SetBuiltinOp(BuiltinOperator_CAST, BuiltinOptions_CastOptions,
CreateCastOptions(builder_).Union());
BuildInterpreter({GetShape(input_)});
}
void Set4BitInput(absl::Span<const int8_t> f) {
PopulateTensor4bit(input_, 0, f.data(), f.data() + f.size());
}
int input() const { return input_; }
int output() const { return output_; }
protected:
int input_;
int output_;
};
} // namespace tflite
#endif // TENSORFLOW_LITE_KERNELS_CAST_TEST_COMMON_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册