aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite/toco
diff options
context:
space:
mode:
authorGravatar Yu-Cheng Ling <ycling@google.com>2018-09-26 14:57:43 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-26 15:03:20 -0700
commit82af048bc8c3c044c98a27b1c4c27bb62d4e4a14 (patch)
treed9285ea3c1ec60cdd1973c517975b61d14d14c1e /tensorflow/contrib/lite/toco
parent83df298d2ed014d263570c7283322c982be556cc (diff)
Rename TFLite Eager delegate -> Flex delegate
PiperOrigin-RevId: 214674717
Diffstat (limited to 'tensorflow/contrib/lite/toco')
-rw-r--r--tensorflow/contrib/lite/toco/args.h4
-rw-r--r--tensorflow/contrib/lite/toco/import_tensorflow.cc4
-rw-r--r--tensorflow/contrib/lite/toco/import_tensorflow.h2
-rw-r--r--tensorflow/contrib/lite/toco/tflite/export.cc20
-rw-r--r--tensorflow/contrib/lite/toco/tflite/export.h4
-rw-r--r--tensorflow/contrib/lite/toco/tflite/export_test.cc2
-rw-r--r--tensorflow/contrib/lite/toco/tflite/operator.cc26
-rw-r--r--tensorflow/contrib/lite/toco/tflite/operator.h6
-rw-r--r--tensorflow/contrib/lite/toco/toco_cmdline_flags.cc24
-rw-r--r--tensorflow/contrib/lite/toco/toco_flags.proto16
-rw-r--r--tensorflow/contrib/lite/toco/toco_tooling.cc8
11 files changed, 58 insertions, 58 deletions
diff --git a/tensorflow/contrib/lite/toco/args.h b/tensorflow/contrib/lite/toco/args.h
index f14dbc258b..2699ac76e1 100644
--- a/tensorflow/contrib/lite/toco/args.h
+++ b/tensorflow/contrib/lite/toco/args.h
@@ -248,9 +248,9 @@ struct ParsedTocoFlags {
Arg<int64> dedupe_array_min_size_bytes = Arg<int64>(64);
Arg<bool> split_tflite_lstm_inputs = Arg<bool>(true);
// WARNING: Experimental interface, subject to change
- Arg<bool> allow_eager_ops = Arg<bool>(false);
+ Arg<bool> allow_flex_ops = Arg<bool>(false);
// WARNING: Experimental interface, subject to change
- Arg<bool> force_eager_ops = Arg<bool>(false);
+ Arg<bool> force_flex_ops = Arg<bool>(false);
};
} // namespace toco
diff --git a/tensorflow/contrib/lite/toco/import_tensorflow.cc b/tensorflow/contrib/lite/toco/import_tensorflow.cc
index e02d000e7e..5eaf6e27fc 100644
--- a/tensorflow/contrib/lite/toco/import_tensorflow.cc
+++ b/tensorflow/contrib/lite/toco/import_tensorflow.cc
@@ -2123,9 +2123,9 @@ std::unique_ptr<Model> ImportTensorFlowGraphDef(
Model* model = new Model;
internal::ConverterMapType converter_map;
- // This is used for the TFLite "Full Eager Mode" conversion. All the ops are
+ // This is used for the TFLite "Full Flex Mode" conversion. All the ops are
// imported as `TensorFlowUnsupportedOperator`, and later all these ops are
- // converted to TFLite Eager ops.
+ // converted to TFLite Flex ops.
if (!tf_import_flags.import_all_ops_as_unsupported) {
converter_map = internal::GetTensorFlowNodeConverterMap();
}
diff --git a/tensorflow/contrib/lite/toco/import_tensorflow.h b/tensorflow/contrib/lite/toco/import_tensorflow.h
index 7db23f2d44..c5ff96956a 100644
--- a/tensorflow/contrib/lite/toco/import_tensorflow.h
+++ b/tensorflow/contrib/lite/toco/import_tensorflow.h
@@ -30,7 +30,7 @@ struct TensorFlowImportFlags {
// Do not recognize any op and import all ops as
// `TensorFlowUnsupportedOperator`. This is used to populated with the
- // `force_eager_ops` flag.
+ // `force_flex_ops` flag.
bool import_all_ops_as_unsupported = false;
};
diff --git a/tensorflow/contrib/lite/toco/tflite/export.cc b/tensorflow/contrib/lite/toco/tflite/export.cc
index fee10b1dff..5cdfd24565 100644
--- a/tensorflow/contrib/lite/toco/tflite/export.cc
+++ b/tensorflow/contrib/lite/toco/tflite/export.cc
@@ -50,16 +50,16 @@ namespace {
details::OperatorKey GetOperatorKey(
const ::toco::Operator& op,
const std::map<OperatorType, std::unique_ptr<BaseOperator>>& ops_by_type,
- bool allow_eager_ops) {
+ bool allow_flex_ops) {
string custom_code;
if (op.type == OperatorType::kUnsupported) {
const TensorFlowUnsupportedOperator& unsupported_op =
static_cast<const TensorFlowUnsupportedOperator&>(op);
- // TODO(b/113715895): When `allow_eager_ops` is on, for now there's no way
+ // TODO(b/113715895): When `allow_flex_ops` is on, for now there's no way
// to populate a regular custom op. We need to find a way to fix this.
- if (allow_eager_ops) {
- custom_code = string(::tflite::kEagerCustomCodePrefix) +
+ if (allow_flex_ops) {
+ custom_code = string(::tflite::kFlexCustomCodePrefix) +
unsupported_op.tensorflow_op;
} else {
custom_code = unsupported_op.tensorflow_op;
@@ -101,11 +101,11 @@ void LoadTensorsMap(const Model& model, TensorsMap* tensors_map) {
void LoadOperatorsMap(
const Model& model, OperatorsMap* operators_map,
const std::map<OperatorType, std::unique_ptr<BaseOperator>>& ops_by_type,
- bool allow_eager_ops) {
+ bool allow_flex_ops) {
// First find a list of unique operator types.
std::set<OperatorKey> keys;
for (const auto& op : model.operators) {
- keys.insert(GetOperatorKey(*op, ops_by_type, allow_eager_ops));
+ keys.insert(GetOperatorKey(*op, ops_by_type, allow_flex_ops));
}
// Now assign indices to them and fill in the map.
int index = 0;
@@ -216,7 +216,7 @@ Offset<Vector<Offset<OperatorCode>>> ExportOperatorCodes(
for (const auto& op : model.operators) {
const details::OperatorKey operator_key =
- GetOperatorKey(*op, ops_by_type, params.allow_eager_ops);
+ GetOperatorKey(*op, ops_by_type, params.allow_flex_ops);
int op_index = operators_map.at(operator_key);
int op_version = operator_key.version;
@@ -281,7 +281,7 @@ Offset<Vector<Offset<Operator>>> ExportOperators(
}
int op_index = operators_map.at(
- GetOperatorKey(*op, ops_by_type, params.allow_eager_ops));
+ GetOperatorKey(*op, ops_by_type, params.allow_flex_ops));
auto tflite_op_it = ops_by_type.find(op->type);
BaseOperator* tflite_op = tflite_op_it == ops_by_type.end()
@@ -334,7 +334,7 @@ Offset<Vector<Offset<Buffer>>> ExportBuffers(
void Export(const Model& model, string* output_file_contents,
const ExportParams& params) {
- const auto ops_by_type = BuildOperatorByTypeMap(params.allow_eager_ops);
+ const auto ops_by_type = BuildOperatorByTypeMap(params.allow_flex_ops);
Export(model, output_file_contents, params, ops_by_type);
}
@@ -349,7 +349,7 @@ void Export(
details::OperatorsMap operators_map;
details::LoadOperatorsMap(model, &operators_map, ops_by_type,
- params.allow_eager_ops);
+ params.allow_flex_ops);
std::vector<const Array*> buffers_to_write;
Array empty_array;
diff --git a/tensorflow/contrib/lite/toco/tflite/export.h b/tensorflow/contrib/lite/toco/tflite/export.h
index b070a38768..29d6de4049 100644
--- a/tensorflow/contrib/lite/toco/tflite/export.h
+++ b/tensorflow/contrib/lite/toco/tflite/export.h
@@ -26,7 +26,7 @@ namespace tflite {
// The parameters for exporting a TFLite model.
struct ExportParams {
bool allow_custom_ops = false;
- bool allow_eager_ops = false;
+ bool allow_flex_ops = false;
bool quantize_weights = false;
};
@@ -121,7 +121,7 @@ void LoadTensorsMap(const Model& model, TensorsMap* tensors_map);
void LoadOperatorsMap(
const Model& model, OperatorsMap* operators_map,
const std::map<OperatorType, std::unique_ptr<BaseOperator>>& ops_by_type,
- bool allow_eager_ops);
+ bool allow_flex_ops);
} // namespace details
} // namespace tflite
diff --git a/tensorflow/contrib/lite/toco/tflite/export_test.cc b/tensorflow/contrib/lite/toco/tflite/export_test.cc
index 8d4d197c46..93882a91a7 100644
--- a/tensorflow/contrib/lite/toco/tflite/export_test.cc
+++ b/tensorflow/contrib/lite/toco/tflite/export_test.cc
@@ -105,7 +105,7 @@ TEST_F(ExportTest, LoadOperatorsMap) {
details::OperatorsMap operators;
const auto ops_by_type = BuildOperatorByTypeMap();
- // TODO(ycling): Add a test for allow_eager_ops.
+ // TODO(ycling): Add a test for allow_flex_ops.
details::LoadOperatorsMap(input_model_, &operators, ops_by_type, false);
EXPECT_EQ(0, operators[details::OperatorKey(OperatorType::kAdd, "", 1)]);
EXPECT_EQ(1, operators[details::OperatorKey(OperatorType::kConv, "", 1)]);
diff --git a/tensorflow/contrib/lite/toco/tflite/operator.cc b/tensorflow/contrib/lite/toco/tflite/operator.cc
index ca2a6a19b3..9addbb81e7 100644
--- a/tensorflow/contrib/lite/toco/tflite/operator.cc
+++ b/tensorflow/contrib/lite/toco/tflite/operator.cc
@@ -1160,8 +1160,8 @@ class Unpack : public BuiltinOperator<UnpackOperator, ::tflite::UnpackOptions,
class TensorFlowUnsupported : public BaseOperator {
public:
TensorFlowUnsupported(const string& name, OperatorType type,
- bool allow_eager_ops)
- : BaseOperator(name, type), allow_eager_ops_(allow_eager_ops) {}
+ bool allow_flex_ops)
+ : BaseOperator(name, type), allow_flex_ops_(allow_flex_ops) {}
Options Serialize(const Operator& op,
flatbuffers::FlatBufferBuilder* builder) const override {
@@ -1177,9 +1177,9 @@ class TensorFlowUnsupported : public BaseOperator {
std::unique_ptr<Operator> Deserialize(
const BuiltinOptions* builtin_options,
const CustomOptions* custom_options) const override {
- // Deserializing Eager ops doesn't work now.
+ // Deserializing Flex ops doesn't work now.
// TODO(ycling): Revisit and decide if we should fix the flow for importing
- // TFLite models with Eager ops.
+ // TFLite models with Flex ops.
auto op = absl::make_unique<TensorFlowUnsupportedOperator>();
if (custom_options) {
auto flexbuffer_map =
@@ -1200,13 +1200,13 @@ class TensorFlowUnsupported : public BaseOperator {
return std::unique_ptr<flexbuffers::Builder>();
}
- if (allow_eager_ops_) {
+ if (allow_flex_ops_) {
fbb->Vector([&]() {
fbb->String(node_def.op());
fbb->String(op.tensorflow_node_def);
});
fbb->Finish();
- LOG(INFO) << "Writing eager op: " << node_def.op();
+ LOG(INFO) << "Writing flex op: " << node_def.op();
return std::unique_ptr<flexbuffers::Builder>(fbb.release());
}
@@ -1316,13 +1316,13 @@ class TensorFlowUnsupported : public BaseOperator {
}
private:
- const bool allow_eager_ops_;
+ const bool allow_flex_ops_;
};
namespace {
// Build a vector containing all the known operators.
std::vector<std::unique_ptr<BaseOperator>> BuildOperatorList(
- bool allow_eager_ops = false) {
+ bool allow_flex_ops = false) {
std::vector<std::unique_ptr<BaseOperator>> ops;
using tensorflow::MakeUnique;
// Builtin Operators.
@@ -1434,7 +1434,7 @@ std::vector<std::unique_ptr<BaseOperator>> BuildOperatorList(
ops.push_back(MakeUnique<CTCBeamSearchDecoder>(
"CTC_BEAM_SEARCH_DECODER", OperatorType::kCTCBeamSearchDecoder));
ops.push_back(MakeUnique<TensorFlowUnsupported>(
- "TENSORFLOW_UNSUPPORTED", OperatorType::kUnsupported, allow_eager_ops));
+ "TENSORFLOW_UNSUPPORTED", OperatorType::kUnsupported, allow_flex_ops));
// There operators are supported by Toco, but not by TF Lite, and has no
// attributes.
@@ -1512,11 +1512,11 @@ std::vector<std::unique_ptr<BaseOperator>> BuildOperatorList(
} // namespace
std::map<OperatorType, std::unique_ptr<BaseOperator>> BuildOperatorByTypeMap(
- bool allow_eager_ops) {
+ bool allow_flex_ops) {
std::map<OperatorType, std::unique_ptr<BaseOperator>> result;
std::vector<std::unique_ptr<BaseOperator>> ops =
- BuildOperatorList(allow_eager_ops);
+ BuildOperatorList(allow_flex_ops);
for (auto& op : ops) {
result[op->type()] = std::move(op);
}
@@ -1525,11 +1525,11 @@ std::map<OperatorType, std::unique_ptr<BaseOperator>> BuildOperatorByTypeMap(
}
std::map<string, std::unique_ptr<BaseOperator>> BuildOperatorByNameMap(
- bool allow_eager_ops) {
+ bool allow_flex_ops) {
std::map<string, std::unique_ptr<BaseOperator>> result;
std::vector<std::unique_ptr<BaseOperator>> ops =
- BuildOperatorList(allow_eager_ops);
+ BuildOperatorList(allow_flex_ops);
for (auto& op : ops) {
result[op->name()] = std::move(op);
}
diff --git a/tensorflow/contrib/lite/toco/tflite/operator.h b/tensorflow/contrib/lite/toco/tflite/operator.h
index 702fb28ea6..13d9f6c49a 100644
--- a/tensorflow/contrib/lite/toco/tflite/operator.h
+++ b/tensorflow/contrib/lite/toco/tflite/operator.h
@@ -26,15 +26,15 @@ namespace tflite {
class BaseOperator;
// Return a map contained all know TF Lite Operators, keyed by their names.
-// TODO(ycling): The pattern to propagate parameters (e.g. allow_eager_ops)
+// TODO(ycling): The pattern to propagate parameters (e.g. allow_flex_ops)
// is ugly here. Consider refactoring.
std::map<string, std::unique_ptr<BaseOperator>> BuildOperatorByNameMap(
- bool allow_eager_ops = false);
+ bool allow_flex_ops = false);
// Return a map contained all know TF Lite Operators, keyed by the type of
// their tf.mini counterparts.
std::map<OperatorType, std::unique_ptr<BaseOperator>> BuildOperatorByTypeMap(
- bool allow_eager_ops = false);
+ bool allow_flex_ops = false);
// These are the flatbuffer types for custom and builtin options.
using CustomOptions = flatbuffers::Vector<uint8_t>;
diff --git a/tensorflow/contrib/lite/toco/toco_cmdline_flags.cc b/tensorflow/contrib/lite/toco/toco_cmdline_flags.cc
index b6aebc0470..cff79776bc 100644
--- a/tensorflow/contrib/lite/toco/toco_cmdline_flags.cc
+++ b/tensorflow/contrib/lite/toco/toco_cmdline_flags.cc
@@ -167,11 +167,11 @@ bool ParseTocoFlagsFromCommandLineFlags(
"converted float model. Model size will be reduced and there will "
"be latency improvements (at the cost of accuracy)."),
// WARNING: Experimental interface, subject to change
- Flag("allow_eager_ops", parsed_flags.allow_eager_ops.bind(),
- parsed_flags.allow_eager_ops.default_value(), ""),
+ Flag("allow_flex_ops", parsed_flags.allow_flex_ops.bind(),
+ parsed_flags.allow_flex_ops.default_value(), ""),
// WARNING: Experimental interface, subject to change
- Flag("force_eager_ops", parsed_flags.force_eager_ops.bind(),
- parsed_flags.force_eager_ops.default_value(), "")};
+ Flag("force_flex_ops", parsed_flags.force_flex_ops.bind(),
+ parsed_flags.force_flex_ops.default_value(), "")};
bool asked_for_help =
*argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-help"));
if (asked_for_help) {
@@ -266,15 +266,15 @@ void ReadTocoFlagsFromCommandLineFlags(const ParsedTocoFlags& parsed_toco_flags,
READ_TOCO_FLAG(split_tflite_lstm_inputs, FlagRequirement::kNone);
READ_TOCO_FLAG(quantize_weights, FlagRequirement::kNone);
READ_TOCO_FLAG(post_training_quantize, FlagRequirement::kNone);
- READ_TOCO_FLAG(allow_eager_ops, FlagRequirement::kNone);
- READ_TOCO_FLAG(force_eager_ops, FlagRequirement::kNone);
+ READ_TOCO_FLAG(allow_flex_ops, FlagRequirement::kNone);
+ READ_TOCO_FLAG(force_flex_ops, FlagRequirement::kNone);
- if (parsed_toco_flags.force_eager_ops.value() &&
- !parsed_toco_flags.allow_eager_ops.value()) {
- // TODO(ycling): Consider to enforce `allow_eager_ops` when
- // `force_eager_ops` is true.
- LOG(WARNING) << "--force_eager_ops should always be used with "
- "--allow_eager_ops.";
+ if (parsed_toco_flags.force_flex_ops.value() &&
+ !parsed_toco_flags.allow_flex_ops.value()) {
+ // TODO(ycling): Consider to enforce `allow_flex_ops` when
+ // `force_flex_ops` is true.
+ LOG(WARNING) << "--force_flex_ops should always be used with "
+ "--allow_flex_ops.";
}
// Deprecated flag handling.
diff --git a/tensorflow/contrib/lite/toco/toco_flags.proto b/tensorflow/contrib/lite/toco/toco_flags.proto
index 53d60fed05..ca3e64485e 100644
--- a/tensorflow/contrib/lite/toco/toco_flags.proto
+++ b/tensorflow/contrib/lite/toco/toco_flags.proto
@@ -190,16 +190,16 @@ message TocoFlags {
// (at the cost of accuracy).
optional bool post_training_quantize = 26 [default = false];
- // When enabled, unsupported ops will be converted to TFLite Eager ops.
+ // When enabled, unsupported ops will be converted to TFLite Flex ops.
// TODO(ycling): Consider to rename the following 2 flags and don't call it
- // "Eager".
- // `allow_eager_ops` should always be used with `allow_custom_ops`.
+ // "Flex".
+ // `allow_flex_ops` should always be used with `allow_custom_ops`.
// WARNING: Experimental interface, subject to change
- optional bool allow_eager_ops = 27 [default = false];
+ optional bool allow_flex_ops = 27 [default = false];
- // When enabled, all TensorFlow ops will be converted to TFLite Eager
- // ops directly. This will force `allow_eager_ops` to true.
- // `force_eager_ops` should always be used with `allow_eager_ops`.
+ // When enabled, all TensorFlow ops will be converted to TFLite Flex
+ // ops directly. This will force `allow_flex_ops` to true.
+ // `force_flex_ops` should always be used with `allow_flex_ops`.
// WARNING: Experimental interface, subject to change
- optional bool force_eager_ops = 28 [default = false];
+ optional bool force_flex_ops = 28 [default = false];
}
diff --git a/tensorflow/contrib/lite/toco/toco_tooling.cc b/tensorflow/contrib/lite/toco/toco_tooling.cc
index a08b02485f..106494f354 100644
--- a/tensorflow/contrib/lite/toco/toco_tooling.cc
+++ b/tensorflow/contrib/lite/toco/toco_tooling.cc
@@ -198,7 +198,7 @@ std::unique_ptr<Model> Import(const TocoFlags& toco_flags,
: (toco_flags.output_format() != TENSORFLOW_GRAPHDEF);
tf_import_flags.import_all_ops_as_unsupported =
- toco_flags.force_eager_ops();
+ toco_flags.force_flex_ops();
model = ImportTensorFlowGraphDef(model_flags, tf_import_flags,
input_file_contents);
@@ -409,9 +409,9 @@ void Export(const TocoFlags& toco_flags, const Model& model,
case TFLITE: {
toco::tflite::ExportParams params;
- // Always allow custom ops when eager ops are allowed.
- if (toco_flags.force_eager_ops() || toco_flags.allow_eager_ops()) {
- params.allow_eager_ops = true;
+ // Always allow custom ops when flex ops are allowed.
+ if (toco_flags.force_flex_ops() || toco_flags.allow_flex_ops()) {
+ params.allow_flex_ops = true;
params.allow_custom_ops = true;
} else if (allow_custom_ops) {
params.allow_custom_ops = true;