Skip to content

Fix REDUCE_PROD #32

@tomsmeding

Description

@tomsmeding

Just creating this issue to document ongoing investigation.

DIM1
        product: FAIL (1.52s)
            ✗ <interactive> failed at test/nofib/Data/Array/Accelerate/Test/NoFib/Prelude/Fold.hs:84:3
              after 1 test.
              shrink path: 1:

              ━━━ Exception (ErrorCall) ━━━
              edgetpu_compiler --show_operations --out_dir=/tmp/dpvanbalen/ /tmp/dpvanbalen/model3866256-1.tflite (exit 1)
              ERROR: Didn't find op for builtin opcode 'REDUCE_PROD' version '2'. An older version of this builtin might be supported. Are you using an old TFLite binary with a newer model?

              ERROR: Registration failed.

              Invalid model: /tmp/dpvanbalen/model3866256-1.tflite
              Model could not be parsed

Since TF 2.6, with TF PR #49735, TFLite generates REDUCE_PROD version 2 in certain cases. The closed-source edgetpu-compiler (which we suspect is based on TF <2.6) apparently doesn't support REDUCE_PROD version 2. With the following diff on TF 2.10.1, the product test does seem to work:

Details
diff --git a/tensorflow/lite/kernels/register.cc b/tensorflow/lite/kernels/register.cc
index 83da3d319cd..8146888b4eb 100644
--- a/tensorflow/lite/kernels/register.cc
+++ b/tensorflow/lite/kernels/register.cc
@@ -224,7 +224,7 @@ BuiltinOpResolver::BuiltinOpResolver() {
              /* max_version = */ 2);
   AddBuiltin(BuiltinOperator_REDUCE_PROD, Register_REDUCE_PROD(),
              /* min_version = */ 1,
-             /* max_version = */ 2);
+             /* max_version = */ 1);
   AddBuiltin(BuiltinOperator_REDUCE_MAX, Register_REDUCE_MAX(),
              /* min_version = */ 1,
              /* max_version = */ 3);
diff --git a/tensorflow/lite/kernels/register_ref.cc b/tensorflow/lite/kernels/register_ref.cc
index 8e6329b7caf..22089702d73 100644
--- a/tensorflow/lite/kernels/register_ref.cc
+++ b/tensorflow/lite/kernels/register_ref.cc
@@ -401,7 +401,7 @@ BuiltinRefOpResolver::BuiltinRefOpResolver() {
              /* max_version = */ 2);
   AddBuiltin(BuiltinOperator_REDUCE_PROD, Register_REDUCE_PROD_REF(),
              /* min_version = */ 1,
-             /* max_version = */ 2);
+             /* max_version = */ 1);
   AddBuiltin(BuiltinOperator_REDUCE_MAX, Register_REDUCE_MAX_REF(),
              /* min_version = */ 1,
              /* max_version = */ 3);
diff --git a/tensorflow/lite/tools/optimize/operator_property.cc b/tensorflow/lite/tools/optimize/operator_property.cc
index e9b960536da..09a19a167e1 100644
--- a/tensorflow/lite/tools/optimize/operator_property.cc
+++ b/tensorflow/lite/tools/optimize/operator_property.cc
@@ -1096,7 +1096,7 @@ OperatorProperty GetOperatorProperty(OpVariant op_variant) {
     case BuiltinOperator_REDUCE_PROD:
       property.inputs = {{0, {}}};
       property.outputs = {{0, {}}};
-      property.version = 2;
+      property.version = 1;
       break;
     case BuiltinOperator_REDUCE_MAX:
     case BuiltinOperator_REDUCE_MIN:
diff --git a/tensorflow/lite/tools/versioning/op_version.cc b/tensorflow/lite/tools/versioning/op_version.cc
index b11a13354f8..87f40f150e2 100644
--- a/tensorflow/lite/tools/versioning/op_version.cc
+++ b/tensorflow/lite/tools/versioning/op_version.cc
@@ -805,10 +805,10 @@ int GetBuiltinOperatorVersion(const OpSignature& op_sig) {
       return 1;
 
     case BuiltinOperator_REDUCE_PROD:
-      if (op_sig.inputs.at(0).type == kTfLiteInt8 ||
-          op_sig.inputs.at(0).type == kTfLiteInt16) {
-        return 2;
-      }
+      // if (op_sig.inputs.at(0).type == kTfLiteInt8 ||
+      //     op_sig.inputs.at(0).type == kTfLiteInt16) {
+      //   return 2;
+      // }
       return 1;
 
     // The version one of broadcast to op won't be not supported since the
diff --git a/tensorflow/lite/tools/versioning/runtime_version.cc b/tensorflow/lite/tools/versioning/runtime_version.cc
index d5745c8d7c2..ce9c14b16b5 100644
--- a/tensorflow/lite/tools/versioning/runtime_version.cc
+++ b/tensorflow/lite/tools/versioning/runtime_version.cc
@@ -203,7 +203,7 @@ std::string FindMinimumRuntimeVersionForOp(tflite::BuiltinOperator op_code,
            {{BuiltinOperator_REDUCE_MIN, 2}, "1.14.0"},
            {{BuiltinOperator_REDUCE_MIN, 3}, "2.5.0"},
            {{BuiltinOperator_REDUCE_PROD, 1}, "1.11.0"},
-           {{BuiltinOperator_REDUCE_PROD, 2}, "2.6.0"},
+           // {{BuiltinOperator_REDUCE_PROD, 2}, "2.6.0"},
            {{BuiltinOperator_REDUCE_ANY, 1}, "1.11.0"},
            {{BuiltinOperator_RELU6, 1}, "1.5.0"},
            {{BuiltinOperator_RELU6, 2}, "1.14.0"},

but just applying that without understanding the implications seems a very bad idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions