Changed OpDefLibrary to use op_def_registry
Prior to this change OpDefLibrary used a local OpDef registry to construct and validate ops. Recent changes in op_def_registry allowed to switch to op_def_registry.get() for OpDef lookups making OpDefLibrary redundant. Note also that this changes removes binary ProtoBuf blobs from auto generated op wrappers because they were only used for defining an OpDefLibrary. Before: $ wc -c [...]/tensorflow/python/ops/gen_*_ops.py ... 4796803 total After: $ wc -c [...]/tensorflow/python/ops/gen_*_ops.py ... 4497581 total PiperOrigin-RevId: 271557944
This commit is contained in:
parent
ac6c12c16c
commit
32be3c5175
@ -974,6 +974,7 @@ tf_py_test(
|
||||
":function_def_to_graph",
|
||||
":graph_to_function_def",
|
||||
":math_ops",
|
||||
":op_def_library",
|
||||
":test_ops",
|
||||
],
|
||||
tags = ["no_pip"],
|
||||
@ -1031,6 +1032,7 @@ py_library(
|
||||
deps = [
|
||||
":dtypes",
|
||||
":framework_ops",
|
||||
":op_def_registry",
|
||||
":platform",
|
||||
":tensor_shape",
|
||||
":util",
|
||||
@ -2039,7 +2041,6 @@ tf_py_test(
|
||||
":framework_for_generated_wrappers",
|
||||
":framework_test_lib",
|
||||
":platform_test",
|
||||
":test_ops",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -23,10 +23,11 @@ from tensorflow.python.framework import constant_op
|
||||
from tensorflow.python.framework import dtypes
|
||||
from tensorflow.python.framework import function_def_to_graph
|
||||
from tensorflow.python.framework import graph_to_function_def
|
||||
from tensorflow.python.framework import op_def_library
|
||||
from tensorflow.python.framework import ops
|
||||
from tensorflow.python.framework import tensor_shape
|
||||
from tensorflow.python.framework import test_util
|
||||
from tensorflow.python.framework import test_ops
|
||||
from tensorflow.python.framework import test_util
|
||||
from tensorflow.python.ops import array_ops
|
||||
from tensorflow.python.ops import math_ops
|
||||
from tensorflow.python.ops import variables
|
||||
@ -119,8 +120,7 @@ class FunctionDefToGraphDefTest(test.TestCase):
|
||||
y = array_ops.placeholder(dtypes.int32, name="y")
|
||||
z = array_ops.placeholder(dtypes.int32, name="z")
|
||||
|
||||
d_1, e_1 = test_ops._op_def_lib.apply_op(
|
||||
"Foo1", name="foo_1", a=x, b=y, c=z)
|
||||
d_1, e_1 = op_def_library.apply_op("Foo1", name="foo_1", a=x, b=y, c=z)
|
||||
|
||||
list_output0, list_output1 = test_ops.list_output(
|
||||
T=[dtypes.int32, dtypes.int32], name="list_output")
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -375,8 +375,8 @@ void GenEagerPythonOp::HandleGraphMode(
|
||||
if (api_def_.visibility() == ApiDef::VISIBLE) {
|
||||
strings::StrAppend(&result_, " try:\n ");
|
||||
}
|
||||
strings::StrAppend(&result_,
|
||||
" _, _, _op, _outputs = _op_def_lib._apply_op_helper(\n");
|
||||
strings::StrAppend(
|
||||
&result_, " _, _, _op, _outputs = _op_def_library._apply_op_helper(\n");
|
||||
AddBodyNoReturn(strings::StrCat(" \"", op_def_.name(), "\", "));
|
||||
AddDispatch(" ");
|
||||
|
||||
@ -1007,7 +1007,6 @@ from tensorflow.python.eager import core as _core
|
||||
from tensorflow.python.eager import execute as _execute
|
||||
from tensorflow.python.framework import dtypes as _dtypes
|
||||
|
||||
from tensorflow.core.framework import op_def_pb2 as _op_def_pb2
|
||||
from tensorflow.python.framework import op_def_registry as _op_def_registry
|
||||
from tensorflow.python.framework import ops as _ops
|
||||
from tensorflow.python.framework import op_def_library as _op_def_library
|
||||
@ -1017,10 +1016,6 @@ from tensorflow.python.util.tf_export import tf_export
|
||||
|
||||
)");
|
||||
|
||||
// We'll make a copy of ops that filters out descriptions.
|
||||
OpList cleaned_ops;
|
||||
auto out = cleaned_ops.mutable_op();
|
||||
out->Reserve(ops.op_size());
|
||||
for (const auto& op_def : ops.op()) {
|
||||
const auto* api_def = api_defs.GetApiDef(op_def.name());
|
||||
|
||||
@ -1064,22 +1059,8 @@ from tensorflow.python.util.tf_export import tf_export
|
||||
|
||||
strings::StrAppend(&result,
|
||||
GetEagerPythonOp(op_def, *api_def, function_name));
|
||||
|
||||
auto added = out->Add();
|
||||
*added = op_def;
|
||||
RemoveNonDeprecationDescriptionsFromOpDef(added);
|
||||
}
|
||||
|
||||
result.append(R"(def _InitOpDefLibrary(op_list_proto_bytes):
|
||||
op_list = _op_def_pb2.OpList()
|
||||
op_list.ParseFromString(op_list_proto_bytes)
|
||||
op_def_lib = _op_def_library.OpDefLibrary()
|
||||
op_def_lib.add_op_list(op_list)
|
||||
return op_def_lib
|
||||
)");
|
||||
|
||||
strings::Appendf(&result, "_op_def_lib = _InitOpDefLibrary(b\"%s\")\n",
|
||||
absl::CEscape(cleaned_ops.SerializeAsString()).c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user