# Backward for negative log likelihood loss of MultivariateNormal (in distributions)

**URL:** <https://discuss.pytorch.org/t/backward-for-negative-log-likelihood-loss-of-multivariatenormal-in-distributions/15339>\
**Category:** autograd\
**Created:** [March 23, 2018, 2:57am UTC](https://discuss.pytorch.org/t/backward-for-negative-log-likelihood-loss-of-multivariatenormal-in-distributions/15339 "2018-03-23T02:57:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fritzo](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/fritzo/32/34992_2.png) [@fritzo](https://discuss.pytorch.org/u/fritzo)\
**Post date:** [April 21, 2018, 2:08am UTC](https://discuss.pytorch.org/t/backward-for-negative-log-likelihood-loss-of-multivariatenormal-in-distributions/15339/2 "2018-04-21T02:08:59Z")

</div>

`Normal` is a batched univariate distribution. Your `mu` is being broadcast up to the same shape as `C`, producing an `n,n` batch of univariate normals. If you want a `MultivariateNormal` distribution, use

```auto
n = 5
mu = torch.zeros(n)
C = torch.eye(n, n)
m = torch.distributions.MultivariateNormal(mu, covariance_matrix=C)
x = m.sample() # should have shape (n,)
loss = -m.log_prob(x) # should be a scalar

```

---

_[View the full topic](https://discuss.pytorch.org/t/backward-for-negative-log-likelihood-loss-of-multivariatenormal-in-distributions/15339)._
