tensorflow/core/tpu/graph_rewrite/tpu_embedding_software_deduplication_rewrite_pass.cc
// Gets the TPUEmbeddingConfiguration proto, assigned device name, and index
// from the graph nodes (activations_node and gradients_node). If both nodes are
// present, ensure that the TPUEmbeddingConfiguration proto, assigned device
// name, and index are the same on both nodes.
Gets the TPUEmbeddingConfiguration proto, assigned device name, and index
from the graph nodes (activations_node and gradients_node). If both nodes are
present, ensure that the TPUEmbeddingConfiguration proto, assigned device
name, and index are the same on both nodes.
Gets the TPUEmbeddingConfiguration proto assigned device name and index from the graph nodes ( activations_node and gradients_node ) . If both nodes are present ensure that the TPUEmbeddingConfiguration proto assigned device name and index are the same on both nodes .
Status ValidateAndGetTPUEmbeddingConfiguration(
    const Node* activations_node, const Node* gradients_node,
    absl::string_view tpu_replicate_attr,
    std::string* tpu_embedding_config_str) {
  if (activations_node != nullptr && gradients_node != nullptr) {
    std::string activations_config_str;
    std::string gradients_config_str;
    TF_RETURN_IF_ERROR(GetNodeAttr(activations_node->def(), "config",
                                   &activations_config_str));
    TF_RETURN_IF_ERROR(
        GetNodeAttr(gradients_node->def(), "config", &gradients_config_str));
    if (activations_config_str != gradients_config_str) {
      return errors::InvalidArgument(absl::StrFormat(
          "TPU embedding config attributes of RecvTPUEmbeddingActivations and "
          "SendTPUEmbeddingGradients nodes with the same tpu_replicate attr: "
          "%s are not identical.",
          tpu_replicate_attr));
    }
    if (activations_node->assigned_device_name() !=
        gradients_node->assigned_device_name()) {
      return errors::InvalidArgument(absl::StrFormat(
          "Mismatch in assigned device names for the "
          "RecvTPUEmbeddingActivations (%s) and SendTPUEmbeddingGradients (%s) "
          "nodes with the same tpu_replicate attr: %s.",
          activations_node->assigned_device_name(),
          gradients_node->assigned_device_name(), tpu_replicate_attr));
    }
    if (activations_node->assigned_device_name_index() !=
        gradients_node->assigned_device_name_index()) {
      return errors::InvalidArgument(absl::StrFormat(
          "Mismatch in assigned device name indices for the "
          "RecvTPUEmbeddingActivations (%d) and SendTPUEmbeddingGradients (%d) "
          "nodes with the same tpu_replicate attr: %s.",
          activations_node->assigned_device_name_index(),
          gradients_node->assigned_device_name_index(), tpu_replicate_attr));
    }
  }
  if (activations_node == nullptr && gradients_node == nullptr) {
    return errors::Internal(absl::StrFormat(
        "Found tpu_replicate attr: %s with no corresponding "
        "RecvTPUEmbeddingActivations or SendTPUEmbeddingGradients nodes",
        tpu_replicate_attr));
  }
  const Node* compile_node =
      (activations_node != nullptr) ? activations_node : gradients_node;
  TF_RETURN_IF_ERROR(
      GetNodeAttr(compile_node->def(), "config", tpu_embedding_config_str));
  return Status::OK();
}
Status ValidateAndGetTPUEmbeddingConfiguration ( const Node * activations_node , const Node * gradients_node , absl :: string_view tpu_replicate_attr , std :: string * tpu_embedding_config_str ) { if ( activations_node != nullptr && gradients_node != nullptr ) { std :: string activations_config_str ; std :: string gradients_config_str ; TF_RETURN_IF_ERROR ( GetNodeAttr ( activations_node -> def ( ) , " " , & activations_config_str ) ) ; TF_RETURN_IF_ERROR ( GetNodeAttr ( gradients_node -> def ( ) , " " , & gradients_config_str ) ) ; if ( activations_config_str != gradients_config_str ) { return errors :: InvalidArgument ( absl :: StrFormat ( " " " " " " , tpu_replicate_attr ) ) ; } if ( activations_node -> assigned_device_name ( ) != gradients_node -> assigned_device_name ( ) ) { return errors :: InvalidArgument ( absl :: StrFormat ( " " " " " " , activations_node -> assigned_device_name ( ) , gradients_node -> assigned_device_name ( ) , tpu_replicate_attr ) ) ; } if ( activations_node -> assigned_device_name_index ( ) != gradients_node -> assigned_device_name_index ( ) ) { return errors :: InvalidArgument ( absl :: StrFormat ( " " " " " " , activations_node -> assigned_device_name_index ( ) , gradients_node -> assigned_device_name_index ( ) , tpu_replicate_attr ) ) ; } } if ( activations_node == nullptr && gradients_node == nullptr ) { return errors :: Internal ( absl :: StrFormat ( " " " " , tpu_replicate_attr ) ) ; } const Node * compile_node = ( activations_node != nullptr ) ? activations_node : gradients_node ; TF_RETURN_IF_ERROR ( GetNodeAttr ( compile_node -> def ( ) , " " , tpu_embedding_config_str ) ) ; return Status :: OK ( ) ; }
Gets the TPUEmbeddingConfiguration proto, assigned device name, and index
from the graph nodes (activations_node and gradients_node).
Gets the TPUEmbeddingConfiguration proto assigned device name and index from the graph nodes ( activations_node and gradients_node ) .