python3Packages.funsor: 0.4.7 -> 0.4.8

Diff: https://github.com/pyro-ppl/funsor/compare/0.4.7...0.4.8

Changelog: https://github.com/pyro-ppl/funsor/releases/tag/0.4.8
This commit is contained in:
Gaetan Lepage
2026-08-03 17:42:08 +00:00
parent 0adbd05f9f
commit a532aae5e9
2 changed files with 59 additions and 8 deletions

View File

@@ -2,7 +2,6 @@
lib,
buildPythonPackage,
fetchFromGitHub,
fetchpatch,
# build-system
setuptools,
@@ -29,7 +28,7 @@
buildPythonPackage (finalAttrs: {
pname = "funsor";
version = "0.4.7";
version = "0.4.8";
pyproject = true;
__structuredAttrs = true;
@@ -37,15 +36,15 @@ buildPythonPackage (finalAttrs: {
owner = "pyro-ppl";
repo = "funsor";
tag = finalAttrs.version;
hash = "sha256-0STJv1OOliJaHdmYUXdnOnocH3hVXceH/Uw5nILvT+U=";
hash = "sha256-iTkDd6vz4wesY3jABSMxLtTKioP98DhGB0plLL+vhNY=";
};
patches = [
# Compatibility with torch >= 2.5 (arg_constraints is now a property)
(fetchpatch {
url = "https://github.com/pyro-ppl/funsor/commit/c5e2a48d73cad4e98058147af4090171272a44e5.patch";
hash = "sha256-sTR+hbJtS0Th5sIqlvB2bReEC0wnEbnB7gAiZKiqjAQ=";
})
# Compatibility with torch >= 2.5, where `Uniform.arg_constraints` is a property.
# Remaining part of the pending upstream PR https://github.com/pyro-ppl/funsor/pull/610
# (the `Uniform` parameter registration was already merged as part of
# https://github.com/pyro-ppl/funsor/pull/614).
./torch-arg-constraints-property.patch
];
build-system = [ setuptools ];

View File

@@ -0,0 +1,52 @@
diff --git a/funsor/distribution.py b/funsor/distribution.py
index 5a48ecb..cfb2d2e 100644
--- a/funsor/distribution.py
+++ b/funsor/distribution.py
@@ -309,7 +309,10 @@ class Distribution(Funsor, metaclass=DistributionMeta):
@classmethod
@functools.lru_cache(maxsize=5000)
def _infer_param_domain(cls, name, raw_shape):
- support = cls.dist_class.arg_constraints.get(name, None)
+ constraints = getattr(cls.dist_class, "arg_constraints", {})
+ if isinstance(constraints, property):
+ constraints = {}
+ support = constraints.get(name, None)
# XXX: if the backend does not have the same definition of constraints, we should
# define backend-specific distributions and overide these `infer_value_domain`,
# `infer_param_domain` methods.
@@ -330,9 +333,8 @@ class Distribution(Funsor, metaclass=DistributionMeta):
# for discrete multivariate distributions in Pyro
elif support_name == "Real":
if name == "logits" and (
- "probs" in cls.dist_class.arg_constraints
- and type(cls.dist_class.arg_constraints["probs"]).__name__.lstrip("_")
- == "Simplex"
+ "probs" in constraints
+ and type(constraints.get("probs")).__name__.lstrip("_") == "Simplex"
):
output = Reals[raw_shape[-1 - event_dim :]]
else:
@@ -377,10 +379,13 @@ def make_dist(
backend_dist_class, param_names=(), generate_eager=True, generate_to_funsor=True
):
if not param_names:
+ constraints = getattr(backend_dist_class, "arg_constraints", {})
+ if isinstance(constraints, property):
+ constraints = {}
param_names = tuple(
name
for name in inspect.getfullargspec(backend_dist_class.__init__)[0][1:]
- if name in backend_dist_class.arg_constraints
+ if name in constraints
)
@makefun.with_signature(
@@ -608,7 +613,7 @@ class CoerceDistributionToFunsor:
def __call__(self, cls, args, kwargs):
# Check whether distribution class takes any tensor inputs.
arg_constraints = getattr(cls, "arg_constraints", None)
- if not arg_constraints:
+ if not arg_constraints or isinstance(arg_constraints, property):
return
# Check whether any tensor inputs are actually funsors.