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()
tensor([1.0535])
ipdb> dist.HalfCauchy(torch.tensor([1.0])).sample()
tensor([2.8069])
ipdb> pyro.sample("A", dist.HalfCauchy(torch.tensor([1.0]))).item()
1.0
ipdb> pyro.sample("B", dist.HalfCauchy(torch.tensor([1.0]))).item()
1.0

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.