code: def compute_extra_loss(layer, loss_fn=kl_divergence_monte_carlo):
      loss = 0.0
      if isinstance(layer, layers_lib.Sequential):
          for x in layer.layers:
              loss += compute_extra_loss(x)
      elif isinstance(layer, vi_lib.VariationalLayer):
          loss += loss_fn(
              layer.posterior, layer.prior, layer.posterior_value
          )
      return loss
  
file_path: probability/tensorflow_probability/python/experimental/nn/losses/losses.py
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.experimental.nn import layers
  from tensorflow_probability.python.experimental.nn import variational_base
  from tensorflow_probability.python.internal.reparameterization import FULLY_REPARAMETERIZED
  from tensorflow_probability.python.monte_carlo.expectation import expectation
label_desc: Use image node_id 4 for calling a global function with example usage: compute_extra_loss(layer, loss_fn) and returns: loss