Skip to content

Commit 858b5a4

Browse files
andyl7anThe Meridian Authors
authored andcommitted
Fix JAX 64-bit precision mismatches by adding strict PriorDistribution dtype checks.
PiperOrigin-RevId: 960436263
1 parent 1253205 commit 858b5a4

2 files changed

Lines changed: 547 additions & 142 deletions

File tree

meridian/model/prior_distribution.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,18 @@ class PriorDistribution:
512512
)
513513

514514
def __post_init__(self):
515+
if backend.float_dtype == np.float64:
516+
for field in dataclasses.fields(self):
517+
dist = getattr(self, field.name)
518+
if dist is None:
519+
continue
520+
dist_dtype = getattr(dist, 'dtype', None)
521+
if dist_dtype is not None and dist_dtype != np.float64:
522+
raise ValueError(
523+
f"Parameter '{field.name}' is expected to have dtype"
524+
f' {backend.float_dtype}, but got {dist_dtype}.'
525+
)
526+
515527
for param, bounds in _parameter_space_bounds.items():
516528
prevent_deterministic_prior_at_bounds = (
517529
_prevent_deterministic_prior_at_bounds[param]

0 commit comments

Comments
 (0)