-
-
Notifications
You must be signed in to change notification settings - Fork 985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copied comment-docs to torch.distributions wrappers from corresponding sources. #3243
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point that it would be helpful to remove that layer of indirection between Pyro wrappers and their PyTorch distributions. However I have a couple concerns with the proposed change:
- We'd prefer to programmatically copy docs directly torch via
@copy_docs_from
rather than manually embed those docs once. The programmatic approach would allow Pyro's wrappers to receive upstream updates from the docs and would reduce our team's maintenance burden. - Pyro uses sphinx-style docstrings whereas PyTorch uses NumPy/Google style docstrings. This unfortunate design choice prevents Pyro's doc building system from directly embedding PyTorch docstrings in Pyro wrappers (and I suspect this PR's docs build will fail even after we
make lint
to fixblack
errors).
I think we can address both concerns with little effort by:
- Updating the loop at the end of this file to programmatically insert the torch docstrings into our wrappers,
- Adding napoleaon to our sphinx dependencies to start supporting NumPy/Google style docstrings as in PyTorch.
@rtviii would you like to try this alternative approach, or would you like me to do it? Either way, thanks for the nudge to fix our redirected docstrings 🙂
Certainly, i can try. Took a brief look..
|
|
Hey, Fritz. A few things.. This fails(asking for nonidented lines) seemingly after So even thought that suggests to me Furthermore, i had to disable the doctest ( see 1. Updated docbuilding loop in `torch.py`def doctest_disable(docstring):
_ = ""
for line in docstring.splitlines():
_ += line + "#doctest: +DISABLE"
return _
# Programmatically load all distributions from PyTorch.
__all__ = []
for _name, _Dist in torch.distributions.__dict__.items():
if not isinstance(_Dist, type):
continue
if not issubclass(_Dist, torch.distributions.Distribution):
continue
if _Dist is torch.distributions.Distribution:
continue
try:
_PyroDist = locals()[_name]
torchDistDocstring = _Dist.__doc__
except KeyError:
_PyroDist = type(_name, (_Dist, TorchDistributionMixin), {})
_PyroDist.__module__ = __name__
locals()[_name] = _PyroDist
torchDistDocstring = None
_PyroDist.__doc__ = """
Wraps :class:`{}.{}` with
:class:`~pyro.distributions.torch_distribution.TorchDistributionMixin`.
""".format(
_Dist.__module__, _Dist.__name__
) + (
"\n\n" + doctest_disable(torchDistDocstring)
if torchDistDocstring is not None
else ""
)
__all__.append(_name)
# Create sphinx documentation.
__doc__ = "\n\n".join(
[
"""
{0}
----------------------------------------------------------------
.. autoclass:: pyro.distributions.{0}
""".format(
_name
)
for _name in sorted(__all__)
]
) 2. Error from building with pytorch docstrings (`napoleon` enabled)ᢹ saeta.rtviii[ ~/pyro ] make format [dev]
python scripts/update_headers.py
ruff check --fix .
black *.py pyro examples tests scripts profiler
Skipping .ipynb files as Jupyter dependencies are not installed.
You can fix this by running ``pip install "black[jupyter]"``
reformatted /Users/rtviii/pyro/pyro/contrib/forecast/forecaster.py
All done! ✨ 🍰 ✨
1 file reformatted, 616 files left unchanged.
ᢹ saeta.rtviii[ ~/pyro ] make test [dev]
ruff check .
black --check *.py pyro examples tests scripts profiler
Skipping .ipynb files as Jupyter dependencies are not installed.
You can fix this by running ``pip install "black[jupyter]"``
All done! ✨ 🍰 ✨
617 files would be left unchanged.
python scripts/update_headers.py --check
mypy --install-types --non-interactive pyro scripts
Success: no issues found in 319 source files
/Library/Developer/CommandLineTools/usr/bin/make -C docs html
Running Sphinx v6.2.1
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://pytorch.org/docs/master/objects.inv...
loading intersphinx inventory from http://funsor.pyro.ai/en/stable/objects.inv...
loading intersphinx inventory from https://optimized-einsum.readthedocs.io/en/stable/objects.inv...
loading intersphinx inventory from https://docs.scipy.org/doc/scipy/reference/objects.inv...
loading intersphinx inventory from https://biopython.org/docs/latest/api/objects.inv...
loading intersphinx inventory from https://horovod.readthedocs.io/en/stable/objects.inv...
loading intersphinx inventory from https://graphviz.readthedocs.io/en/stable/objects.inv...
intersphinx inventory has moved: http://funsor.pyro.ai/en/stable/objects.inv -> https://funsor.pyro.ai/en/stable/objects.inv
intersphinx inventory has moved: https://docs.scipy.org/doc/scipy/reference/objects.inv -> https://docs.scipy.org/doc/scipy/objects.inv
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 32 source files that are out of date
updating environment: [new config] 32 added, 0 changed, 0 removed
reading sources... [100%] testing
Warning, treated as error:
/Users/rtviii/pyro/pyro/distributions/torch.py:docstring of pyro.distributions.torch.Categorical:6:Inline interpreted text or phrase reference start-string without end-string.
make[1]: *** [html] Error 2
make: *** [docs] Error 2 |
Closing in favor of #3246 |
Was surprised not to find a little handy annotations, had to drill down to source make sure i'm using the parameter correctly.