diff --git a/pkgs/development/python-modules/funsor/default.nix b/pkgs/development/python-modules/funsor/default.nix index 04ece9b20542..4c57b7fbb58c 100644 --- a/pkgs/development/python-modules/funsor/default.nix +++ b/pkgs/development/python-modules/funsor/default.nix @@ -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 ]; diff --git a/pkgs/development/python-modules/funsor/torch-arg-constraints-property.patch b/pkgs/development/python-modules/funsor/torch-arg-constraints-property.patch new file mode 100644 index 000000000000..e6dd756af6d1 --- /dev/null +++ b/pkgs/development/python-modules/funsor/torch-arg-constraints-property.patch @@ -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.