code: def _discount_reward_tensor_2d(
      reward, sequence_length=None, discount=1.0, dtype=None
  ):
      if sequence_length is not None:
          reward = mask_sequences(
              reward, sequence_length, dtype=dtype, tensor_rank=2
          )
  
      if discount == 1.0:
          disc_reward = tf.cumsum(reward, axis=1, reverse=True)
      else:
          # [max_time, batch_size]
          rev_reward_T = tf.transpose(tf.reverse(reward, [1]), [1, 0])
          rev_reward_T_cum = tf.scan(
              fn=lambda acc, cur: cur + discount * acc,
              elems=rev_reward_T,
              initializer=tf.zeros_like(reward[:, 1]),
              back_prop=False,
          )
          disc_reward = tf.reverse(
              tf.transpose(rev_reward_T_cum, [1, 0]), [1]
          )
  
      return disc_reward
  
imports: import numpy
  import tensorflow
  from texar.tf.utils.shapes import mask_sequences
label_desc: Use image node_id 5 for calling a global function with example usage: _discount_reward_tensor_2d(reward, sequence_length, discount, dtype) and returns: disc_reward