I am fitting a very simple VAE model with two latent variables, one which specifies Normal latent exposures (original spec) and a second that specifies latent clusters (recent addition to model) with 40 clusters, a temperature of 0.35 and a dtype of float32. The prior was specifies using probs was passed to the RelaxedOneHotCategorical constructor as probs=XXX in the guide / model and the parameter that was being fit was passed to sample(…, obs=XXX) in the model.
The smoke test came together quickly (5 iteration) and then I began fitting the model with roughly 75 iterations.
Once it started fitting, I would see issues where some fits worked fine. But occasionally – increasingly frequent with the number of iterations which appears conditioned on the temperature value – I would get errors ending the fit. The probs passed to the Distribution had these values:
tensor([0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250,
0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250,
0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250,
0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250, 0.0250,
0.0250, 0.0250, 0.0250, 0.0250])
The fit params variable in sample(obs=XXX) had these values:
in sample(obs=XXX) had these values:
tensor([9.9970e06, 9.9970e06, 9.9970e06, 9.9970e06, 9.9970e06, 9.9970e06,
9.9970e06, 9.9970e06, 9.9970e06, 9.9970e06, 9.2487e01, 9.9970e06,
9.9970e06, 2.0528e04, 9.9970e06, 9.9970e06, 9.9970e06, 9.9970e06,
9.9970e06, 9.9970e06, 9.9970e06, 9.9970e06, 1.0555e04, 9.9970e06,
9.9970e06, 9.9970e06, 2.1660e05, 6.1786e02, 9.9970e06, 9.9970e06,
9.9970e06, 9.9970e06, 6.1573e04, 9.9970e06, 9.9970e06, 9.9970e06,
9.9970e06, 9.9970e06, 1.2062e02, 9.9970e06])
The error in this case was:
ValueError: Expected value argument (Tensor of shape (40,)) to be within the support (Simplex()) of the distribution RelaxedOneHotCategorical(), but found invalid values:
tensor([9.4518e01, 1.1688e11, 5.2286e12, 5.6717e11, 2.4537e13, 4.0543e14,
6.5703e12, 5.0752e12, 5.4818e02, 4.2382e11, 2.1359e12, 1.0125e13,
1.0480e12, 2.0709e12, 3.0333e10, 1.3162e13, 4.4372e12, 3.1155e12,
4.3695e14, 1.3960e12, 1.4140e11, 1.0914e11, 2.0808e12, 4.7455e12,
2.8321e12, 3.8122e12, 2.4209e11, 4.7964e13, 4.1868e10, 5.1994e12,
4.0029e12, 2.9496e12, 5.8078e13, 8.1536e11, 2.0167e07, 1.7596e11,
5.0181e13, 5.7172e09, 5.4377e14, 1.8678e08])
Some thoughts / observations:

Raising the temperature reduces the frequent of what looks like a nondeterministic explosion

The shift to the values in param to the probabilities indicated by RelaxedOneHotCategorical are obviously controlled by the temperature value

Suppressing the error allows the fit to continue (the error will not reoccur on the next evaluation of svi.step, but obviously this is not a solution I would entertain.

The probabilities in the prior and in the parameter object passed to XXX.sample(…, obs=param_k) both add to exactly one but the probabilities that come out of RelaxedOneHotCategorical.sample in the failing example sum to 0.9999960000000008

Switching the dtype to float64 also reduces the frequency, but this also isn’t a solution.
Questions / Requests:

What would be an example of an invalid value? What are the boundaries on this?

What does “ValueError: Expected value argument (Tensor of shape (40,)) to be within the support (Simplex()) of the distribution RelaxedOneHotCategorical(), but found invalid values” really mean? It looks like the values on the least likely clusters are so small that there isn’t enough room for a valid Simplex.

Would it be possible in such an example to provide the name of the parameter in the parameter store in such cases where the failing values are caused by a parameter (e.g. for context / forensics) The output lists all of the distributions being sampled but in my case there are one set of latent factors (the Normal distribution values) and one latent cluster map for each county in the United States (~ 4000 counties) so the list is 8000+ samples large. My interest is really in the one sample that caused the failure?
Getting a simple example of the failure has been challenging:
 Smoke test always works
 Fitting just a handful of counties has never required enough evaluations / draws to present the problem
 The exception data isn’t great in providing enough color to identify or reproduce the problem
4.) Would adding upper / lower probabilities boundaries – in RelaxedOneHotCategorical, not in the parameter bijector – resolve the issue? In this case the simplex would still have room to search, but again that solution – specifying boundaries that ensure a valid Simplex – would depend on the choice for temperature.
Together it looks like there is a bit of code that gives rise to a numerical precision error in building the Simplex. Also the output of RelaxedOneHotCategorical.sample(…) should sum to one.