Skip to content

Only include arg_constraints in pytree_data_fields if they are not lazy_propertys.#1929

Merged
fehiepsi merged 1 commit intopyro-ppl:masterfrom
tillahoffmann:pytree
Dec 5, 2024
Merged

Only include arg_constraints in pytree_data_fields if they are not lazy_propertys.#1929
fehiepsi merged 1 commit intopyro-ppl:masterfrom
tillahoffmann:pytree

Conversation

@tillahoffmann
Copy link
Collaborator

This PR tries to address #1928 to obtain consistent pytree structures.

On a related note, similar behavior is observed with the get_args method. I'm not sure what the "correct" behavior should be in this case.

>>> import jax
>>> from jax import numpy as jnp
>>> from numpyro import distributions as dists
>>> 
>>> 
>>> def make_dist():
>>>     return dists.MultivariateNormal(precision_matrix=jnp.eye(2))
>>> 
>>> 
>>> init = make_dist()
>>> init.get_args()
{'loc': array([0.]),
 'precision_matrix': Array([[1., 0.],
        [0., 1.]], dtype=float32),
 'scale_tril': Array([[1., 0.],
        [0., 1.]], dtype=float32)}
>>> init.covariance_matrix
>>> init.get_args()
{'loc': array([0.]),
 'covariance_matrix': Array([[1., 0.],
        [0., 1.]], dtype=float32),
 'precision_matrix': Array([[1., 0.],
        [0., 1.]], dtype=float32),
 'scale_tril': Array([[1., 0.],
        [0., 1.]], dtype=float32)}

Copy link
Member

@fehiepsi fehiepsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Re get_args: it depends on the definition of the method. It might be worth to add a clear description there. Any method with lazy properties might give inconsistent behaviors, not just with get_args.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants