Skip to content

Commit ebb579e

Browse files
alankellytensorflower-gardener
authored andcommitted
Check that zero point and scale of inputs and outputs match for Concatenate operator.
The initial checks within VisitConcatenationNode all pass as xnn_define_concatenate is not called when checking if a node may be delegated or not. It is during the second pass that the check fails, causing delegation to fail. INFO: Created TensorFlow Lite XNNPACK delegate for CPU. ERROR: failed to delegate CONCATENATION node #31 ERROR: failed to delegate CONCATENATION node #36 ERROR: Node number 55 (TfLiteXNNPackDelegate) failed to prepare. PiperOrigin-RevId: 514364419
1 parent 6895071 commit ebb579e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tensorflow/lite/delegates/xnnpack/xnnpack_delegate.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,6 +2816,33 @@ class Subgraph {
28162816
if (axis < 0) axis += NumDimensions(&output_tensor);
28172817
int sum_axis = 0;
28182818

2819+
if (output_tensor.type == kTfLiteUInt8) {
2820+
const int32_t zero_point =
2821+
tensors[node->outputs->data[0]].params.zero_point;
2822+
const float scale = tensors[node->outputs->data[0]].params.scale;
2823+
for (int i = 0; i < num_inputs; i++) {
2824+
if (tensors[node->inputs->data[i]].params.zero_point != zero_point) {
2825+
TF_LITE_MAYBE_KERNEL_LOG(
2826+
logging_context,
2827+
"Mismatching quantization zero point across the %dth input "
2828+
"(%" PRId32 ") and the output (%" PRId32
2829+
") for CONCATENATE operator #%d",
2830+
i, tensors[node->inputs->data[i]].params.zero_point, zero_point,
2831+
node_index);
2832+
return kTfLiteError;
2833+
}
2834+
if (tensors[node->inputs->data[i]].params.scale != scale) {
2835+
TF_LITE_MAYBE_KERNEL_LOG(
2836+
logging_context,
2837+
"Mismatching quantization scale across the %dth input (%f) "
2838+
"and the output (%f) for CONCATENATE operator #%d",
2839+
i, tensors[node->inputs->data[i]].params.scale, scale,
2840+
node_index);
2841+
return kTfLiteError;
2842+
}
2843+
}
2844+
}
2845+
28192846
for (int i = 0; i < num_inputs; i++) {
28202847
const TfLiteTensor& input_tensor = tensors[node->inputs->data[i]];
28212848
TF_LITE_ENSURE_STATUS(CheckTensorFloat32OrQUInt8Type(

0 commit comments

Comments
 (0)