Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/35985 This PR is one of steps to extend 8-bit quantization to support symmetric 16-bit activations. Each activation is of type int16 and symmetric around zero. The weight tensor precision remains at 8-bit signed values. The bias is set to int64 precision. In this PR we introduce implementation and tests for ADD/SUB kernel reference function. The specification of this operator: SUB Input 0: data_type : int16 range : [-32768, 32767] granularity: per-tensor, zero_point=0 Input 1: data_type : int16 range : [-32768, 32767] granularity: per-tensor, zero_point=0 Output 0: data_type : int16 range : [-32768, 32767] granularity: per-tensor, zero_point=0 ADD Input 0: data_type : int16 range : [-32768, 32767] granularity: per-tensor, zero_point=0 Input 1: data_type : int16 range : [-32768, 32767] granularity: per-tensor, zero_point=0 Output 0: data_type : int16 range : [-32768, 32767] granularity: per-tensor, zero_point=0 Copybara import of the project: --b94cb4732a
by Elena Zhelezina <elena.zhelezina@arm.com>: Added 16-bit version of ADD/SUB operators. Broadcasting is included. --924d0b72c5
by Elena Zhelezina <elena.zhelezina@arm.com>: Addressed reviewer comments. --dd0d9e8f03
by Elena Zhelezina <elena.zhelezina@arm.com>: Added versioning to ADD/SUB + some rework of the existing code. --abae3fd9a9
by Elena Zhelezina <elena.zhelezina@arm.com>: Added versioning for ADD/SUB with new option in the schema.fbs schema_generated.h is edited manually. --24f3f5593a
by Elena Zhelezina <elena.zhelezina@arm.com>: Fix for broken build. --d252fe175a
by Elena Zhelezina <elena.zhelezina@arm.com>: Fix for the failing internal test for NN delegates. --2223a5c380
by Elena Zhelezina <elena.zhelezina@arm.com>: Fix for asan failures. Change-Id: I2cf421ddda7f9e802202239136ab062bcd63b4aa --3c219a46ce
by Elena Zhelezina <elena.zhelezina@arm.com>: Added broadcast params to addsub structure. Change-Id: I61d7d4a94087d052a782890799211031f6ed3015 --9131a38c77
by Elena Zhelezina <elena.zhelezina@arm.com>: Corrected defaults. Change-Id: I9ea50c75014cc03ac91fdef0f5b4fe11395f7074 PiperOrigin-RevId: 324865496
89 lines
2.5 KiB
C++
89 lines
2.5 KiB
C++
/* Copyright 2019 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_TOOLS_VERSIONING_OP_VERSION_H_
|
|
#define TENSORFLOW_LITE_TOOLS_VERSIONING_OP_VERSION_H_
|
|
|
|
#include <vector>
|
|
|
|
#include "tensorflow/lite/schema/mutable/schema_generated.h"
|
|
|
|
namespace tflite {
|
|
|
|
// OpSignature contains operator parameters for version functions.
|
|
typedef struct {
|
|
BuiltinOperator op;
|
|
std::vector<TensorType> input_types;
|
|
std::vector<TensorType> output_types;
|
|
union {
|
|
struct {
|
|
int32_t dilation_w_factor;
|
|
int32_t dilation_h_factor;
|
|
bool is_per_channel_quantized;
|
|
} depthwise_conv_2d;
|
|
struct {
|
|
bool narrow_range;
|
|
} fakequant;
|
|
struct {
|
|
bool keep_num_dims;
|
|
FullyConnectedOptionsWeightsFormat weights_format;
|
|
// TODO(b/156530611): Make this global when more ops support sparse
|
|
// computation.
|
|
bool sparse_weight;
|
|
bool asymmetric_quantize_inputs;
|
|
} fully_connected;
|
|
struct {
|
|
float input1_scale;
|
|
float input2_scale;
|
|
float output_scale;
|
|
} mul;
|
|
struct {
|
|
LSTMKernelType kernel_type;
|
|
bool asymmetric_quantize_inputs;
|
|
} lstm;
|
|
struct {
|
|
bool half_pixel_centers;
|
|
bool align_corners;
|
|
} resize;
|
|
struct {
|
|
int32_t num_dims;
|
|
} single_input_op;
|
|
struct {
|
|
int32_t num_dims;
|
|
bool need_broadcast;
|
|
} broadcast;
|
|
struct {
|
|
bool pot_scale_int16;
|
|
int32_t num_dims;
|
|
bool need_broadcast;
|
|
} addsub;
|
|
struct {
|
|
bool is_per_channel_quantized;
|
|
} conv_2d;
|
|
struct {
|
|
bool asymmetric_quantize_inputs;
|
|
} input_quantization;
|
|
} options;
|
|
} OpSignature;
|
|
|
|
// Returns version of builtin ops by the given signature.
|
|
int GetBuiltinOperatorVersion(const OpSignature& op_sig);
|
|
|
|
// Update operator's version of the given TFL flatbuffer model.
|
|
void UpdateOpVersion(uint8_t* model_buffer_pointer);
|
|
|
|
} // namespace tflite
|
|
|
|
#endif // TENSORFLOW_LITE_TOOLS_VERSIONING_OP_VERSION_H_
|