MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / InsertLogging

Function InsertLogging

tensorflow/tools/graph_transforms/insert_logging.cc:31–146  ·  view source on GitHub ↗

Clears the device field of all ops in the graph.

Source from the content-addressed store, hash-verified

29
30// Clears the device field of all ops in the graph.
31Status InsertLogging(const GraphDef& input_graph_def,
32 const TransformFuncContext& context,
33 GraphDef* output_graph_def) {
34 std::unordered_set<string> ops;
35 bool has_ops;
36 if (context.params.count("op")) {
37 has_ops = true;
38 for (const string& op : context.params.at("op")) {
39 ops.insert(op);
40 }
41 } else {
42 has_ops = false;
43 }
44
45 std::unordered_set<string> prefixes;
46 bool has_prefixes;
47 if (context.params.count("prefix")) {
48 has_prefixes = true;
49 for (const string& prefix : context.params.at("prefix")) {
50 prefixes.insert(prefix);
51 }
52 } else {
53 has_prefixes = false;
54 }
55
56 string message;
57 TF_RETURN_IF_ERROR(context.GetOneStringParameter("message", "", &message));
58
59 bool show_name;
60 TF_RETURN_IF_ERROR(
61 context.GetOneBoolParameter("show_name", false, &show_name));
62
63 bool show_op;
64 TF_RETURN_IF_ERROR(context.GetOneBoolParameter("show_op", false, &show_op));
65
66 int32 first_n;
67 TF_RETURN_IF_ERROR(context.GetOneInt32Parameter("first_n", -1, &first_n));
68
69 int32 summarize;
70 TF_RETURN_IF_ERROR(
71 context.GetOneInt32Parameter("summarize", 1024, &summarize));
72
73 std::unordered_map<string, std::set<int>> node_outputs;
74 for (const NodeDef& node : input_graph_def.node()) {
75 for (const string& input : node.input()) {
76 const string canonical_input = CanonicalInputName(input);
77 string prefix;
78 string name;
79 string suffix;
80 NodeNamePartsFromInput(canonical_input, &prefix, &name, &suffix);
81 const string output_index_string = suffix.substr(1, suffix.size() - 1);
82 int32 output_index;
83 if (!strings::safe_strto32(output_index_string, &output_index)) {
84 return errors::InvalidArgument("Couldn't understand output number in ",
85 input);
86 }
87 node_outputs[name].insert(output_index);
88 }

Callers 3

TestInsertLoggingMethod · 0.85

Calls 15

CanonicalInputNameFunction · 0.85
NodeNamePartsFromInputFunction · 0.85
InvalidArgumentFunction · 0.85
StartsWithFunction · 0.85
GetInOutTypesFunction · 0.85
RenameNodeInputsFunction · 0.85
GetOneStringParameterMethod · 0.80
GetOneBoolParameterMethod · 0.80
GetOneInt32ParameterMethod · 0.80
set_opMethod · 0.80
SetNodeAttrFunction · 0.70
nameMethod · 0.65

Tested by 3

TestInsertLoggingMethod · 0.68