message: Don't remove leaf identity nodes, they are used in some models as fetch nodes. And when they aren't fetched, they won't be evaluated anyway.
diff: @@ -679,10 +679,16 @@ bool RemoveIdentityNodes(Graph* g) {
  bool removed_any = false;
  gtl::InlinedVector<Node*, 8> matches;
  for (Node* n : g->nodes()) {
  - if (n->IsIdentity() && GetTheOnlyDataEdge(n->in_edges())) {
  + if (!n->IsIdentity()) continue;
  + if (!GetTheOnlyDataEdge(n->in_edges())) continue;
  +
  + // Some identity nodes are used as sink nodes to give names to output
  + // tensors. These nodes are not going to be executed unless they are in the
  + // fetch set. But if they are in the fetch set we don't want to remove them.
  + if (n->out_edges().empty()) continue;
  +
  matches.push_back(n);
  }
  - }
  if (!matches.empty()) {
  for (Node* n : matches) {
  const Edge* in = GetTheOnlyDataEdge(n->in_edges());
  