Unexplainable Difference `.sample()` and `pyro.sample()`

Hey everyone,

after setting a breakpoint in my model(), I observe the following strange behaviour:

  • Using HalfCauchy(...).sample() to sample from a HalfCouchy returns random values.
  • Using pyro.sample("A", dist.HalfCauchy(...)) to sample from a HalfCouchy returns always 1.0!
ipdb> dist.HalfCauchy(torch.tensor([1.0])).sample()
ipdb> dist.HalfCauchy(torch.tensor([1.0])).sample()
ipdb> pyro.sample("A", dist.HalfCauchy(torch.tensor([1.0]))).item()
ipdb> pyro.sample("B", dist.HalfCauchy(torch.tensor([1.0]))).item()

The same behaviour is observable for more dimensions, e.g.,:

ipdb> pyro.sample("C", dist.HalfCauchy(torch.ones(10)))
tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])

I do not understand where this is coming from. Does anyone here has an idea?

However, when I execute the code in this pyro question, everything works like a charm…

P.S.: I spend my whole afternoon trying to find out what’s going on. Please, tell me there is a reasonable explanation for this or I might go crazy.

Looking like the samples come from init_to_feasible() initialization strategy of some algorithms. You might look into that direction.