Stabilize Gaussian mixture backward passes#3452
Conversation
|
thanks @jburroni! your diff changed a bunch of other files so you'll need to fix that if you want this reviewed and merged |
|
Hi @martinjankowiak! The GH actions seem to be broken, and I don't know how to proceed. What do you suggest? |
|
Hi @martinjankowiak, I've removed everything that was not strictly related to the PR. |
martinjankowiak
left a comment
There was a problem hiding this comment.
thanks @jburroni !
|
Thank you for your feedback @martinjankowiak I made a mistake in my previous version. I'm sorry. I’ve now improved my changes to I also removed manual seeding from the new tests. |
martinjankowiak
left a comment
There was a problem hiding this comment.
looks good, thanks for doing this!
| r_j_poly = r_sqr_j.unsqueeze(-1).expand(-1, int(dim / 2)) # l j d/2 | ||
| r_j_poly = coeffs * torch.pow(r_j_poly, exponents) | ||
| Phi_j *= r_j_poly.sum(-1) | ||
| if dim % 2 == 1: |
There was a problem hiding this comment.
does test_mean_gradient pass with D=3? unclear to me if we're testing this branch properly. this would be an existing issue, but good to check?
Summary
This PR fixes numerical instabilities in the backward passes for Pyro's Gaussian mixture distributions:
MixtureOfDiagNormalsGaussianScaleMixtureMixtureOfDiagNormalsSharedCovarianceThe affected backward paths can materialize very small density/product terms in probability space. In float32, these terms can underflow to zero, which can then produce nonfinite gradients during backpropagation.
Changes
Adds regression tests that assert finite gradients in numerically sensitive high-dimensional / small-scale cases.
Updates the affected backward computations to avoid unstable probability-space divisions/products where possible.
Format code to pass lint.
Tests
Added regression coverage for:
small-scale
MixtureOfDiagNormalssmall-scale
GaussianScaleMixturehigh-dimensional
MixtureOfDiagNormalsSharedCovarianceEach test verifies that samples, losses, and parameter gradients remain finite.