[go: nahoru, domu]

Skip to content

Commit

Permalink
moving TF/lite/python/metrics/converter_error_data.proto to TF/mlir/l…
Browse files Browse the repository at this point in the history
…ite/python/metrics

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#14254 from apivovarov:symbolic_tile_analysis_test a6dc8fa12d2038c745d8b3e632002f549f5a0832
PiperOrigin-RevId: 644170858
  • Loading branch information
tensorflower-gardener committed Jun 28, 2024
1 parent 14d4b2e commit 5f66ba7
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 33 deletions.
4 changes: 2 additions & 2 deletions tensorflow/compiler/mlir/lite/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ cc_library(
"//tensorflow/compiler/mlir/lite:control_edges",
"//tensorflow/compiler/mlir/lite/core/c:private_common",
"//tensorflow/compiler/mlir/lite/experimental/remat:metadata_util",
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_cc",
"//tensorflow/compiler/mlir/lite/metrics:error_collector_inst",
"//tensorflow/compiler/mlir/lite/quantization/ir:QuantOps",
"//tensorflow/compiler/mlir/lite/schema:schema_conversion_utils",
Expand All @@ -1110,7 +1111,6 @@ cc_library(
"//tensorflow/core:protos_all_cc",
"//tensorflow/lite/core:framework",
"//tensorflow/lite/delegates/flex:allowlisted_flex_ops_lib",
"//tensorflow/lite/python/metrics:converter_error_data_proto_cc",
"//tensorflow/lite/toco:toco_flags_proto_cc",
"//tensorflow/lite/tools/versioning",
"//tensorflow/lite/tools/versioning:gpu_compatibility",
Expand Down Expand Up @@ -1418,6 +1418,7 @@ cc_library(
"//tensorflow/compiler/mlir:op_or_arg_name_mapper",
"//tensorflow/compiler/mlir/lite/debug",
"//tensorflow/compiler/mlir/lite/experimental/remat:metadata_util",
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_cc",
"//tensorflow/compiler/mlir/lite/metrics:error_collector",
"//tensorflow/compiler/mlir/lite/metrics:error_collector_inst",
"//tensorflow/compiler/mlir/lite/quantization/stablehlo:quantization",
Expand Down Expand Up @@ -1445,7 +1446,6 @@ cc_library(
"//tensorflow/core:core_cpu_base",
"//tensorflow/core:framework",
"//tensorflow/core:protos_all_cc",
"//tensorflow/lite/python/metrics:converter_error_data_proto_cc",
"//tensorflow/lite/toco:toco_flags_proto_cc",
"//tensorflow/lite/tools/optimize:quantize_weights",
"//tensorflow/lite/tools/optimize:reduced_precision_support",
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/compiler/mlir/lite/flatbuffer_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ limitations under the License.
#include "tensorflow/compiler/mlir/lite/experimental/remat/metadata_util.h"
#include "tensorflow/compiler/mlir/lite/flatbuffer_operator.h"
#include "tensorflow/compiler/mlir/lite/ir/tfl_ops.h"
#include "tensorflow/compiler/mlir/lite/metrics/converter_error_data.pb.h"
#include "tensorflow/compiler/mlir/lite/metrics/error_collector_inst.h"
#include "tensorflow/compiler/mlir/lite/quantization/ir/QuantOps.h"
#include "tensorflow/compiler/mlir/lite/schema/mutable/schema_generated.h"
Expand Down Expand Up @@ -113,7 +114,6 @@ limitations under the License.
#include "tensorflow/lite/core/interpreter.h"
#include "tensorflow/lite/core/macros.h"
#include "tensorflow/lite/delegates/flex/allowlisted_flex_ops.h"
#include "tensorflow/lite/python/metrics/converter_error_data.pb.h"
#include "tensorflow/lite/toco/toco_flags.pb.h"
#include "tensorflow/lite/tools/versioning/gpu_compatibility.h"
#include "tensorflow/lite/tools/versioning/op_version.h"
Expand Down
33 changes: 29 additions & 4 deletions tensorflow/compiler/mlir/lite/metrics/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Placeholder: load py_proto_library
load("//tensorflow:tensorflow.bzl", "tf_cc_test")
load(
"//tensorflow/core/platform:build_config.bzl",
"tf_proto_library",
)
load("//tensorflow/core/platform:rules_cc.bzl", "cc_library")

package(
Expand All @@ -17,8 +22,8 @@ cc_library(
srcs = ["error_collector.cc"],
hdrs = ["error_collector.h"],
deps = [
":converter_error_data_proto_cc",
":types_util",
"//tensorflow/lite/python/metrics:converter_error_data_proto_cc",
"@com_google_absl//absl/strings",
],
)
Expand All @@ -28,9 +33,9 @@ cc_library(
srcs = ["error_collector_inst.cc"],
hdrs = ["error_collector_inst.h"],
deps = [
":converter_error_data_proto_cc",
":error_collector",
":types_util",
"//tensorflow/lite/python/metrics:converter_error_data_proto_cc",
"@com_google_absl//absl/strings",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
Expand All @@ -45,14 +50,14 @@ tf_cc_test(
"testdata/strided_slice.mlir",
],
deps = [
":converter_error_data_proto_cc",
":error_collector",
":error_collector_inst",
":types_util",
"//tensorflow/compiler/mlir/tensorflow",
"//tensorflow/core:test",
"//tensorflow/core/platform:errors",
"//tensorflow/core/platform:resource_loader",
"//tensorflow/lite/python/metrics:converter_error_data_proto_cc",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest_main",
"@llvm-project//llvm:Support",
Expand All @@ -70,9 +75,29 @@ cc_library(
srcs = ["types_util.cc"],
hdrs = ["types_util.h"],
deps = [
"//tensorflow/lite/python/metrics:converter_error_data_proto_cc",
":converter_error_data_proto_cc",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Support",
],
)

tf_proto_library(
name = "converter_error_data_proto",
srcs = ["converter_error_data.proto"],
cc_api_version = 2,
visibility = [
"//visibility:public",
],
)

# copybara:uncomment_begin(google-only)
# py_proto_library(
# name = "converter_error_data_proto_py",
# api_version = 2,
# visibility = [
# "//visibility:public",
# ],
# deps = [":converter_error_data_proto"],
# )
# copybara:uncomment_end
2 changes: 1 addition & 1 deletion tensorflow/compiler/mlir/lite/metrics/error_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ limitations under the License.
#include <unordered_set>
#include <vector>

#include "tensorflow/compiler/mlir/lite/metrics/converter_error_data.pb.h"
#include "tensorflow/compiler/mlir/lite/metrics/types_util.h"
#include "tensorflow/lite/python/metrics/converter_error_data.pb.h"

namespace mlir {
namespace TFL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ limitations under the License.
#include "mlir/IR/MLIRContext.h" // from @llvm-project
#include "mlir/IR/Operation.h" // from @llvm-project
#include "mlir/Pass/PassInstrumentation.h" // from @llvm-project
#include "tensorflow/compiler/mlir/lite/metrics/converter_error_data.pb.h"
#include "tensorflow/compiler/mlir/lite/metrics/error_collector.h"
#include "tensorflow/compiler/mlir/lite/metrics/types_util.h"
#include "tensorflow/lite/python/metrics/converter_error_data.pb.h"

namespace mlir {
namespace TFL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ limitations under the License.
#include "mlir/Support/FileUtilities.h" // from @llvm-project
#include "mlir/Support/LogicalResult.h" // from @llvm-project
#include "mlir/Support/TypeID.h" // from @llvm-project
#include "tensorflow/compiler/mlir/lite/metrics/converter_error_data.pb.h"
#include "tensorflow/compiler/mlir/lite/metrics/error_collector.h"
#include "tensorflow/compiler/mlir/lite/metrics/types_util.h"
#include "tensorflow/compiler/mlir/tensorflow/ir/tf_dialect.h"
#include "tensorflow/core/platform/errors.h"
#include "tensorflow/core/platform/resource_loader.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/lite/python/metrics/converter_error_data.pb.h"
#include "tsl/platform/statusor.h"

namespace mlir {
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/compiler/mlir/lite/metrics/types_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ limitations under the License.
#include "mlir/IR/BuiltinAttributes.h" // from @llvm-project
#include "mlir/IR/Location.h" // from @llvm-project
#include "mlir/Support/LLVM.h" // from @llvm-project
#include "tensorflow/lite/python/metrics/converter_error_data.pb.h"
#include "tensorflow/compiler/mlir/lite/metrics/converter_error_data.pb.h"

namespace mlir {
namespace TFL {
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/compiler/mlir/lite/metrics/types_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
#include <string>

#include "mlir/IR/Location.h" // from @llvm-project
#include "tensorflow/lite/python/metrics/converter_error_data.pb.h"
#include "tensorflow/compiler/mlir/lite/metrics/converter_error_data.pb.h"

namespace mlir {
namespace TFL {
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/compiler/mlir/lite/tf_to_tfl_flatbuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ limitations under the License.
#include "tensorflow/compiler/mlir/lite/debug/debug.h"
#include "tensorflow/compiler/mlir/lite/experimental/remat/metadata_util.h"
#include "tensorflow/compiler/mlir/lite/flatbuffer_export.h"
#include "tensorflow/compiler/mlir/lite/metrics/converter_error_data.pb.h"
#include "tensorflow/compiler/mlir/lite/metrics/error_collector.h"
#include "tensorflow/compiler/mlir/lite/metrics/error_collector_inst.h"
#include "tensorflow/compiler/mlir/lite/quantization/stablehlo/quantization.h"
Expand Down Expand Up @@ -80,7 +81,6 @@ limitations under the License.
#include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/lite/python/metrics/converter_error_data.pb.h"
#include "tensorflow/lite/tools/optimize/quantize_weights.h"
#include "tensorflow/lite/tools/optimize/reduced_precision_support.h"
#include "tsl/platform/protobuf.h" // IWYU pragma: keep
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/lite/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ pytype_strict_library(
":convert_phase",
":lite_constants",
":util",
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_py",
"//tensorflow/compiler/mlir/lite/python:wrap_converter",
"//tensorflow/compiler/mlir/quantization/stablehlo:quantization_config_proto_py",
"//tensorflow/compiler/mlir/quantization/stablehlo:quantization_options_proto_py",
"//tensorflow/lite/python/metrics:converter_error_data_proto_py",
"//tensorflow/lite/python/metrics:metrics_wrapper",
"//tensorflow/lite/toco:model_flags_proto_py",
"//tensorflow/lite/toco:toco_flags_proto_py",
Expand Down Expand Up @@ -517,7 +517,7 @@ pytype_strict_contrib_test(
":convert",
":interpreter",
":op_hint",
"//tensorflow/lite/python/metrics:converter_error_data_proto_py",
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_py",
"//tensorflow/lite/python/metrics:metrics_wrapper",
"//tensorflow/lite/toco:toco_flags_proto_py",
"//tensorflow/python/client:session",
Expand Down Expand Up @@ -618,8 +618,8 @@ py_strict_library(
srcs_version = "PY3",
visibility = ["//tensorflow/lite:__subpackages__"],
deps = [
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_py",
"//tensorflow/lite/python/metrics",
"//tensorflow/lite/python/metrics:converter_error_data_proto_py",
],
)

Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/python/authoring/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ py_strict_library(
srcs_version = "PY3",
visibility = ["//visibility:public"],
deps = [
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_py",
"//tensorflow/lite/python:convert",
"//tensorflow/lite/python:lite",
"//tensorflow/lite/python/metrics:converter_error_data_proto_py",
"//tensorflow/python/util:tf_export",
],
)
Expand Down
4 changes: 1 addition & 3 deletions tensorflow/lite/python/authoring/authoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ def f(x):
> - simple_authoring.py:xxx
"""
import functools


from tensorflow.compiler.mlir.lite.metrics import converter_error_data_pb2
# pylint: disable=g-import-not-at-top
from tensorflow.lite.python import convert
from tensorflow.lite.python import lite
from tensorflow.lite.python.metrics import converter_error_data_pb2
from tensorflow.python.util.tf_export import tf_export as _tf_export


Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/python/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from typing import Optional
import warnings

from tensorflow.compiler.mlir.lite.metrics import converter_error_data_pb2
from tensorflow.compiler.mlir.lite.python import wrap_converter
from tensorflow.compiler.mlir.quantization.stablehlo import quantization_config_pb2
from tensorflow.compiler.mlir.quantization.stablehlo import quantization_options_pb2 as quant_opts_pb2
Expand All @@ -33,7 +34,6 @@
from tensorflow.lite.python.convert_phase import convert_phase
from tensorflow.lite.python.convert_phase import ConverterError
from tensorflow.lite.python.convert_phase import SubComponent
from tensorflow.lite.python.metrics import converter_error_data_pb2
from tensorflow.lite.python.metrics.wrapper import metrics_wrapper as _metrics_wrapper
from tensorflow.lite.toco import model_flags_pb2 as _model_flags_pb2
from tensorflow.lite.toco import toco_flags_pb2 as _conversion_flags_pb2
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/python/convert_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import functools
from typing import Text

from tensorflow.lite.python.metrics import converter_error_data_pb2
from tensorflow.compiler.mlir.lite.metrics import converter_error_data_pb2
from tensorflow.lite.python.metrics import metrics


Expand Down
3 changes: 1 addition & 2 deletions tensorflow/lite/python/convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
"""TensorFlow Lite Python Interface: Sanity check."""
from unittest import mock
import numpy as np

from tensorflow.compiler.mlir.lite.metrics import converter_error_data_pb2
from tensorflow.lite.python import convert
from tensorflow.lite.python import op_hint
from tensorflow.lite.python.interpreter import Interpreter
from tensorflow.lite.python.metrics import converter_error_data_pb2
from tensorflow.lite.python.metrics.wrapper import metrics_wrapper
from tensorflow.lite.toco import toco_flags_pb2 as _conversion_flags_pb2
from tensorflow.python.client import session
Expand Down
8 changes: 4 additions & 4 deletions tensorflow/lite/python/metrics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pytype_strict_library(
srcs_version = "PY3",
deps = [
":_pywrap_tensorflow_lite_metrics_wrapper",
":converter_error_data_proto_py",
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_py",
"//tensorflow/compiler/mlir/lite/python:wrap_converter",
],
)
Expand Down Expand Up @@ -111,7 +111,7 @@ pytype_strict_library(
visibility = ["//tensorflow/lite:__subpackages__"],
deps = if_portable(
if_false = [
":converter_error_data_proto_py",
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_py",
":metrics_wrapper",
"//tensorflow/python/eager:monitoring",
],
Expand All @@ -134,12 +134,12 @@ py_strict_test(
),
python_version = "PY3",
deps = [
":converter_error_data_proto_py",
":metrics",
"@absl_py//absl/testing:parameterized",
#internal proto upb dep
"//third_party/py/numpy",
"//tensorflow:tensorflow_py",
"//tensorflow/compiler/mlir/lite/metrics:converter_error_data_proto_py",
"//tensorflow/core:protos_all_py",
"//tensorflow/lite/python:convert",
"//tensorflow/lite/python:lite",
Expand All @@ -165,7 +165,7 @@ py_strict_test(

tf_proto_library(
name = "converter_error_data_proto",
srcs = ["converter_error_data.proto"],
srcs = ["third_party/tensorflow/compiler/mlir/lite/metrics/converter_error_data.proto"],
cc_api_version = 2,
)

Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/python/metrics/metrics_nonportable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Optional, Text
import uuid

from tensorflow.lite.python.metrics import converter_error_data_pb2
from tensorflow.compiler.mlir.lite.metrics import converter_error_data_pb2
from tensorflow.lite.python.metrics import metrics_interface
from tensorflow.lite.python.metrics.wrapper import metrics_wrapper
from tensorflow.python.eager import monitoring
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/python/metrics/metrics_nonportable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import numpy as np
import tensorflow as tf

from tensorflow.compiler.mlir.lite.metrics import converter_error_data_pb2
from tensorflow.core.framework import graph_pb2
from tensorflow.lite.python import lite
from tensorflow.lite.python.convert import ConverterError
from tensorflow.lite.python.convert import register_custom_opdefs
from tensorflow.lite.python.metrics import converter_error_data_pb2
from tensorflow.lite.python.metrics import metrics
from tensorflow.python.client import session
from tensorflow.python.eager import context
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/python/metrics/wrapper/metrics_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# ==============================================================================
"""Stub to make pywrap metrics wrapper accessible."""

from tensorflow.compiler.mlir.lite.metrics import converter_error_data_pb2
from tensorflow.compiler.mlir.lite.python import wrap_converter
from tensorflow.lite.python.metrics import converter_error_data_pb2
from tensorflow.lite.python.metrics._pywrap_tensorflow_lite_metrics_wrapper import MetricsWrapper # pylint: disable=unused-import


Expand Down
4 changes: 4 additions & 0 deletions third_party/xla/xla/service/algebraic_simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ bool AlgebraicSimplifierVisitor::IsNonNegative(
}
return false;
}
case HloOpcode::kMinimum: {
return IsNonNegative(hlo->operand(0), options) &&
IsNonNegative(hlo->operand(1), options);
}
case HloOpcode::kMaximum: {
return IsNonNegative(hlo->operand(0), options) ||
IsNonNegative(hlo->operand(1), options);
Expand Down
4 changes: 4 additions & 0 deletions third_party/xla/xla/service/algebraic_simplifier_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const char* non_neg_ops[] = {"abs(p0)",
"exponential(p0)",
"maximum(p0, a1)",
"maximum(a1, p0)",
"minimum(a0, a1)",
"multiply(p0, p0)",
"select(pred0, a0, a1)",
"select(pred0, a1, a0)"};
Expand All @@ -90,6 +91,9 @@ const char* arb_sing_ops[] = {"constant(-0.1)",
"custom-call(a1), custom_call_target=\"foobar\"",
"maximum(p0, p1)",
"maximum(p1, p0)",
"minimum(a0, p1)",
"minimum(p0, a1)",
"minimum(p0, p1)",
"multiply(p0, a1)",
"multiply(a1, p0)",
"negate(p0)",
Expand Down
Loading

0 comments on commit 5f66ba7

Please sign in to comment.