Skip to content
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

R1.10 cherry-pick request: Fix tensorrt conversion to ignore all preserved nodes #20863

Merged
merged 2 commits into from
Jul 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion tensorflow/contrib/tensorrt/convert/trt_optimization_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#include "tensorflow/core/grappler/clusters/cluster.h"
#include "tensorflow/core/grappler/grappler_item.h"
#include "tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.h"
#include "tensorflow/core/lib/strings/numbers.h"
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/logging.h"
Expand Down Expand Up @@ -232,8 +233,25 @@ tensorflow::Status TRTOptimizationPass::Optimize(
tensorflow::grappler::GraphProperties static_graph_properties(item);
TF_RETURN_IF_ERROR(static_graph_properties.InferStatically(true));
tensorflow::tensorrt::convert::ConversionParams cp;

std::vector<string> nodes_to_preserve;
for (const auto& n : item.NodesToPreserve()) {
auto tokens = str_util::Split(n, ":");
string s = tokens.at(0);
for (int i = 1; i < tokens.size() - 1; ++i) {
StrAppend(&s, ":", tokens.at(i));
}
int dumm_port = -1;
// If the last token is not an integer, it must be part of the name.
// Otherwise it is port number.
if (tokens.size() > 1 &&
!strings::safe_strto32(tokens.back(), &dumm_port)) {
StrAppend(&s, ":", tokens.back());
}
nodes_to_preserve.push_back(s);
}
cp.input_graph_def = &item.graph;
cp.output_names = &item.fetch;
cp.output_names = &nodes_to_preserve;
cp.max_batch_size = maximum_batch_size_;
cp.max_workspace_size_bytes = maximum_workspace_size_;
cp.output_graph_def = optimized_graph;
Expand Down