-
Notifications
You must be signed in to change notification settings - Fork 979
Tensorflow serializer #1056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Tensorflow serializer #1056
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9ca2b45
tensorflow serializer version 1
e7d6f33
tf serializer version 1
c5e7cb7
apply code-format changes
bzhang5 e7a95ed
suppoer tensorflow mobilenet
c18f815
suppoer tensorflow mobilenet
8ca444d
apply code-format changes
bzhang5 94bf44b
Merge branch 'tensorflow_serializer' of https://github.com/bzhang5/Te…
bb81f21
apply code-format changes
bzhang5 532a1f9
Update CMakeLists.txt
bzhang5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -49,15 +49,15 @@ IF (NOT CMAKE_BUILD_TYPE) | |||||
ENDIF() | ||||||
|
||||||
# Module options | ||||||
OPTION (TENGINE_BUILD_BENCHMARK "Build benchmark" ON) | ||||||
OPTION (TENGINE_BUILD_EXAMPLES "Build examples" ON) | ||||||
OPTION (TENGINE_BUILD_BENCHMARK "Build benchmark" OFF) | ||||||
OPTION (TENGINE_BUILD_EXAMPLES "Build examples" OFF) | ||||||
OPTION (TENGINE_BUILD_DEMO "Build demos" OFF) | ||||||
OPTION (TENGINE_BUILD_TESTS "Build tests" OFF) | ||||||
OPTION (TENGINE_BUILD_CPP_API "Build C++ API" OFF) | ||||||
|
||||||
# Tools options | ||||||
# Tools | ||||||
OPTION (TENGINE_BUILD_CONVERT_TOOL "Build convert tool" OFF) | ||||||
OPTION (TENGINE_BUILD_CONVERT_TOOL "Build convert tool" ON) | ||||||
|
OPTION (TENGINE_BUILD_CONVERT_TOOL "Build convert tool" ON) | |
OPTION (TENGINE_BUILD_CONVERT_TOOL "Build convert tool" OFF) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
syntax = "proto3"; | ||
|
||
package tensorflow; | ||
option cc_enable_arenas = true; | ||
option java_outer_classname = "AttrValueProtos"; | ||
option java_multiple_files = true; | ||
option java_package = "org.tensorflow.framework"; | ||
|
||
import "tensor.proto"; | ||
import "tensor_shape.proto"; | ||
import "types.proto"; | ||
|
||
// Protocol buffer representing the value for an attr used to configure an Op. | ||
// Comment indicates the corresponding attr type. Only the field matching the | ||
// attr type may be filled. | ||
message AttrValue { | ||
// LINT.IfChange | ||
message ListValue { | ||
repeated bytes s = 2; // "list(string)" | ||
repeated int64 i = 3 [packed = true]; // "list(int)" | ||
repeated float f = 4 [packed = true]; // "list(float)" | ||
repeated bool b = 5 [packed = true]; // "list(bool)" | ||
repeated DataType type = 6 [packed = true]; // "list(type)" | ||
repeated TensorShapeProto shape = 7; // "list(shape)" | ||
repeated TensorProto tensor = 8; // "list(tensor)" | ||
repeated NameAttrList func = 9; // "list(attr)" | ||
} | ||
// LINT.ThenChange(https://www.tensorflow.org/code/tensorflow/c/c_api.cc) | ||
|
||
oneof value { | ||
bytes s = 2; // "string" | ||
int64 i = 3; // "int" | ||
float f = 4; // "float" | ||
bool b = 5; // "bool" | ||
DataType type = 6; // "type" | ||
TensorShapeProto shape = 7; // "shape" | ||
TensorProto tensor = 8; // "tensor" | ||
ListValue list = 1; // any "list(...)" | ||
|
||
// "func" represents a function. func.name is a function's name or | ||
// a primitive op's name. func.attr.first is the name of an attr | ||
// defined for that function. func.attr.second is the value for | ||
// that attr in the instantiation. | ||
NameAttrList func = 10; | ||
|
||
// This is a placeholder only used in nodes defined inside a | ||
// function. It indicates the attr value will be supplied when | ||
// the function is instantiated. For example, let us suppose a | ||
// node "N" in function "FN". "N" has an attr "A" with value | ||
// placeholder = "foo". When FN is instantiated with attr "foo" | ||
// set to "bar", the instantiated node N's attr A will have been | ||
// given the value "bar". | ||
string placeholder = 9; | ||
} | ||
} | ||
|
||
// A list of attr names and their values. The whole list is attached | ||
// with a string name. E.g., MatMul[T=float]. | ||
message NameAttrList { | ||
string name = 1; | ||
map<string, AttrValue> attr = 2; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
syntax = "proto3"; | ||
|
||
package tensorflow; | ||
option cc_enable_arenas = true; | ||
option java_outer_classname = "FunctionProtos"; | ||
option java_multiple_files = true; | ||
option java_package = "org.tensorflow.framework"; | ||
|
||
import "attr_value.proto"; | ||
import "node_def.proto"; | ||
import "op_def.proto"; | ||
|
||
// A library is a set of named functions. | ||
message FunctionDefLibrary { | ||
repeated FunctionDef function = 1; | ||
repeated GradientDef gradient = 2; | ||
} | ||
|
||
// A function can be instantiated when the runtime can bind every attr | ||
// with a value. When a GraphDef has a call to a function, it must | ||
// have binding for every attr defined in the signature. | ||
// | ||
// TODO(zhifengc): | ||
// * device spec, etc. | ||
message FunctionDef { | ||
// The definition of the function's name, arguments, return values, | ||
// attrs etc. | ||
OpDef signature = 1; | ||
|
||
// Attributes specific to this function definition. | ||
map<string, AttrValue> attr = 5; | ||
|
||
// NOTE: field id 2 deleted on Jan 11, 2016, GraphDef version 21. | ||
|
||
// In both of the following fields, there is the need to specify an | ||
// output that is used as either the input to another node (in | ||
// `node_def`) or as a return value of the function (in `ret`). | ||
// Unlike the NodeDefs in GraphDef, we need to be able to specify a | ||
// list in some cases (instead of just single outputs). Also, we | ||
// need to be able to deal with lists of unknown length (so the | ||
// output index may not be known at function definition time). So | ||
// we use the following format instead: | ||
// * "fun_in" where "fun_in" is the name of a function input arg in | ||
// the `signature` field above. This represents that input, whether | ||
// it is a single tensor or a list. | ||
// * "fun_in:0" gives the first element of a function input arg (a | ||
// non-list input is considered a list of length 1 for these | ||
// purposes). | ||
// * "node:out" where "node" is the name of a node in `node_def` and | ||
// "out" is the name one of its op's output arguments (the name | ||
// comes from the OpDef of the node's op). This represents that | ||
// node's output, whether it is a single tensor or a list. | ||
// Note: We enforce that an op's output arguments are never | ||
// renamed in the backwards-compatibility test. | ||
// * "node:out:0" gives the first element of a node output arg (a | ||
// non-list output is considered a list of length 1 for these | ||
// purposes). | ||
// | ||
// NOT CURRENTLY SUPPORTED (but may be in the future): | ||
// * "node:out:-1" gives last element in a node output list | ||
// * "node:out:1:" gives a list with all but the first element in a | ||
// node output list | ||
// * "node:out::-1" gives a list with all but the last element in a | ||
// node output list | ||
|
||
// The body of the function. Unlike the NodeDefs in a GraphDef, attrs | ||
// may have values of type `placeholder` and the `input` field uses | ||
// the "output" format above. | ||
|
||
// By convention, "op" in node_def is resolved by consulting with a | ||
// user-defined library first. If not resolved, "func" is assumed to | ||
// be a builtin op. | ||
repeated NodeDef node_def = 3; | ||
|
||
// A mapping from the output arg names from `signature` to the | ||
// outputs from `node_def` that should be returned by the function. | ||
map<string, string> ret = 4; | ||
} | ||
|
||
// GradientDef defines the gradient function of a function defined in | ||
// a function library. | ||
// | ||
// A gradient function g (specified by gradient_func) for a function f | ||
// (specified by function_name) must follow the following: | ||
// | ||
// The function 'f' must be a numerical function which takes N inputs | ||
// and produces M outputs. Its gradient function 'g', which is a | ||
// function taking N + M inputs and produces N outputs. | ||
// | ||
// I.e. if we have | ||
// (y1, y2, ..., y_M) = f(x1, x2, ..., x_N), | ||
// then, g is | ||
// (dL/dx1, dL/dx2, ..., dL/dx_N) = g(x1, x2, ..., x_N, | ||
// dL/dy1, dL/dy2, ..., dL/dy_M), | ||
// where L is a scalar-value function of (x1, x2, ..., xN) (e.g., the | ||
// loss function). dL/dx_i is the partial derivative of L with respect | ||
// to x_i. | ||
message GradientDef { | ||
string function_name = 1; // The function name. | ||
string gradient_func = 2; // The gradient function's name. | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
syntax = "proto3"; | ||
|
||
package tensorflow; | ||
option cc_enable_arenas = true; | ||
option java_outer_classname = "GraphProtos"; | ||
option java_multiple_files = true; | ||
option java_package = "org.tensorflow.framework"; | ||
|
||
import "node_def.proto"; | ||
import "function.proto"; | ||
import "versions.proto"; | ||
|
||
// Represents the graph of operations | ||
message GraphDef { | ||
repeated NodeDef node = 1; | ||
|
||
// Compatibility versions of the graph. See core/public/version.h for version | ||
// history. The GraphDef version is distinct from the TensorFlow version, and | ||
// each release of TensorFlow will support a range of GraphDef versions. | ||
VersionDef versions = 4; | ||
|
||
// Deprecated single version field; use versions above instead. Since all | ||
// GraphDef changes before "versions" was introduced were forward | ||
// compatible, this field is entirely ignored. | ||
int32 version = 3 [deprecated = true]; | ||
|
||
// EXPERIMENTAL. DO NOT USE OR DEPEND ON THIS YET. | ||
// | ||
// "library" provides user-defined functions. | ||
// | ||
// Naming: | ||
// * library.function.name are in a flat namespace. | ||
// NOTE: We may need to change it to be hierarchical to support | ||
// different orgs. E.g., | ||
// { "/google/nn", { ... }}, | ||
// { "/google/vision", { ... }} | ||
// { "/org_foo/module_bar", { ... }} | ||
// map<string, FunctionDefLib> named_lib; | ||
// * If node[i].op is the name of one function in "library", | ||
// node[i] is deemed as a function call. Otherwise, node[i].op | ||
// must be a primitive operation supported by the runtime. | ||
// | ||
// | ||
// Function call semantics: | ||
// | ||
// * The callee may start execution as soon as some of its inputs | ||
// are ready. The caller may want to use Tuple() mechanism to | ||
// ensure all inputs are ready in the same time. | ||
// | ||
// * The consumer of return values may start executing as soon as | ||
// the return values the consumer depends on are ready. The | ||
// consumer may want to use Tuple() mechanism to ensure the | ||
// consumer does not start until all return values of the callee | ||
// function are ready. | ||
FunctionDefLibrary library = 2; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
syntax = "proto3"; | ||
|
||
package tensorflow; | ||
option cc_enable_arenas = true; | ||
option java_outer_classname = "NodeProto"; | ||
option java_multiple_files = true; | ||
option java_package = "org.tensorflow.framework"; | ||
|
||
import "attr_value.proto"; | ||
|
||
message NodeDef { | ||
// The name given to this operator. Used for naming inputs, | ||
// logging, visualization, etc. Unique within a single GraphDef. | ||
// Must match the regexp "[A-Za-z0-9.][A-Za-z0-9_./]*". | ||
string name = 1; | ||
|
||
// The operation name. There may be custom parameters in attrs. | ||
// Op names starting with an underscore are reserved for internal use. | ||
string op = 2; | ||
|
||
// Each input is "node:src_output" with "node" being a string name and | ||
// "src_output" indicating which output tensor to use from "node". If | ||
// "src_output" is 0 the ":0" suffix can be omitted. Regular inputs | ||
// may optionally be followed by control inputs that have the format | ||
// "^node". | ||
repeated string input = 3; | ||
|
||
// A (possibly partial) specification for the device on which this | ||
// node should be placed. | ||
// The expected syntax for this string is as follows: | ||
// | ||
// DEVICE_SPEC ::= PARTIAL_SPEC | ||
// | ||
// PARTIAL_SPEC ::= ("/" CONSTRAINT) * | ||
// CONSTRAINT ::= ("job:" JOB_NAME) | ||
// | ("replica:" [1-9][0-9]*) | ||
// | ("task:" [1-9][0-9]*) | ||
// | ( ("gpu" | "cpu") ":" ([1-9][0-9]* | "*") ) | ||
// | ||
// Valid values for this string include: | ||
// * "/job:worker/replica:0/task:1/gpu:3" (full specification) | ||
// * "/job:worker/gpu:3" (partial specification) | ||
// * "" (no specification) | ||
// | ||
// If the constraints do not resolve to a single device (or if this | ||
// field is empty or not present), the runtime will attempt to | ||
// choose a device automatically. | ||
string device = 4; | ||
|
||
// Operation-specific graph-construction-time configuration. | ||
// Note that this should include all attrs defined in the | ||
// corresponding OpDef, including those with a value matching | ||
// the default -- this allows the default to change and makes | ||
// NodeDefs easier to interpret on their own. However, if | ||
// an attr with a default is not specified in this list, the | ||
// default will be used. | ||
// The "names" (keys) must match the regexp "[a-z][a-z0-9_]+" (and | ||
// one of the names from the corresponding OpDef's attr field). | ||
// The values must have a type matching the corresponding OpDef | ||
// attr's type field. | ||
// TODO(josh11b): Add some examples here showing best practices. | ||
map<string, AttrValue> attr = 5; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.