docstr: Ensure _loss_single() respects optional 'weights' argument.
code: def testLossSingleWeights(self):
      """Ensure _loss_single() respects optional 'weights' argument."""
      with tf.Graph().as_default():
          with self.test_session() as sess:
              batch_size = 2
              sequence_size = 16
              vocab_size = 3
  
              model_hparams = hparam.HParams(
                  prepend_mode="none",
                  loss={},
                  weights_fn={},
                  label_smoothing=0.0,
                  shared_embedding_and_softmax_weights=False,
              )
  
              ph = problem_hparams.TestProblem(
                  vocab_size, vocab_size
              ).get_hparams(model_hparams)
  
              model = t2t_model.T2TModel(
                  model_hparams, problem_hparams=ph
              )
              logits = tf.zeros(
                  (batch_size, sequence_size, 1, 1, vocab_size)
              )
              feature = tf.ones((batch_size, sequence_size, 1, 1))
  
              # all-zero weights == zero loss.
              weights = tf.zeros((batch_size, sequence_size))
              loss_num, loss_denom = model._loss_single(
                  logits, "targets", feature, weights=weights
              )
              self.assertAllClose(
                  tf.zeros_like(loss_num), sess.run(loss_num)
              )
              self.assertAllClose(
                  tf.zeros_like(loss_denom), sess.run(loss_denom)
              )
  
              # non-zero weights > zero loss.
              weights = tf.ones((batch_size, sequence_size))
              loss_num, loss_denom = model._loss_single(
                  logits, "targets", feature, weights=weights
              )
              self.assertAllLess(0.0, sess.run(loss_num))
              self.assertAllClose(
                  batch_size * sequence_size, sess.run(loss_denom)
              )
  
file_path: tensor2tensor/tensor2tensor/utils/t2t_model_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.data_generators import problem_hparams
  from tensor2tensor.utils import hparam
  from tensor2tensor.utils import t2t_model
  from tensor2tensor.utils import test_utils
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling the T2TModelTest obj's underlying member method code with example usage: obj.testLossSingleWeights() without return types