code: def random_mvn(batch_shape, dim, *, requires_grad=False):
      """
      Generate a random MultivariateNormal distribution for testing.
      """
      rank = dim + dim
      loc = torch.randn(
          batch_shape + (dim,), requires_grad=requires_grad
      )
      cov = torch.randn(batch_shape + (dim, rank))
      cov = cov.matmul(cov.transpose(-1, -2))
      cov.requires_grad_(requires_grad)
      return dist.MultivariateNormal(loc, cov)
  
imports: import torch
  import pyro.distributions
  from pyro.ops.gaussian import Gaussian
  from tests.common import assert_close
label_desc: Use image node_id 2 for calling a global function with example usage: random_mvn(batch_shape, dim) and returns: dist