Check that the graph doesn't have any invalid nodes (e.g. incompatible with given device_type, invalid data type, missing attributes...)
| 1105 | // Check that the graph doesn't have any invalid nodes (e.g. incompatible with |
| 1106 | // given device_type, invalid data type, missing attributes...) |
| 1107 | Status ValidateGraph(const Graph* graph, |
| 1108 | const FunctionLibraryDefinition& flib_def, |
| 1109 | const DeviceType& device_type, const string& name) { |
| 1110 | // Make sure the XLA compilation kernels are registered. This operation is |
| 1111 | // idempotent so it is fine if someone called it already. |
| 1112 | XlaOpRegistry::RegisterCompilationKernels(); |
| 1113 | |
| 1114 | auto maybe_error = [&](const Node* node, const Status& s) -> Status { |
| 1115 | if (!s.ok()) { |
| 1116 | return errors::InvalidArgument(absl::StrCat( |
| 1117 | "Detected unsupported operations when trying to compile graph ", name, |
| 1118 | " on ", device_type.type_string(), ": ", node->def().op(), " (", |
| 1119 | s.error_message(), ")", FormatNodeForError(*node))); |
| 1120 | } |
| 1121 | return Status::OK(); |
| 1122 | }; |
| 1123 | |
| 1124 | for (const Node* node : graph->nodes()) { |
| 1125 | if (node->type_string() == FunctionLibraryDefinition::kGradientOp) { |
| 1126 | continue; |
| 1127 | } |
| 1128 | const string* function_name; |
| 1129 | TF_RETURN_IF_ERROR(GetPotentialFunctionName(*node, &function_name)); |
| 1130 | const FunctionDef* fdef = flib_def.Find(*function_name); |
| 1131 | Status s; |
| 1132 | if (fdef) { |
| 1133 | s = ValidateFunctionDef(fdef, flib_def); |
| 1134 | TF_RETURN_IF_ERROR(maybe_error(node, s)); |
| 1135 | continue; |
| 1136 | } |
| 1137 | const OpDef* op_def; |
| 1138 | s = OpRegistry::Global()->LookUpOpDef(node->def().op(), &op_def); |
| 1139 | TF_RETURN_IF_ERROR(maybe_error(node, s)); |
| 1140 | TF_RETURN_IF_ERROR(ValidateNodeDef(node->def(), *op_def)); |
| 1141 | s = FindKernelDef(device_type, node->def(), nullptr, nullptr); |
| 1142 | TF_RETURN_IF_ERROR(maybe_error(node, s)); |
| 1143 | } |
| 1144 | return Status::OK(); |
| 1145 | } |
| 1146 | |
| 1147 | // Converts the value of any expressions whose values are known at compile-time |
| 1148 | // to constants. |
no test coverage detected