code: def testTotalLossGradients(self, is_multi_actions):
      with self.test_session() as sess:
          if is_multi_actions:
              total_loss = tf.reduce_sum(self.multi_op.loss)
              policy_logits_nest = self.multi_policy_logits
          else:
              total_loss = tf.reduce_sum(self.op.loss)
              policy_logits_nest = self.policy_logits
  
          grad_policy_list = [
              tf.gradients(total_loss, policy_logits)[0]
              for policy_logits in nest.flatten(policy_logits_nest)
          ]
          grad_baseline = tf.gradients(
              total_loss, self.baseline_values
          )[0]
  
          for grad_policy in grad_policy_list:
              self.assertEqual(
                  grad_policy.get_shape(), tf.TensorShape([2, 1, 3])
              )
              # These values were just generated once and hard-coded here to check for
              # regressions. Calculating by hand would be too time-consuming,
              # error-prone and unreadable.
              self.assertAllClose(
                  sess.run(grad_policy),
                  [
                      [[-0.5995, 0.1224, 0.4770]],
                      [[0.0288, -0.0576, 0.0288]],
                  ],
                  atol=1e-4,
              )
          self.assertEqual(
              grad_baseline.get_shape(), tf.TensorShape([2, 1])
          )
          self.assertAllClose(
              sess.run(grad_baseline), [[-0.1083], [-0.0420]], atol=1e-4
          )
  
          self.assertAllEqual(
              tf.gradients(total_loss, self.invalid_grad_inputs),
              self.invalid_grad_outputs,
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  import numpy
  from six.moves import xrange
  import tensorflow.compat.v1
  import tree
  from trfl import discrete_policy_gradient_ops
label_desc: Use image node_id 6 for calling the SequenceAdvantageActorCriticLossGradientTest obj's underlying member method code with example usage: obj.testTotalLossGradients(is_multi_actions) without return types