Did you try this?

  
      pytorch.org
  
  
    

Probability distributions - torch.distributions — PyTorch 1.7.0 documentation 10



  
  
    
    
  
  


from  torch.distributions import multivariate_normal
dist = multivariate_normal.MultivariateNormal(loc=torch.zeros(5), covariance_matrix=torch.eye(5))
probability = torch.exp(dist.log_prob(torch.randn(5)))