tensorflow/core/tpu/graph_rewrite/combine_tpu_embedding_load_retrieve_pass.cc
// Gets TPUEmbeddingConfiguration proto from embedding ops.
Gets TPUEmbeddingConfiguration proto from embedding ops.
Gets TPUEmbeddingConfiguration proto from embedding ops .
Status GetTPUEmbeddingConfiguration(
    Graph* graph,
    tensorflow::tpu::TPUEmbeddingConfiguration* tpu_embedding_config,
    std::string* tpu_embedding_config_str) {
  bool have_config = false;
  const absl::flat_hash_set<std::string> load_retrieve_nodes =
      GetLoadRetrieveNodeNames();
  for (Node* n : graph->nodes()) {
    const auto& node_name = n->op_def().name();
    if (n->IsOp() && (load_retrieve_nodes.contains(node_name) ||
                      node_name == "_RecvTPUEmbeddingActivations" ||
                      node_name == "_SendTPUEmbeddingGradients" ||
                      node_name == "ConfigureTPUEmbedding")) {
      std::string test_tpu_embedding_config_str;
      TF_RETURN_IF_ERROR(
          GetNodeAttr(n->def(), "config", &test_tpu_embedding_config_str));
      if (test_tpu_embedding_config_str.empty()) {
        if (load_retrieve_nodes.contains(node_name)) {
          continue;
        } else if (node_name == "ConfigureTPUEmbedding") {
          return errors::InvalidArgument(
              "ConfigureTPUEmbedding used but no configuration provided");
        }
      }
      if (have_config) {
        TF_RET_CHECK(test_tpu_embedding_config_str ==
                     *tpu_embedding_config_str);
      } else {
        have_config = true;
        *tpu_embedding_config_str = test_tpu_embedding_config_str;
        TF_RET_CHECK(
            tpu_embedding_config->ParseFromString(*tpu_embedding_config_str));
      }
    }
  }
  if (!have_config) {
    return errors::InvalidArgument("No TPU embedding config provided");
  }
  return Status::OK();
}
Status GetTPUEmbeddingConfiguration ( Graph * graph , tensorflow :: tpu :: TPUEmbeddingConfiguration * tpu_embedding_config , std :: string * tpu_embedding_config_str ) { bool have_config = false ; const absl :: flat_hash_set < std :: string > load_retrieve_nodes = GetLoadRetrieveNodeNames ( ) ; for ( Node * n : graph -> nodes ( ) ) { const auto & node_name = n -> op_def ( ) . name ( ) ; if ( n -> IsOp ( ) && ( load_retrieve_nodes . contains ( node_name ) || node_name == " " || node_name == " " || node_name == " " ) ) { std :: string test_tpu_embedding_config_str ; TF_RETURN_IF_ERROR ( GetNodeAttr ( n -> def ( ) , " " , & test_tpu_embedding_config_str ) ) ; if ( test_tpu_embedding_config_str . empty ( ) ) { if ( load_retrieve_nodes . contains ( node_name ) ) { continue ; } else if ( node_name == " " ) { return errors :: InvalidArgument ( " " ) ; } } if ( have_config ) { TF_RET_CHECK ( test_tpu_embedding_config_str == * tpu_embedding_config_str ) ; } else { have_config = true ; * tpu_embedding_config_str = test_tpu_embedding_config_str ; TF_RET_CHECK ( tpu_embedding_config -> ParseFromString ( * tpu_embedding_config_str ) ) ; } } } if ( ! have_config ) { return errors :: InvalidArgument ( " " ) ; } return Status :: OK ( ) ; }
Gets TPUEmbeddingConfiguration proto from embedding ops.
Gets TPUEmbeddingConfiguration proto from embedding ops .