tensorflow/core/tpu/graph_rewrite/tpu_embedding_software_deduplication_rewrite_pass.cc
// Constructs a NodeDef proto for the _RecvTPUEmbeddingActivations node to be
// added to the graph or function def.
Constructs a NodeDef proto for the _RecvTPUEmbeddingActivations node to be
added to the graph or function def.
Constructs a NodeDef proto for the _RecvTPUEmbeddingActivations node to be added to the graph or function def .
xla::StatusOr<NodeDef> MakeRecvActivationsNodeDef(
    const NodeDef& old_activations_node_def,
    absl::string_view deduplication_data_node_name,
    absl::string_view device_name, absl::string_view tpu_replicate_attr,
    absl::string_view tpu_embedding_config_str,
    absl::Span<const NodeDefBuilder::NodeOut> data_inputs,
    absl::Span<const std::string> control_inputs) {
  if (!data_inputs.empty()) {
    return errors::InvalidArgument(
        absl::StrFormat("Expected to have zero inputs for "
                        "RecvTPUEmbeddingActivations node, found %d inputs.",
                        data_inputs.size()));
  }
  tpu::TPUEmbeddingConfiguration tpu_embedding_config;
  if (!tpu_embedding_config.ParseFromString(
          std::string(tpu_embedding_config_str))) {  
    return errors::InvalidArgument(
        "Malformed config attribute in the RecvTPUEmbeddingActivations node.");
  }
  int32 num_outputs;
  TF_RETURN_IF_ERROR(GetNodeAttr(AttrSlice(old_activations_node_def),
                                 "num_outputs", &num_outputs));
  TF_RETURN_IF_ERROR(CheckNumInputsOrOutputs(num_outputs, "num_outputs",
                                             "RecvTPUEmbeddingActivations",
                                             tpu_embedding_config));
  NodeDefBuilder builder(old_activations_node_def.name(),
                         "_RecvTPUEmbeddingActivations");
  if (!device_name.empty()) {
    builder.Device(device_name);
  }
  builder.Attr("num_tables", num_outputs)
      .Attr("config", tpu_embedding_config_str);
  if (!tpu_replicate_attr.empty()) {
    builder.Attr("_tpu_replicate", tpu_replicate_attr);
  }
  std::string embedding_layer;
  if (TryGetNodeAttr(AttrSlice(old_activations_node_def),
                     "_tpu_embedding_layer", &embedding_layer)) {
    builder.Attr("_tpu_embedding_layer", embedding_layer);
  }
  builder.Input(absl::StrCat(deduplication_data_node_name, ":output"),
                0, DT_VARIANT);
  for (const std::string& control_input : control_inputs) {
    builder.ControlInput(control_input);
  }
  NodeDef activations_node_def;
  TF_RETURN_IF_ERROR(builder.Finalize(&activations_node_def));
  *activations_node_def.mutable_experimental_debug_info() =
      old_activations_node_def.experimental_debug_info();
  VLOG(1) << "Created new _RecvTPUEmbeddingActivations node def: "
          << activations_node_def.DebugString();
  return activations_node_def;
}
xla :: StatusOr < NodeDef > MakeRecvActivationsNodeDef ( const NodeDef & old_activations_node_def , absl :: string_view deduplication_data_node_name , absl :: string_view device_name , absl :: string_view tpu_replicate_attr , absl :: string_view tpu_embedding_config_str , absl :: Span < const NodeDefBuilder :: NodeOut > data_inputs , absl :: Span < const std :: string > control_inputs ) { if ( ! data_inputs . empty ( ) ) { return errors :: InvalidArgument ( absl :: StrFormat ( " " " " , data_inputs . size ( ) ) ) ; } tpu :: TPUEmbeddingConfiguration tpu_embedding_config ; if ( ! tpu_embedding_config . ParseFromString ( std :: string ( tpu_embedding_config_str ) ) ) { return errors :: InvalidArgument ( " " ) ; } int32 num_outputs ; TF_RETURN_IF_ERROR ( GetNodeAttr ( AttrSlice ( old_activations_node_def ) , " " , & num_outputs ) ) ; TF_RETURN_IF_ERROR ( CheckNumInputsOrOutputs ( num_outputs , " " , " " , tpu_embedding_config ) ) ; NodeDefBuilder builder ( old_activations_node_def . name ( ) , " " ) ; if ( ! device_name . empty ( ) ) { builder . Device ( device_name ) ; } builder . Attr ( " " , num_outputs ) . Attr ( " " , tpu_embedding_config_str ) ; if ( ! tpu_replicate_attr . empty ( ) ) { builder . Attr ( " " , tpu_replicate_attr ) ; } std :: string embedding_layer ; if ( TryGetNodeAttr ( AttrSlice ( old_activations_node_def ) , " " , & embedding_layer ) ) { builder . Attr ( " " , embedding_layer ) ; } builder . Input ( absl :: StrCat ( deduplication_data_node_name , " " ) , 0 , DT_VARIANT ) ; for ( const std :: string & control_input : control_inputs ) { builder . ControlInput ( control_input ) ; } NodeDef activations_node_def ; TF_RETURN_IF_ERROR ( builder . Finalize ( & activations_node_def ) ) ; * activations_node_def . mutable_experimental_debug_info ( ) = old_activations_node_def . experimental_debug_info ( ) ; VLOG ( 1 ) << " " << activations_node_def . DebugString ( ) ; return activations_node_def ; }
Constructs a NodeDef proto for the _RecvTPUEmbeddingActivations node to be
added to the graph or function def.
Constructs a NodeDef proto for the _RecvTPUEmbeddingActivations node to be added to the graph or function def .
// NOLINT // The num tables here can be interpreted as num features if the feature // descriptor is present in the config. /*src_index=*/