Skip to content

Amortized VI fails at the first iteration with a bounded prior #2137

Closed

Description

@janfb

VIPosterior.train_amortized() stops at iteration 0 with a non-finite loss when the prior is a BoxUniform. The same setup with a Gaussian prior trains. It happens with NLE, NRE and NPE potentials. The amortized VI tests use Gaussian priors only, so CI does not catch it.

prior = BoxUniform(-3 * torch.ones(2), 3 * torch.ones(2))
theta = prior.sample((300,))
x = theta + 0.3 * torch.randn_like(theta)
nle = NLE(prior)
nle.append_simulations(theta, x).train(max_num_epochs=3)
posterior = nle.build_posterior(sample_with="vi")
posterior.train_amortized(theta, x, max_num_iters=5)
# RuntimeError: Training loss became non-finite at iteration 0: inf.

I think the conditional flow of amortized VI draws theta outside the support of the prior, where the potential is -inf. Single-x VI maps its flow through the support transform of the prior; amortized VI probably needs the same. A fix should come with a test that uses a bounded prior.

Activity

  1. added
    bug
    help wanted
    posteriors
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wantedposteriors

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions