code: def _sparse_vs_dense_xent_benchmark_dense(labels, logits):
      labels = array_ops.identity(labels)
      logits = array_ops.identity(logits)
      with ops_lib.device("/cpu:0"):  # Sparse-to-dense must be on CPU
          batch_size = array_ops.shape(logits)[0]
          num_entries = array_ops.shape(logits)[1]
          length = batch_size * num_entries
          labels += num_entries * math_ops.range(batch_size)
          target = sparse_ops.sparse_to_dense(
              labels, array_ops_stack.stack([length]), 1.0, 0.0
          )
      target = array_ops.reshape(
          target, array_ops_stack.stack([-1, num_entries])
      )
      crossent = nn_ops.softmax_cross_entropy_with_logits(
          labels=target, logits=logits, name="SequenceLoss/CrossEntropy"
      )
      crossent_sum = math_ops.reduce_sum(crossent)
      grads = gradients_impl.gradients([crossent_sum], [logits])[0]
  
      return (crossent_sum, grads)
  
file_path: tensorflow-upstream/tensorflow/python/kernel_tests/sparse_ops/sparse_xent_op_test.py
imports: import sys
  import time
  from absl import app
  import numpy
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.python.client import session
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.kernel_tests.sparse_ops import sparse_xent_op_test_base
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import array_ops_stack
  from tensorflow.python.ops import gradients_impl
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import sparse_ops
  from tensorflow.python.ops.nn_grad import _SparseSoftmaxCrossEntropyWithLogitsGrad
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling a global function with example usage: _sparse_vs_dense_xent_benchmark_dense(labels, logits) and returns: crossent_sum,  grads