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

Method BuildAndReplace

tensorflow/compiler/tf2xla/functionalize_cond.cc:888–920  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

886}
887
888Status Conditional::BuildAndReplace(
889 Graph* graph, FunctionLibraryDefinition* library,
890 std::unordered_map<Node*, OutputTensor>* merge_to_replacement) {
891 VLOG(1) << "Build If and replace merge nodes "
892 << NodesToString(this->merges_);
893 if (replaced_) return Status::OK();
894
895 TF_RETURN_IF_ERROR(ExtractBodies(graph));
896 TF_RETURN_IF_ERROR(BuildArgumentNodes());
897
898 if (VLOG_IS_ON(3)) {
899 LOG(INFO) << "Extracted bodies:";
900 for (auto branch : {BranchType::kElseBranch, BranchType::kThenBranch}) {
901 int branch_index = static_cast<int>(branch);
902 auto output = bodies_[branch_index].get();
903 LOG(INFO) << Branch_Name(branch) << ": "
904 << DebugString(output->ToGraphDefDebug());
905 }
906 }
907
908 TF_RETURN_IF_ERROR(BuildIfNode(graph, library));
909 TF_RETURN_IF_ERROR(AddInputEdges(graph, *merge_to_replacement));
910 TF_RETURN_IF_ERROR(AddOutputEdges(graph, merge_to_replacement));
911 TF_RETURN_IF_ERROR(parent_->PropagateUpdatedState(if_node_));
912
913 // Check that the if_node doesn't feed into itself.
914 TF_RETURN_WITH_CONTEXT_IF_ERROR(
915 CheckNodeNotInCycle(if_node_, graph->num_node_ids()),
916 "Converting to If failed.");
917
918 replaced_ = true;
919 return Status::OK();
920}
921
922string Conditional::name() const {
923 CHECK(!merges_.empty());

Callers 1

FunctionalizeInternalMethod · 0.80

Calls 8

NodesToStringFunction · 0.85
Branch_NameFunction · 0.85
CheckNodeNotInCycleFunction · 0.85
ToGraphDefDebugMethod · 0.80
PropagateUpdatedStateMethod · 0.80
DebugStringFunction · 0.70
getMethod · 0.45
num_node_idsMethod · 0.45

Tested by

no test coverage detected