class_docstr: A collection of decoder tests. This class should be inherited together with
  `tf.test.TestCase`.
class_docstr_tok: ["A","collection","of","decoder","tests",".","This","class","should","be","inherited","together","with","`","tf.test.TestCase","`","."]
code: def test_gradients(self):
      inputs = tf.random_normal(
          [self.batch_size, self.sequence_length, self.input_depth]
      )
      seq_length = (
          tf.ones(self.batch_size, dtype=tf.int32)
          * self.sequence_length
      )
      labels = np.random.randint(
          0, self.vocab_size, [self.batch_size, self.sequence_length]
      )
  
      helper = decode_helper.TrainingHelper(
          inputs=inputs, sequence_length=seq_length
      )
      decoder_fn = self.create_decoder(
          helper=helper, mode=tf.contrib.learn.ModeKeys.TRAIN
      )
      initial_state = decoder_fn.cell.zero_state(
          self.batch_size, dtype=tf.float32
      )
      decoder_output, _ = decoder_fn(initial_state, helper)
  
      losses = tf.nn.sparse_softmax_cross_entropy_with_logits(
          logits=decoder_output.logits, labels=labels
      )
      optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
      grads_and_vars = optimizer.compute_gradients(
          tf.reduce_mean(losses)
      )
  
      # pylint: disable=E1101
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          grads_and_vars_ = sess.run(grads_and_vars)
  
      for grad, _ in grads_and_vars_:
          self.assertFalse(np.isnan(grad).any())
  
      return grads_and_vars_
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import tensorflow
  import numpy
  from seq2seq.decoders import BasicDecoder, AttentionDecoder, AttentionLayerDot
  from seq2seq.decoders import beam_search_decoder
  from seq2seq.inference import beam_search
  from seq2seq.contrib.seq2seq import helper
label_desc: Use image node_id 4 for calling the DecoderTests obj's underlying member method code with example usage: obj.test_gradients() and returns: grads_and_vars_