diff options
author | 2018-07-16 15:12:27 -0700 | |
---|---|---|
committer | 2018-07-16 15:12:48 -0700 | |
commit | 409c0673b6a98a02be19adba5e64a489bd28b703 (patch) | |
tree | f0d8c198eaf8202fa7229d6e5724fca36a16a799 /tensorflow/contrib/tensorrt | |
parent | a968fd3993f0cc0a54431a3f897a1a8ff4e717e3 (diff) | |
parent | 2203a79228ba40888515b0d71c99719b4429563a (diff) |
Merge pull request #20603 from aaroey:fix_const_nodes_adding_order
PiperOrigin-RevId: 204814139
Diffstat (limited to 'tensorflow/contrib/tensorrt')
-rw-r--r-- | tensorflow/contrib/tensorrt/convert/convert_graph.cc | 13 | ||||
-rw-r--r-- | tensorflow/contrib/tensorrt/test/tf_trt_integration_test.py | 7 |
2 files changed, 16 insertions, 4 deletions
diff --git a/tensorflow/contrib/tensorrt/convert/convert_graph.cc b/tensorflow/contrib/tensorrt/convert/convert_graph.cc index 6ebc30ca82..63d8eec7db 100644 --- a/tensorflow/contrib/tensorrt/convert/convert_graph.cc +++ b/tensorflow/contrib/tensorrt/convert/convert_graph.cc @@ -269,6 +269,7 @@ tensorflow::Status GetEngineInfo( const std::vector<tensorflow::Node*>& reverse_topo_order, EngineInfo* info) { std::vector<int> subgraph_node_ids; + std::set<int> added_const_node_ids; // Used to prevent double insertion. std::set<string> segment_devices; int input_port = 0; int output_port = 0; @@ -278,6 +279,7 @@ tensorflow::Status GetEngineInfo( // edge, thus there must not be any duplicates since source nodes of // input/output edges must be in different split of the graph. // TODO(aaroey): consider using node id and port instead. + // TODO(aaroey): using topo order instead of reverting reverse topo order. std::unordered_map<string, int> created_edges; for (auto it = reverse_topo_order.rbegin(); it != reverse_topo_order.rend(); ++it) { @@ -296,8 +298,7 @@ tensorflow::Status GetEngineInfo( << " neither have requested device nor assigned device"; } } - int node_id = node->id(); - subgraph_node_ids.push_back(node_id); + const int node_id = node->id(); for (const auto edge : node->in_edges()) { auto input_node = edge->src(); if (segment_nodes.count(input_node->name()) == 0) { @@ -307,7 +308,10 @@ tensorflow::Status GetEngineInfo( // won't be removed from the graph. If it doesn't have any edges, TF // will prune it out. if (input_node->type_string() == "Const") { - subgraph_node_ids.push_back(input_node->id()); + if (added_const_node_ids.count(input_node->id()) == 0) { + added_const_node_ids.insert(input_node->id()); + subgraph_node_ids.push_back(input_node->id()); + } } else if (!edge->IsControlEdge() && !input_node->IsSource()) { string s(input_node->name()); StrAppend(&s, ":", edge->src_output()); @@ -325,6 +329,9 @@ tensorflow::Status GetEngineInfo( } } } + // We need to add possible const input nodes before adding this node in + // order to keep the topological order. + subgraph_node_ids.push_back(node_id); for (const auto edge : node->out_edges()) { auto output_node = edge->dst(); if (segment_nodes.count(output_node->name()) == 0 && diff --git a/tensorflow/contrib/tensorrt/test/tf_trt_integration_test.py b/tensorflow/contrib/tensorrt/test/tf_trt_integration_test.py index d9c41f90d0..3c68c6e4e9 100644 --- a/tensorflow/contrib/tensorrt/test/tf_trt_integration_test.py +++ b/tensorflow/contrib/tensorrt/test/tf_trt_integration_test.py @@ -290,7 +290,12 @@ class TfTrtIntegrationTest(test_util.TensorFlowTestCase): def testIdempotence(self): # Test that applying tensorrt optimizer or offline conversion tools multiple # times to the same graph will result in same graph. - # TODO(aaroey): implement this. + # + # TODO(aaroey): currently the conversion is not deterministic, this is + # mainly because during tensorflow::ConvertGraphDefToGraph(), the graph uses + # EdgeSet which use a map keyed by Edge*, so the order of input/output edges + # of a node is nondeterministic, thus the order for segmenter to contract + # edges is nondeterministic. Need to evaluate whether we should fix this. pass |