code: def kl_mvn_mvn(
      p_dist: MultivariateNormal, q_dist: MultivariateNormal
  ) -> Tensor:
      output_shape = torch.broadcast_shapes(
          p_dist.batch_shape, q_dist.batch_shape
      )
      if output_shape != p_dist.batch_shape:
          p_dist = p_dist.expand(output_shape)
      if output_shape != q_dist.batch_shape:
          q_dist = q_dist.expand(output_shape)
  
      q_mean = q_dist.loc
      q_covar = q_dist.lazy_covariance_matrix
  
      p_mean = p_dist.loc
      p_covar = p_dist.lazy_covariance_matrix
      root_p_covar = p_covar.root_decomposition().root.to_dense()
  
      mean_diffs = p_mean - q_mean
      if isinstance(root_p_covar, LinearOperator):
          # right now this just catches if root_p_covar is a DiagLinearOperator,
          # but we may want to be smarter about this in the future
          root_p_covar = root_p_covar.to_dense()
      inv_quad_rhs = torch.cat(
          [mean_diffs.unsqueeze(-1), root_p_covar], -1
      )
      logdet_p_covar = p_covar.logdet()
      (
          trace_plus_inv_quad_form,
          logdet_q_covar,
      ) = q_covar.inv_quad_logdet(
          inv_quad_rhs=inv_quad_rhs, logdet=True
      )
  
      # Compute the KL Divergence.
      res = 0.5 * sum(
          [
              logdet_q_covar,
              logdet_p_covar.mul(-1),
              trace_plus_inv_quad_form,
              -float(mean_diffs.size(-1)),
          ]
      )
      return res
  
imports: from __future__ import annotations
  import math
  import warnings
  from numbers import Number
  from typing import Optional, Tuple, Union
  import torch
  from linear_operator import to_dense, to_linear_operator
  from linear_operator.operators import DiagLinearOperator, LinearOperator, RootLinearOperator
  from torch import Tensor
  from torch.distributions import MultivariateNormal
  from torch.distributions.kl import register_kl
  from torch.distributions.utils import _standard_normal, lazy_property
  from ..None import settings
  from ..utils.warnings import NumericalWarning
  from .distribution import Distribution
label_desc: Use image node_id 1 for calling a global function with example usage: kl_mvn_mvn(p_dist, q_dist) and returns: res