Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[TFLite FE] Dequantize to op float type for fp16 models (#36186)

Maxim Vafin496d9260e82a
diff --git a/src/frontends/tensorflow_lite/src/op/op_translation_utils.hpp b/src/frontends/tensorflow_lite/src/op/op_translation_utils.hpp
index b6a781bc0d6..1062403ffff 100644
--- a/src/frontends/tensorflow_lite/src/op/op_translation_utils.hpp
+++ b/src/frontends/tensorflow_lite/src/op/op_translation_utils.hpp
@@ -51,7 +51,7 @@ template <typename OV_TYPE>
OutputVector translate_binary_op_with_activation(const ov::frontend::tensorflow_lite::NodeContext& node) {
auto fused_activation_function = node.get_attribute<std::string>("fused_activation_function");
auto inputs = node.get_inputs();
- ov::frontend::tensorflow_lite::dequantize_inputs(inputs);
+ ov::frontend::tensorflow_lite::dequantize_inputs(inputs, node.get_decoder());
auto context = ov::frontend::tensorflow_lite::NodeContext(node.get_decoder(), inputs);
auto output = ov::frontend::tensorflow::op::translate_binary_op<OV_TYPE>(context);
output[0].get_node()->set_friendly_name("");
@@ -73,7 +73,7 @@ template OutputVector translate_binary_op_with_activation<opset10::Divide>(
template <typename OV_TYPE>
OutputVector translate_reduce_op(const ov::frontend::tensorflow_lite::NodeContext& node) {
auto inputs = node.get_inputs();
- ov::frontend::tensorflow_lite::dequantize_inputs(inputs);
+ ov::frontend::tensorflow_lite::dequantize_inputs(inputs, node.get_decoder());
auto context = ov::frontend::tensorflow_lite::NodeContext(node.get_decoder(), inputs);
auto outputs = ov::frontend::tensorflow::op::translate_direct_reduce_op<OV_TYPE>(context);
del_output_names(outputs);
diff --git a/src/frontends/tensorflow_lite/src/op_table.cpp b/src/frontends/tensorflow_lite/src/op_table.cpp
index 679b9351bfe..11d3d5343a0 100644
--- a/src/frontends/tensorflow_lite/src/op_table.cpp
+++ b/src/frontends/tensorflow_lite/src/op_table.cpp
@@ -15,7 +15,7 @@ using namespace ov::frontend::tensorflow::op;
[](const ov::frontend::tensorflow_lite::NodeContext& node) -> OutputVector { \
auto decoder = node.get_decoder(); \
auto inputs = node.get_inputs(); \
- ov::frontend::tensorflow_lite::dequantize_inputs(inputs); \
+ ov::frontend::tensorflow_lite::dequantize_inputs(inputs, decoder); \
auto context = ov::frontend::tensorflow_lite::NodeContext(decoder, inputs); \
return func(context); \
}
@@ -24,7 +24,7 @@ using namespace ov::frontend::tensorflow::op;
[](const ov::frontend::tensorflow_lite::NodeContext& node) -> OutputVector { \
auto decoder = node.get_decoder(); \
auto inputs = node.get_inputs(); \
- ov::frontend::tensorflow_lite::dequantize_inputs(inputs); \
+ ov::frontend::tensorflow_lite::dequantize_inputs(inputs, decoder); \
auto context = frontend::tensorflow_lite::NodeContext(decoder, inputs); \
return get_indexed_outputs(func(context)); \
}
diff --git a/src/frontends/tensorflow_lite/src/op_table.hpp b/src/frontends/tensorflow_lite/src/op_table.hpp
index fc7e681dced..6165b750da7 100644
--- a/src/frontends/tensorflow_lite/src/op_table.hpp
+++ b/src/frontends/tensorflow_lite/src/op_table.hpp
@@ -54,7 +54,7 @@ OutputVector translate_reduce_op(const ov::frontend::tensorflow_lite::NodeContex
template <typename OV_TYPE>
OutputVector translate_unary(const ov::frontend::tensorflow_lite::NodeContext& node) {
auto inputs = node.get_inputs();
- ov::frontend::tensorflow_lite::dequantize_inputs(inputs);
+ ov::frontend::tensorflow_lite::dequantize_inputs(inputs, node.get_decoder());
auto context = ov::frontend::tensorflow_lite::NodeContext(node.get_decoder(), inputs);
return ov::frontend::tensorflow::op::translate_unary_op<OV_TYPE>(context);
}
@@ -62,7 +62,7 @@ OutputVector translate_unary(const ov::frontend::tensorflow_lite::NodeContext& n
template <typename OV_TYPE>
OutputVector translate_binary(const ov::frontend::tensorflow_lite::NodeContext& node) {
auto inputs = node.get_inputs();
- ov::frontend::tensorflow_lite::dequantize_inputs(inputs);
+ ov::frontend::tensorflow_lite::dequantize_inputs(inputs, node.get_decoder());
auto context = ov::frontend::tensorflow_lite::NodeContext(node.get_decoder(), inputs);
return ov::frontend::tensorflow::op::translate_binary_op<OV_TYPE>(context);
}
diff --git a/src/frontends/tensorflow_lite/src/tflite_transformations/tflite_quantize_resolver.cpp b/src/frontends/tensorflow_lite/src/tflite_transformations/tflite_quantize_resolver.cpp
index 48b8ffbd911..a66c14ac1a9 100644
--- a/src/frontends/tensorflow_lite/src/tflite_transformations/tflite_quantize_resolver.cpp
+++ b/src/frontends/tensorflow_lite/src/tflite_transformations/tflite_quantize_resolver.cpp
@@ -41,7 +41,7 @@ pass::TFLQuantizeConvert::TFLQuantizeConvert() {
if (!convert)
return false;
auto type = convert->get_destination_type();
- if (type != element::f32)
+ if (!type.is_real())
return false;
auto tfl_quantize = ov::as_type_ptr<TFLQuantize>(tfl_quantize_node);
if (!tfl_quantize)
@@ -49,7 +49,7 @@ pass::TFLQuantizeConvert::TFLQuantizeConvert() {
const auto replace_f32_convert = [](const std::shared_ptr<v0::Convert>& consumer_convert,
const std::shared_ptr<TFLQuantize>& producer) -> bool {
- if (!consumer_convert || consumer_convert->get_destination_type() != element::f32)
+ if (!consumer_convert || !consumer_convert->get_destination_type().is_real())
return false;
consumer_convert->input(0).replace_source_output(producer->output(0));
consumer_convert->output(0).replace(producer->output(0));
@@ -176,7 +176,7 @@ pass::TFLQuantizeReplacer::TFLQuantizeReplacer() {
const auto is_constant =
ov::is_type<v0::Constant>(tfl_quantize->get_input_node_shared_ptr(0)); // for Constant case
- FRONT_END_GENERAL_CHECK(in_type == out_type || in_type == element::f32 || out_type == element::f32,
+ FRONT_END_GENERAL_CHECK(in_type == out_type || in_type.is_real() || out_type.is_real(),
"TFLQuantized types do not match: in_type = ",
in_type,
" out_type = ",
@@ -195,18 +195,22 @@ pass::TFLQuantizeReplacer::TFLQuantizeReplacer() {
const auto& scale_node = v0::Constant::create(element::f32, scale_shape, scale);
if (is_constant) {
+ // Dequantize constant weights directly into the requested floating type (f32 for typical
+ // models, f16 for fully float16 models) so the produced constant matches the consuming op.
+ const auto deq_type = out_type.is_real() ? out_type : element::f32;
+ const auto& const_scale = v0::Constant::create(deq_type, scale_shape, scale);
fuse_zp_to_weights(output, zp, zp_shape);
ov::Output<ov::Node> zp_input;
if (std::any_of(zp.begin(), zp.end(), [](const int64_t& i) {
return i != 0;
})) {
- zp_input = zp_node;
+ zp_input = v0::Constant::create(deq_type, zp_shape, zp);
}
- output = ov::decomposition::low_precision_dequantize(output, scale_node, zp_input);
+ output = ov::decomposition::low_precision_dequantize(output, const_scale, zp_input);
tfl_quantize->output(0).replace(output);
return true;
}
- if (in_type != element::f32) {
+ if (!in_type.is_real()) {
output = make_shared<v0::Convert>(output, element::f32);
}
@@ -221,9 +225,9 @@ pass::TFLQuantizeReplacer::TFLQuantizeReplacer() {
Output<Node> input_low, input_high, output_low, output_high;
- if (out_type != element::f32) {
+ if (!out_type.is_real()) {
/*
- Quantize case when it must provide non-float32 output
+ Quantize case when it must provide non-float output
Calculating default values for input/output low/high (example calculations for int8):
output_low = lower bound for original type (-128)
output_high = upper bound for original type (127)
@@ -235,9 +239,9 @@ pass::TFLQuantizeReplacer::TFLQuantizeReplacer() {
input_low = std::make_shared<v1::Multiply>(std::make_shared<v1::Subtract>(output_low, zp_node), scale_node);
input_high =
std::make_shared<v1::Multiply>(std::make_shared<v1::Subtract>(output_high, zp_node), scale_node);
- } else if (in_type != element::f32) {
+ } else if (!in_type.is_real()) {
/*
- Dequantize case when it must accept non-float32 input
+ Dequantize case when it must accept non-float input
Calculating default values for input/output low/high (example calculations for int8):
input_low = lower bound for original type (-128)
input_high = upper bound for original type (127)
@@ -251,7 +255,7 @@ pass::TFLQuantizeReplacer::TFLQuantizeReplacer() {
std::make_shared<v1::Multiply>(std::make_shared<v1::Subtract>(input_high, zp_node), scale_node);
} else {
/*
- Requantize (QDQ) case when it accepts float32 for input and output
+ Requantize (QDQ) case when both input and output are real (float) types
Calculating default values for input/output low/high (example calculations for int8):
input_low = (lower bound for original type - zero point) * scale ((-128 - 16) * 0.25 = -36.0)
input_high = (upper bound for original type - zero point) * scale ((127 - 16) * 0.25 = 27.75)
diff --git a/src/frontends/tensorflow_lite/src/utils.cpp b/src/frontends/tensorflow_lite/src/utils.cpp
index d3be291516c..68efd9a8390 100644
--- a/src/frontends/tensorflow_lite/src/utils.cpp
+++ b/src/frontends/tensorflow_lite/src/utils.cpp
@@ -132,12 +132,24 @@ void ov::frontend::tensorflow_lite::apply_quantization(ov::Output<ov::Node>& out
return;
}
-void ov::frontend::tensorflow_lite::dequantize_inputs(OutputVector& deq_inputs) {
+void ov::frontend::tensorflow_lite::dequantize_inputs(OutputVector& deq_inputs,
+ const std::shared_ptr<DecoderBase>& decoder) {
+ // Dequantization is performed in floating point. Most TFLite models compute in f32, but fully
+ // float16 models keep activations and dequantized weights in f16. Derive the dequantization type
+ // from the operation's float output type so operands stay consistent, falling back to f32.
+ auto dequantized_type = element::f32;
+ auto op_decoder = std::dynamic_pointer_cast<DecoderBaseOperation>(decoder);
+ if (op_decoder && op_decoder->get_output_size() > 0) {
+ const auto out_type = op_decoder->get_output_tensor_type(0);
+ if (out_type.is_real())
+ dequantized_type = out_type;
+ }
+
for (auto& deq_input : deq_inputs) {
auto input = deq_input.get_node_shared_ptr();
if (!ov::is_type<ov::frontend::tensorflow_lite::TFLQuantize>(input))
continue;
- deq_input = std::make_shared<opset10::Convert>(deq_input, element::f32);
+ deq_input = std::make_shared<opset10::Convert>(deq_input, dequantized_type);
}
}
diff --git a/src/frontends/tensorflow_lite/src/utils.hpp b/src/frontends/tensorflow_lite/src/utils.hpp
index b1e1f866a43..01a7e89d618 100644
--- a/src/frontends/tensorflow_lite/src/utils.hpp
+++ b/src/frontends/tensorflow_lite/src/utils.hpp
@@ -21,7 +21,8 @@ ov::PartialShape get_ov_shape(const flatbuffers::Vector<int32_t>* tf_shape,
const flatbuffers::Vector<int32_t>* tf_shape_sig);
std::shared_ptr<QuantizationInfo> get_quantization(const tflite::QuantizationParameters* tf_quantization);
void apply_quantization(ov::Output<ov::Node>& output, ov::element::Type type);
-void dequantize_inputs(OutputVector& deq_inputs);
+void dequantize_inputs(OutputVector& deq_inputs,
+ const std::shared_ptr<ov::frontend::tensorflow_lite::DecoderBase>& decoder = nullptr);
std::shared_ptr<SparsityInfo> get_sparsity(const flatbuffers::Vector<int32_t>* tf_shape,
const tflite::SparsityParameters* tf_sparsity,
const ov::element::Type target_type,
diff --git a/src/frontends/tensorflow_lite/tests/quantization.cpp b/src/frontends/tensorflow_lite/tests/quantization.cpp
index de22ba9681e..5dfbed77715 100644
--- a/src/frontends/tensorflow_lite/tests/quantization.cpp
+++ b/src/frontends/tensorflow_lite/tests/quantization.cpp
@@ -74,6 +74,33 @@ OPENVINO_TEST(TensorFlowLiteTrickyModels, tflite_dequantize_uint8) {
test_case.run_with_tolerance_as_fp(0.001f);
}
+OPENVINO_TEST(TensorFlowLiteTrickyModels, tflite_dequantize_fp16) {
+ // Tests that a fully fp16 model dequantizes int8 weights to float16 (not float32),
+ // avoiding operand type mismatches in ops like FULLY_CONNECTED with fp16 activations.
+ auto model = convert_model("dequantize_fp16.tflite");
+
+ // Verify output type is float16
+ ASSERT_EQ(model->get_output_element_type(0), ov::element::f16);
+
+ auto test_case = ov::test::TestCase(model, ov::test::utils::DEVICE_CPU);
+ test_case.add_input<int8_t>({-128, -100, -1, 0, 1, 2, 3, 4, 5, 16, 100, 127});
+ // Expected: (val - zero_point) * scale = (val - 16) * 0.25
+ test_case.add_expected_output<ov::float16>(Shape{12},
+ {ov::float16(-36.f),
+ ov::float16(-29.f),
+ ov::float16(-4.25f),
+ ov::float16(-4.f),
+ ov::float16(-3.75f),
+ ov::float16(-3.5f),
+ ov::float16(-3.25f),
+ ov::float16(-3.f),
+ ov::float16(-2.75f),
+ ov::float16(0.f),
+ ov::float16(21.f),
+ ov::float16(27.75f)});
+ test_case.run_with_tolerance_as_fp(0.01f);
+}
+
OPENVINO_TEST(TensorFlowLiteTrickyModels, tflite_quantize_dequantize_int8) {
auto model = convert_model("qdq_int8.tflite");
diff --git a/src/frontends/tensorflow_lite/tests/test_models/gen_scripts/generate_dequantize.py b/src/frontends/tensorflow_lite/tests/test_models/gen_scripts/generate_dequantize.py
index 7e69ff46391..3fc88bf235f 100644
--- a/src/frontends/tensorflow_lite/tests/test_models/gen_scripts/generate_dequantize.py
+++ b/src/frontends/tensorflow_lite/tests/test_models/gen_scripts/generate_dequantize.py
@@ -2,8 +2,12 @@
# SPDX-License-Identifier: Apache-2.0
import os
+import struct
import sys
+import flatbuffers
+from flatbuffers import builder as flatbuffers_builder
+
import tensorflow as tf
# Create the graph and model
@@ -34,22 +38,175 @@ tflite_model = converter.convert()
with open(os.path.join(sys.argv[1], sm_path + ".tflite"), 'wb') as f:
f.write(tflite_model)
-# Model:
-# (int8)tensor_0[12] -> DEQUANTIZE -> (float32)tensor_1[12]
-# QUANTIZE:
-# scale: 0.25
-# zero point: 16
+
+# TFLite TensorType byte enum values (from schema.fbs)
+TENSOR_TYPE_FLOAT32 = 0
+TENSOR_TYPE_FLOAT16 = 1
+TENSOR_TYPE_UINT8 = 3
+TENSOR_TYPE_INT8 = 9
+
+# TFLite builtin opcode for DEQUANTIZE
+DEQUANTIZE_OPCODE = 6
+
+
+def build_dequantize_tflite(input_type, output_type, scale, zero_point, shape):
+ """Build a minimal TFLite model: input_tensor -> DEQUANTIZE -> output_tensor.
+
+ The TFLite flatbuffer schema field IDs used here:
+ Tensor: shape(0), type(1), buffer(2), name(3), quantization(4)
+ QuantizationParams: min(0), max(1), scale(2), zero_point(3)
+ SubGraph: tensors(0), inputs(1), outputs(2), operators(3), name(4)
+ Operator: opcode_index(0), inputs(1), outputs(2)
+ OperatorCode: deprecated_builtin_code(0), custom_code(1), version(2), builtin_code(3)
+ Model: version(0), operator_codes(1), subgraphs(2), description(3), buffers(4)
+ """
+ fbb = flatbuffers_builder.Builder(512)
+
+ # ---- output tensor (index 1) ----
+ out_name = fbb.CreateString("tensor_1")
+ fbb.StartVector(4, len(shape), 4)
+ for dim in reversed(shape):
+ fbb.PrependInt32(dim)
+ out_shape = fbb.EndVector(len(shape))
+
+ fbb.StartObject(0)
+ out_quant = fbb.EndObject()
+
+ fbb.StartObject(5)
+ fbb.PrependUOffsetTRelative(out_quant); fbb.Slot(4) # quantization
+ fbb.PrependUOffsetTRelative(out_name); fbb.Slot(3) # name
+ # buffer (slot 2) absent — default 0
+ fbb.PrependByte(output_type); fbb.Slot(1) # type (byte enum)
+ fbb.PrependUOffsetTRelative(out_shape); fbb.Slot(0) # shape
+ tensor_out = fbb.EndObject()
+
+ # ---- input tensor (index 0) with quantization ----
+ in_name = fbb.CreateString("tensor_0")
+ fbb.StartVector(4, len(shape), 4)
+ for dim in reversed(shape):
+ fbb.PrependInt32(dim)
+ in_shape = fbb.EndVector(len(shape))
+
+ fbb.StartVector(4, 1, 4)
+ fbb.PrependFloat32(scale)
+ scale_vec = fbb.EndVector(1)
+
+ fbb.StartVector(8, 1, 8)
+ fbb.PrependInt64(zero_point)
+ zp_vec = fbb.EndVector(1)
+
+ fbb.StartObject(7)
+ fbb.PrependUOffsetTRelative(zp_vec); fbb.Slot(3) # zero_point
+ fbb.PrependUOffsetTRelative(scale_vec); fbb.Slot(2) # scale
+ in_quant = fbb.EndObject()
+
+ fbb.StartObject(5)
+ fbb.PrependUOffsetTRelative(in_quant); fbb.Slot(4) # quantization
+ fbb.PrependUOffsetTRelative(in_name); fbb.Slot(3) # name
+ # buffer (slot 2) absent — default 0
+ fbb.PrependByte(input_type); fbb.Slot(1) # type (byte enum)
+ fbb.PrependUOffsetTRelative(in_shape); fbb.Slot(0) # shape
+ tensor_in = fbb.EndObject()
+
+ # tensors vector: [tensor_in(0), tensor_out(1)]
+ # PrependUOffsetTRelative adds backwards; last prepended → index 0
+ fbb.StartVector(4, 2, 4)
+ fbb.PrependUOffsetTRelative(tensor_out)
+ fbb.PrependUOffsetTRelative(tensor_in)
+ tensors_vec = fbb.EndVector(2)
+
+ # ---- DEQUANTIZE operator ----
+ fbb.StartVector(4, 1, 4)
+ fbb.PrependInt32(0)
+ op_inputs = fbb.EndVector(1)
+
+ fbb.StartVector(4, 1, 4)
+ fbb.PrependInt32(1)
+ op_outputs = fbb.EndVector(1)
+
+ # opcode_index absent (default 0 = DEQUANTIZE)
+ fbb.StartObject(3)
+ fbb.PrependUOffsetTRelative(op_outputs); fbb.Slot(2)
+ fbb.PrependUOffsetTRelative(op_inputs); fbb.Slot(1)
+ op = fbb.EndObject()
+
+ fbb.StartVector(4, 1, 4)
+ fbb.PrependUOffsetTRelative(op)
+ ops_vec = fbb.EndVector(1)
+
+ # ---- subgraph ----
+ fbb.StartVector(4, 1, 4); fbb.PrependInt32(0); sg_inputs = fbb.EndVector(1)
+ fbb.StartVector(4, 1, 4); fbb.PrependInt32(1); sg_outputs = fbb.EndVector(1)
+ sg_name = fbb.CreateString("test_subgraph")
+
+ fbb.StartObject(5)
+ fbb.PrependUOffsetTRelative(sg_name); fbb.Slot(4)
+ fbb.PrependUOffsetTRelative(ops_vec); fbb.Slot(3)
+ fbb.PrependUOffsetTRelative(sg_outputs); fbb.Slot(2)
+ fbb.PrependUOffsetTRelative(sg_inputs); fbb.Slot(1)
+ fbb.PrependUOffsetTRelative(tensors_vec);fbb.Slot(0)
+ subgraph = fbb.EndObject()
+
+ fbb.StartVector(4, 1, 4)
+ fbb.PrependUOffsetTRelative(subgraph)
+ subgraphs_vec = fbb.EndVector(1)
+
+ # ---- OperatorCode: DEQUANTIZE ----
+ fbb.StartObject(4)
+ fbb.PrependInt32(DEQUANTIZE_OPCODE); fbb.Slot(3) # builtin_code
+ fbb.PrependInt32(1); fbb.Slot(2) # version
+ fbb.PrependByte(DEQUANTIZE_OPCODE); fbb.Slot(0) # deprecated_builtin_code
+ op_code = fbb.EndObject()
+
+ fbb.StartVector(4, 1, 4)
+ fbb.PrependUOffsetTRelative(op_code)
+ op_codes_vec = fbb.EndVector(1)
+
+ # ---- two empty buffers ----
+ fbb.StartObject(0); buf0 = fbb.EndObject()
+ fbb.StartObject(0); buf1 = fbb.EndObject()
+ fbb.StartVector(4, 2, 4)
+ fbb.PrependUOffsetTRelative(buf1)
+ fbb.PrependUOffsetTRelative(buf0)
+ buffers_vec = fbb.EndVector(2)
+
+ model_name = fbb.CreateString("test_model")
+
+ fbb.StartObject(5)
+ fbb.PrependUOffsetTRelative(buffers_vec); fbb.Slot(4)
+ fbb.PrependUOffsetTRelative(model_name); fbb.Slot(3)
+ fbb.PrependUOffsetTRelative(subgraphs_vec); fbb.Slot(2)
+ fbb.PrependUOffsetTRelative(op_codes_vec); fbb.Slot(1)
+ fbb.PrependInt32(3); fbb.Slot(0) # version
+ model = fbb.EndObject()
+
+ fbb.Finish(model)
+ raw = bytearray(fbb.Output())
+
+ # Patch in the TFL3 file identifier. flatbuffers.Builder.Finish() writes a
+ # plain root-offset prefix; TFLite requires a 4-byte "TFL3" magic after it.
+ # Insert the identifier and adjust the root offset accordingly.
+ root_off = struct.unpack_from('<I', raw, 0)[0]
+ result = bytearray(4) + b'TFL3' + bytes(raw[4:])
+ struct.pack_into('<I', result, 0, root_off + 4)
+ return bytes(result)
+
+
+# Model: (int8)[12] -> DEQUANTIZE -> (float32)[12], scale=0.25, zero_point=16
sm_path = os.path.join(sys.argv[1], "dequantize_int8")
-tflite_model = b'\x08\x00\x00\x00TFL3\xbe\xff\xff\xff\x03\x00\x00\x00\x10\x00\x00\x00\x14\x00\x00\x00\x18\x00\x00\x00$\x00\x00\x00\x01\x00\x00\x00l\x01\x00\x00\x01\x00\x00\x00,\x00\x00\x00\n\x00\x00\x00test_model\x00\x00\x01\x00\x00\x00h\x00\x00\x00\x00\x00\x0e\x00\x18\x00\x04\x00\x08\x00\x0c\x00\x10\x00\x14\x00\x0e\x00\x00\x00\x14\x00\x00\x00\x1c\x00\x00\x00 \x00\x00\x00$\x00\x00\x00(\x00\x00\x00\x02\x00\x00\x00\xb4\x00\x00\x00\x80\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x000\x00\x00\x00\r\x00\x00\x00test_subgraph\x00\x00\x00\x04\x00\x06\x00\x04\x00\x00\x00\x00\x00\x0e\x00\x14\x00\x00\x00\x08\x00\x0c\x00\x07\x00\x10\x00\x0e\x00\x00\x00\x00\x00\x00&\x0c\x00\x00\x00\x10\x00\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x04\x00\x04\x00\x04\x00\x00\x00\x0c\x00\x0c\x00\x04\x00\x00\x00\x00\x00\x08\x00\x0c\x00\x00\x00\x08\x00\x00\x00\x0c\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00\x08\x00\x00\x00tensor_1\x00\x00\x0e\x00\x14\x00\x08\x00\x07\x00\x00\x00\x0c\x00\x10\x00\x0e\x00\x00\x00\x00\x00\x00\t\x0c\x00\x00\x00\x10\x00\x00\x00(\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00\x08\x00\x00\x00tensor_0\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x00\x00\x00\x04\x00\x08\x00\x0c\x00\x00\x00\x08\x00\x00\x00\x0c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x80>\x01\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x10\x00\x07\x00\x00\x00\x08\x00\x0c\x00\x0c\x00\x00\x00\x00\x00\x00\x06\x03\x00\x00\x00\x06\x00\x00\x00'
-with open(os.path.join(sys.argv[1], sm_path + ".tflite"), 'wb') as f:
- f.write(tflite_model)
+with open(sm_path + ".tflite", 'wb') as f:
+ f.write(build_dequantize_tflite(TENSOR_TYPE_INT8, TENSOR_TYPE_FLOAT32,
+ scale=0.25, zero_point=16, shape=[12]))
-# Model:
-# (uint8)tensor_0[12] -> DEQUANTIZE -> (float32)tensor_1[12]
-# QUANTIZE:
-# scale: 0.25
-# zero point: 16
+# Model: (uint8)[12] -> DEQUANTIZE -> (float32)[12], scale=0.25, zero_point=16
sm_path = os.path.join(sys.argv[1], "dequantize_uint8")
-tflite_model = b'\x08\x00\x00\x00TFL3\xbe\xff\xff\xff\x03\x00\x00\x00\x10\x00\x00\x00\x14\x00\x00\x00\x18\x00\x00\x00$\x00\x00\x00\x01\x00\x00\x00l\x01\x00\x00\x01\x00\x00\x00,\x00\x00\x00\n\x00\x00\x00test_model\x00\x00\x01\x00\x00\x00h\x00\x00\x00\x00\x00\x0e\x00\x18\x00\x04\x00\x08\x00\x0c\x00\x10\x00\x14\x00\x0e\x00\x00\x00\x14\x00\x00\x00\x1c\x00\x00\x00 \x00\x00\x00$\x00\x00\x00(\x00\x00\x00\x02\x00\x00\x00\xb4\x00\x00\x00\x80\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x000\x00\x00\x00\r\x00\x00\x00test_subgraph\x00\x00\x00\x04\x00\x06\x00\x04\x00\x00\x00\x00\x00\x0e\x00\x14\x00\x00\x00\x08\x00\x0c\x00\x07\x00\x10\x00\x0e\x00\x00\x00\x00\x00\x00&\x0c\x00\x00\x00\x10\x00\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x04\x00\x04\x00\x04\x00\x00\x00\x0c\x00\x0c\x00\x04\x00\x00\x00\x00\x00\x08\x00\x0c\x00\x00\x00\x08\x00\x00\x00\x0c\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00\x08\x00\x00\x00tensor_1\x00\x00\x0e\x00\x14\x00\x08\x00\x07\x00\x00\x00\x0c\x00\x10\x00\x0e\x00\x00\x00\x00\x00\x00\x03\x0c\x00\x00\x00\x10\x00\x00\x00(\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00\x08\x00\x00\x00tensor_0\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x00\x00\x00\x04\x00\x08\x00\x0c\x00\x00\x00\x08\x00\x00\x00\x0c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x80>\x01\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x10\x00\x07\x00\x00\x00\x08\x00\x0c\x00\x0c\x00\x00\x00\x00\x00\x00\x06\x03\x00\x00\x00\x06\x00\x00\x00'
-with open(os.path.join(sys.argv[1], sm_path + ".tflite"), 'wb') as f:
- f.write(tflite_model)
+with open(sm_path + ".tflite", 'wb') as f:
+ f.write(build_dequantize_tflite(TENSOR_TYPE_UINT8, TENSOR_TYPE_FLOAT32,
+ scale=0.25, zero_point=16, shape=[12]))
+
+# Model: (int8)[12] -> DEQUANTIZE -> (float16)[12], scale=0.25, zero_point=16
+# Tests fp16 dequantize path: weights stay in f16 to match fp16 activations.
+sm_path = os.path.join(sys.argv[1], "dequantize_fp16")
+with open(sm_path + ".tflite", 'wb') as f:
+ f.write(build_dequantize_tflite(TENSOR_TYPE_INT8, TENSOR_TYPE_FLOAT16,
+ scale=0.25, zero_point=16, shape=[12]))