mirror of
https://github.com/zebrajr/tensorflow.git
synced 2025-12-06 12:20:11 +01:00
Make 'import tensorflow' go faster
It now takes about 400ms rather than 800ms, if the file system cache is warm. Most of the latency was due to parsing text_format OpList protocol buffers in our generated sources. We now use a binary representation, while preserving the text proto as a comment for readability. Note: This change does not improve the latency of dereferencing tf.contrib, which takes about 340ms. PiperOrigin-RevId: 163739355
This commit is contained in:
parent
c215c55d54
commit
3445dd0edf
|
|
@ -722,8 +722,6 @@ This file is MACHINE GENERATED! Do not edit.
|
||||||
|
|
||||||
import collections as _collections
|
import collections as _collections
|
||||||
|
|
||||||
from google.protobuf import text_format as _text_format
|
|
||||||
|
|
||||||
from tensorflow.core.framework import op_def_pb2 as _op_def_pb2
|
from tensorflow.core.framework import op_def_pb2 as _op_def_pb2
|
||||||
|
|
||||||
# Needed to trigger the call to _set_call_cpp_shape_fn.
|
# Needed to trigger the call to _set_call_cpp_shape_fn.
|
||||||
|
|
@ -772,21 +770,24 @@ from tensorflow.python.framework import op_def_library as _op_def_library
|
||||||
RemoveNonDeprecationDescriptionsFromOpDef(added);
|
RemoveNonDeprecationDescriptionsFromOpDef(added);
|
||||||
}
|
}
|
||||||
|
|
||||||
strings::Appendf(&result, R"(def _InitOpDefLibrary():
|
result.append(R"(def _InitOpDefLibrary(op_list_proto_bytes):
|
||||||
op_list = _op_def_pb2.OpList()
|
op_list = _op_def_pb2.OpList()
|
||||||
_text_format.Merge(_InitOpDefLibrary.op_list_ascii, op_list)
|
op_list.ParseFromString(op_list_proto_bytes)
|
||||||
_op_def_registry.register_op_list(op_list)
|
_op_def_registry.register_op_list(op_list)
|
||||||
op_def_lib = _op_def_library.OpDefLibrary()
|
op_def_lib = _op_def_library.OpDefLibrary()
|
||||||
op_def_lib.add_op_list(op_list)
|
op_def_lib.add_op_list(op_list)
|
||||||
return op_def_lib
|
return op_def_lib
|
||||||
|
|
||||||
|
|
||||||
_InitOpDefLibrary.op_list_ascii = """%s"""
|
)");
|
||||||
|
|
||||||
|
result.append("# ");
|
||||||
_op_def_lib = _InitOpDefLibrary()
|
auto ops_text = ProtoDebugString(cleaned_ops);
|
||||||
)",
|
str_util::StripTrailingWhitespace(&ops_text);
|
||||||
ProtoDebugString(cleaned_ops).c_str());
|
result.append(str_util::StringReplace(ops_text, "\n", "\n# ", true));
|
||||||
|
result.append("\n");
|
||||||
|
strings::Appendf(&result, "_op_def_lib = _InitOpDefLibrary(b\"%s\")\n",
|
||||||
|
str_util::CEscape(cleaned_ops.SerializeAsString()).c_str());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user