Add per-tensor quantization into dynamic range quantization execution path for TRANSPOSE_CONV layer (https://github.com/tensorflow/tensorflow/issues/76624)

PiperOrigin-RevId: 682438954
This commit is contained in:
Artsiom Ablavatski 2024-10-04 13:50:51 -07:00 committed by TensorFlower Gardener
parent fa74dd087d
commit dde5634061
2 changed files with 18 additions and 6 deletions

View File

@ -99,6 +99,7 @@ This release contains contributions from many people at Google, as well as:
* Add support for `stablehlo.composite`.
* `EmbeddingLookup` op supports per-channel quantization and `TensorType_INT4` values.
* `FullyConnected` op supports `TensorType_INT16` activation and `TensorType_Int4` weight per-channel quantization.
* Enable per-tensor quantization support in dynamic range quantization of `TRANSPOSE_CONV` layer. Fixes TFLite converter [bug](https://github.com/tensorflow/tensorflow/issues/76624).
* `tf.tensor_scatter_update`, `tf.tensor_scatter_add` and of other reduce types.
* Support `bad_indices_policy`.

View File

@ -477,14 +477,25 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
scaling_factors_size));
}
const auto* affine_quantization =
reinterpret_cast<TfLiteAffineQuantization*>(
weights->quantization.params);
auto* affine_quantization = reinterpret_cast<TfLiteAffineQuantization*>(
weights->quantization.params);
TF_LITE_ENSURE(context, affine_quantization);
TF_LITE_ENSURE(context, affine_quantization->scale);
TF_LITE_ENSURE_EQ(
context, affine_quantization->scale->size,
weights->dims->data[affine_quantization->quantized_dimension]);
const int channels_out =
weights->dims->data[affine_quantization->quantized_dimension];
if (affine_quantization->scale->size != channels_out) {
TF_LITE_ENSURE_EQ(context, affine_quantization->scale->size, 1);
TfLiteFloatArrayFree(affine_quantization->scale);
affine_quantization->scale = TfLiteFloatArrayCreate(channels_out);
for (int i = 0; i < channels_out; ++i) {
affine_quantization->scale->data[i] = weights->params.scale;
}
} else {
TF_LITE_ENSURE_EQ(context, affine_quantization->scale->size,
channels_out);
}
node->temporaries->data[data->input_offset_index] = data->input_offset_id;
TfLiteTensor* input_offsets;
TF_LITE_ENSURE_OK(context,