pyro icon indicating copy to clipboard operation
pyro copied to clipboard

Init signature does not appear for distribution class

Open fehiepsi opened this issue 5 years ago • 5 comments

Currently, when creating an instance of dist.Normal in jupyter, the docstring will say

Init signature: dist.Normal(*args, **kwargs)

That infomation is not helpful. This new behavior happens because we define DistributionMeta.__call__ for collapse messenger. It would be nice to find an alternative solution that preserves the signature of distributions' constructors.

fehiepsi avatar Oct 28 '20 02:10 fehiepsi

Thanks for pointing this out, I'll look into it.

fritzo avatar Oct 28 '20 03:10 fritzo

It looks like we'll need to get inspect.signature(Normal) to print the more informative string, since that's what help() uses. Here's a minimal working example:

python -c 'import pyro.distributions as d, inspect as i; print(i.signature(d.Normal))'
(*args, **kwargs)

fritzo avatar Oct 28 '20 03:10 fritzo

It looks like this is failing again as of Pyro 1.8.0. @fehiepsi have you noticed anything else that's changed in that you've had to fix in NumPyro?

EDIT specifically, I see Normal(*args, **kwargs) on readthedocs, but Normal(loc, scale, validate_args=None) when I build docs locally. I wonder if this is a readthedocs version issue

fritzo avatar Jul 19 '22 22:07 fritzo

@fritzo I fixed the issue at #3064. The latest release should have the desired signature. That explains why things worked when you built locally. ;)

fehiepsi avatar Jul 22 '22 11:07 fehiepsi

Oh thanks @fehiepsi I'll try to release soon

fritzo avatar Jul 22 '22 15:07 fritzo