code: def _kl_independent_independent(dist1, dist2):
      """Computes Kullback-Leibler divergence for independent distributions.
  
      We can leverage the fact that
      .. math::
          \\mathrm{KL}(
                  \\mathrm{Independent}(\\mathrm{dist1}) ||
                  \\mathrm{Independent}(\\mathrm{dist2}))
          = \\mathrm{sum}(\\mathrm{KL}(\\mathrm{dist1} || \\mathrm{dist2}))
      where the sum is over the ``reinterpreted_batch_ndims``.
  
      Args:
          dist1 (:class:`~chainer.distribution.Independent`): Instance of
              `Independent`.
          dist2 (:class:`~chainer.distribution.Independent`): Instance of
              `Independent`.
  
      Returns:
          Batchwise ``KL(dist1 || dist2)``.
  
      Raises:
          :class:`ValueError`: If the event space for ``dist1`` and ``dist2``,
              or their underlying distributions don't match.
      """
  
      p = dist1.distribution
      q = dist2.distribution
  
      # The KL between any two (non)-batched distributions is a scalar.
      # Given that the KL between two factored distributions is the sum, i.e.
      # KL(p1(x)p2(y) || q1(x)q2(y)) = KL(p1 || q1) + KL(q1 || q2), we compute
      # KL(p || q) and do a `reduce_sum` on the reinterpreted batch dimensions.
      if dist1.event_shape == dist2.event_shape:
          if p.event_shape == q.event_shape:
              n_axes = len(dist1.event_shape) - len(p.event_shape)
              n_reduce_dims = tuple([-i - 1 for i in range(0, n_axes)])
  
              return sum_mod.sum(
                  distribution.kl_divergence(p, q), axis=n_reduce_dims
              )
          else:
              raise NotImplementedError(
                  "KL between Independents with different "
                  "event shapes not supported."
              )
      else:
          raise ValueError("Event shapes do not match.")
  
imports: import numpy
  from chainer.backend import cuda
  from chainer import distribution
  from chainer.functions.array import repeat
  from chainer.functions.array import reshape
  from chainer.functions.array import transpose
  from chainer.functions.math import prod
  from chainer.functions.math import sum
  from chainer.utils import array
  from chainer.utils import cache
label_desc: Use image node_id 1 for calling a global function with example usage: _kl_independent_independent(dist1, dist2) and returns: sum_mod