tensorflow/core/tpu/graph_rewrite/update_tpu_embedding_ops_passes.cc
// Update the function def for a specific enqueue op.
Update the function def for a specific enqueue op.
Update the function def for a specific enqueue op .
Status UpdateTPUEmbeddingModePass::UpdateFunctionDefEnqueueOp(
    int enqueue, bool training, FunctionDef* function, bool* updated) {
  NodeDef* node = function->mutable_node_def(enqueue);
  int mode_override = node->input_size() - 1;
  while ((mode_override >= 0) && (node->input(mode_override).empty() ||
                                  (node->input(mode_override)[0] == '^'))) {
    mode_override--;
  }
  TF_RET_CHECK(mode_override >= 0) << "Can't find non-control input to "
                                   << "enqueue.";
  TF_RET_CHECK(!node->input(mode_override).empty());
  string select_name = std::vector<std::string>(
      absl::StrSplit(node->input(mode_override), ':'))[0];
  int select = 0;
  while ((select < function->node_def_size()) &&
         (function->node_def(select).name() != select_name)) {
    select++;
  }
  TF_RET_CHECK(select < function->node_def_size())
      << "Unable to find enqueue input node " << select_name << " in function "
      << function->signature().name();
  if (function->node_def(select).op() == "SelectV2") {
    (*node->mutable_input(mode_override)) =
        function->node_def(select).input(training ? 1 : 2);
    *updated = true;
  }
  return Status::OK();
}
Status UpdateTPUEmbeddingModePass :: UpdateFunctionDefEnqueueOp ( int enqueue , bool training , FunctionDef * function , bool * updated ) { NodeDef * node = function -> mutable_node_def ( enqueue ) ; int mode_override = node -> input_size ( ) - 1 ; while ( ( mode_override >= 0 ) && ( node -> input ( mode_override ) . empty ( ) || ( node -> input ( mode_override ) [ 0 ] == ' ' ) ) ) { mode_override -- ; } TF_RET_CHECK ( mode_override >= 0 ) << " " << " " ; TF_RET_CHECK ( ! node -> input ( mode_override ) . empty ( ) ) ; string select_name = std :: vector < std :: string > ( absl :: StrSplit ( node -> input ( mode_override ) , ' ' ) ) [ 0 ] ; int select = 0 ; while ( ( select < function -> node_def_size ( ) ) && ( function -> node_def ( select ) . name ( ) != select_name ) ) { select ++ ; } TF_RET_CHECK ( select < function -> node_def_size ( ) ) << " " << select_name << " " << function -> signature ( ) . name ( ) ; if ( function -> node_def ( select ) . op ( ) == " " ) { ( * node -> mutable_input ( mode_override ) ) = function -> node_def ( select ) . input ( training ? 1 : 2 ) ; * updated = true ; } return Status :: OK ( ) ; }
Update the function def for a specific enqueue op.
Update the function def for a specific enqueue op .
// When using the layer, the mode override input is a SelectV2 op, // which takes a training and eval op as input. We will simply short circut // the SelectV2 and take input from the correct op. // Find input node // Make the mode override input the same as the correct input of the // select v2.