From a747e74440dd0ad4846b8f7c59492bfa3394bcc2 Mon Sep 17 00:00:00 2001 From: ThomasHeede <145970483+ThomasHeede@users.noreply.github.com> Date: Wed, 15 Oct 2025 11:51:05 +0200 Subject: [PATCH] Fix _log_beta_1 function for non-integer alphas The function __log_beta_1_ cannot handle the argument _is_sparse=True_ due to incorrect data type of instantiating _result = torch.zeros_like(value)_. I propose to add that the dtype should be the same as _alpha_; thus, _result = torch.zeros_like(value, dtype=alpha.dtype)_. The problem arises when: _result[mask] = (torch.lgamma(1 + value) + torch.lgamma(alpha) - torch.lgamma(value + alpha))_, as result[mask].dtype >> torch.int64 and (torch.lgamma(1 + value) + torch.lgamma(alpha) - torch.lgamma(value + alpha)).dtype >> torch.float32 --- pyro/distributions/conjugate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyro/distributions/conjugate.py b/pyro/distributions/conjugate.py index ffb37f3148..ce5cc59574 100644 --- a/pyro/distributions/conjugate.py +++ b/pyro/distributions/conjugate.py @@ -18,7 +18,7 @@ def _log_beta_1(alpha, value, is_sparse): if is_sparse: mask = value != 0 value, alpha, mask = torch.broadcast_tensors(value, alpha, mask) - result = torch.zeros_like(value) + result = torch.zeros_like(value, dtype=alpha.dtype) value = value[mask] alpha = alpha[mask] result[mask] = (