Skip to content

Split up documentation into subpages and clean up some warnings#37419

Closed
mattip wants to merge 9 commits intopytorch:masterfrom
mattip:issue-32838
Closed

Split up documentation into subpages and clean up some warnings#37419
mattip wants to merge 9 commits intopytorch:masterfrom
mattip:issue-32838

Conversation

@mattip
Copy link
Copy Markdown
Contributor

@mattip mattip commented Apr 28, 2020

xref gh-32838, gh-34032

This is a major refactor of parts of the documentation to split it up using sphinx's autosummary feature which will build out autofuction and autoclass stub files and link to them. The end result is that the top module pages like torch.nn.rst and torch.rst are now more like table-of-contents to the actual single-class or single-function documentations pages.

Along the way, I modified many of the docstrings to eliminate sphinx warnings when building. I think the only thing I changed from a non-documentation perspective is to add names to __all__ when adding them to globals() in torch.__init__.py

I do not know the CI system: are the documentation build artifacts available after the build, so reviewers can preview before merging?

@mattip mattip requested review from albanD and apaszke as code owners April 28, 2020 17:01
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Apr 28, 2020
Comment thread torch/autograd/functional.py
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Apr 28, 2020

💊 Build failures summary and remediations

As of commit c277285 (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

See how this bot performed.

This comment has been revised 27 times.

@mattip mattip changed the title Issue 32838 Split up documentation into subpages and clean up some warnings Apr 29, 2020
@ShawnZhong
Copy link
Copy Markdown
Contributor

ShawnZhong commented Apr 29, 2020

I really like the way you organized the functions to the generated folder and the changes you made to the docs.

FYI, I built the docs based on 2fd0354, and published it at https://shawnzhong.github.io/pytorch/.

It also turns out that the folder structure works pretty well with PyCharm/Inteiilj's External Documentation (See related discussion on PyTorch Forum) by setting the URL to https://shawnzhong.github.io/pytorch/generated/{element.qname}.html

image

Comment thread torch/onnx/__init__.py Outdated
to 'mode', resetting it when we exit the with-block. A no-op if
mode is None.

In verison 1.5 changed to this from set_training
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

minor: typo in version here. also set_training looks like it needs double backticks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, should be 1.6

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

and "version" not "verison"

Copy link
Copy Markdown
Collaborator

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

This looks quite good and from some testing it seems like this resolves both the searching and the "docs are heavy" issues well.

Visually I think the vertical margins on every function/class entry in autosummary tables could be made smaller, that way things get more compact and it would read even better. Non-blocking comment though, it's a matter of taste and either way this is a significant improvement.

image

@rgommers rgommers requested a review from ezyang April 29, 2020 19:30
@rgommers
Copy link
Copy Markdown
Collaborator

I do not know the CI system: are the documentation build artifacts available after the build, so reviewers can preview before merging?

There's a CircleCI job pytorch_python_doc_push that builds the docs, however it doesn't store any artifacts for PRs. Controlled by .circleci/scripts/python_doc_push_script.sh. I think that's the only doc build (?). Not sure why it doesn't store the artifacts, that would be useful.

@mattip
Copy link
Copy Markdown
Contributor Author

mattip commented Apr 29, 2020

TL DR: there is a broken test. I propose redoing it properly which will require a few days work.

The test/test_docs_coverage.py test is failing since it does this:

  • scan a top-level module's rst file for autofunction directives to determine which functions are documented
  • scan [a.__doc__ for a in dir(module)] for the string .. function in the docstring to determine which functions should be documented
  • compare the two, they should be equal.

This PR broke both sides of the equation:

  • autosummary replaces the autofunction directives and builds out stub files that in turn are linked back in, so now the documentation has a multi-level heirarchy
  • the leading .. function directive broke autosummary so I removed it.

I propose we use sphinx.ext.coverage to do this for us, but it means investing time to get the call right and parse the output. Are there other options? Should we add a make coverage CI step (which will also require work) to check coverage instead of a test? Should we disable the check entirely for now, and open a new issue to fix it?

@ShawnZhong
Copy link
Copy Markdown
Contributor

I was checking the links for the functions and found that some overloaded functions are not linked correctly in torch.html

For those functions, the second column shows the function signature instead of the description, and the link target is set to torch.html#torch.mul instead of generated/point/torch.mul.html?highlight=mul

image

Comment thread docs/source/torch.rst Outdated
.. autofunction:: trunc

.. autosummary::
:toctree: generated/point
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe you want to use generated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, fixed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it's just me, but it seems that this change doesn't fix the link issue mentioned above: torch.mul still links to the torch.html#torch.mul.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Strange. I don't see this on two different builds (both with cuda installed, one on a machine with a GPU, one without). There is nothing obvious in torch/_torch_docs.py in the docstrings for these functions as overloaded from add_docstr(torch.mul,... and friends. What do you mean by "some overloaded functions" - is there something special about mul and pow that my builds are not picking up?

How are you building and uploading the docs to https://shawnzhong.github.io/pytorch ?

I guess I could try to replicate the actual python_doc_push_script.sh in a docker, does that CI step run with a GPU?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I use a GitHub action to build and push the HTML files to gh_pages, which is served by GitHub pages.

It might be a different environment that causes this issue. I tried to use the same environment as CircileCI, but it seems that I don't have the permission to pull the docker image for building docs. BTW, I just opened a PR to upload the build artifact for python docs at #37658.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Apr 30, 2020

I propose we use sphinx.ext.coverage to do this for us, but it means investing time to get the call right and parse the output. Are there other options? Should we add a make coverage CI step (which will also require work) to check coverage instead of a test? Should we disable the check entirely for now, and open a new issue to fix it?

Reading over the sphinx coverage docs, it does seem like this is the right thing to do. You can see the original PR #16039 we mostly added this test script in anger. The important thing is the test needs to fail when you don't document and don't explicitly blacklist. The only plausible alternative is to bulk up the script so that it can handle hierarchy on the documentation; probably not too hard either, but if Sphinx has a built in to do this, we probably should use it.

However, there's a huge benefit to getting this PR in directly, so I think that it is OK not to block this PR and disable the check for now, and then fix it later.

cc @zasdfgbnm who originally added the test

@zasdfgbnm
Copy link
Copy Markdown
Collaborator

I propose we use sphinx.ext.coverage to do this for us, but it means investing time to get the call right and parse the output. Are there other options? Should we add a make coverage CI step (which will also require work) to check coverage instead of a test? Should we disable the check entirely for now, and open a new issue to fix it?

Reading over the sphinx coverage docs, it does seem like this is the right thing to do. You can see the original PR #16039 we mostly added this test script in anger. The important thing is the test needs to fail when you don't document and don't explicitly blacklist. The only plausible alternative is to bulk up the script so that it can handle hierarchy on the documentation; probably not too hard either, but if Sphinx has a built in to do this, we probably should use it.

However, there's a huge benefit to getting this PR in directly, so I think that it is OK not to block this PR and disable the check for now, and then fix it later.

cc @zasdfgbnm who originally added the test

I agree that it is a good idea to just disable this test to unblock this. After you disable it, can you open an issue for that?

@mattip
Copy link
Copy Markdown
Contributor Author

mattip commented Apr 30, 2020

Comment thread torch/nn/modules/loss.py
Labelling Unsegmented Sequence Data with Recurrent Neural Networks:
https://www.cs.toronto.edu/~graves/icml_2006.pdf

.. Note::
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Huh, .. Note:: is not actually a thing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

.. note:: is a directive for general RST and rendered as a <div> with formatting to look like a box, Note: is a docstring heading. I think the intent here is a docstring section

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

ShawnZhong added a commit to ShawnZhong/pytorch that referenced this pull request May 5, 2020
Summary:
This PR allows the build artifacts for python docs to be stored on CircieCI, which helps the reviewer to preview doc changes before merging.

The artifacts can be found in the [`ARTIFACTS` tab](  https://app.circleci.com/pipelines/github/pytorch/pytorch/162986/workflows/a969f256-3243-414f-8a02-1234b9dac149/jobs/5320907/artifacts) of the test **pytorch_cpp_doc_push**, and the website is served at https://5320907-65600975-gh.circle-artifacts.com/0/docs/index.html

This PR is inspired by rgommers's comment under pytorch#37419 (comment)

> There's a CircleCI job pytorch_python_doc_push that builds the docs, however it doesn't store any artifacts for PRs. Controlled by .circleci/scripts/python_doc_push_script.sh. I think that's the only doc build (?). Not sure why it doesn't store the artifacts, that would be useful.
Pull Request resolved: pytorch#37658

Differential Revision: D21380094

Pulled By: ezyang

fbshipit-source-id: 1dd44bf836ebc74454f4444ae9321807dccdb313
ShawnZhong pushed a commit to ShawnZhong/pytorch that referenced this pull request May 5, 2020
…rch#37419)

Summary:
xref pytorchgh-32838, pytorchgh-34032

This is a major refactor of parts of the documentation to split it up using sphinx's `autosummary` feature which will build out `autofuction` and `autoclass` stub files and link to them. The end result is that the top module pages like torch.nn.rst and torch.rst are now more like table-of-contents to the actual single-class or single-function documentations pages.

Along the way, I modified many of the docstrings to eliminate sphinx warnings when building. I think the only thing I changed from a non-documentation perspective is to add names to `__all__` when adding them to `globals()` in `torch.__init__.py`

I do not know the CI system: are the documentation build artifacts available after the build, so reviewers can preview before merging?
Pull Request resolved: pytorch#37419

Differential Revision: D21337640

Pulled By: ezyang

fbshipit-source-id: d4ad198780c3ae7a96a9f22651e00ff2d31a0c0f
ShawnZhong pushed a commit to ShawnZhong/pytorch that referenced this pull request May 5, 2020
…ubpages and clean up some warnings" (pytorch#37778)

Summary:
Original PR: pytorch#37419

cc mattip suo
Pull Request resolved: pytorch#37778

Differential Revision: D21385774

Pulled By: ezyang

fbshipit-source-id: 5de532faab8bae132736b6b5189e0ee2ac9935be
bharatr21 pushed a commit to bharatr21/pytorch that referenced this pull request May 5, 2020
Summary:
This PR allows the build artifacts for python docs to be stored on CircieCI, which helps the reviewer to preview doc changes before merging.

The artifacts can be found in the [`ARTIFACTS` tab](  https://app.circleci.com/pipelines/github/pytorch/pytorch/162986/workflows/a969f256-3243-414f-8a02-1234b9dac149/jobs/5320907/artifacts) of the test **pytorch_cpp_doc_push**, and the website is served at https://5320907-65600975-gh.circle-artifacts.com/0/docs/index.html

This PR is inspired by rgommers's comment under pytorch#37419 (comment)

> There's a CircleCI job pytorch_python_doc_push that builds the docs, however it doesn't store any artifacts for PRs. Controlled by .circleci/scripts/python_doc_push_script.sh. I think that's the only doc build (?). Not sure why it doesn't store the artifacts, that would be useful.
Pull Request resolved: pytorch#37658

Differential Revision: D21380094

Pulled By: ezyang

fbshipit-source-id: 1dd44bf836ebc74454f4444ae9321807dccdb313
bharatr21 pushed a commit to bharatr21/pytorch that referenced this pull request May 5, 2020
…rch#37419)

Summary:
xref pytorchgh-32838, pytorchgh-34032

This is a major refactor of parts of the documentation to split it up using sphinx's `autosummary` feature which will build out `autofuction` and `autoclass` stub files and link to them. The end result is that the top module pages like torch.nn.rst and torch.rst are now more like table-of-contents to the actual single-class or single-function documentations pages.

Along the way, I modified many of the docstrings to eliminate sphinx warnings when building. I think the only thing I changed from a non-documentation perspective is to add names to `__all__` when adding them to `globals()` in `torch.__init__.py`

I do not know the CI system: are the documentation build artifacts available after the build, so reviewers can preview before merging?
Pull Request resolved: pytorch#37419

Differential Revision: D21337640

Pulled By: ezyang

fbshipit-source-id: d4ad198780c3ae7a96a9f22651e00ff2d31a0c0f
bharatr21 pushed a commit to bharatr21/pytorch that referenced this pull request May 5, 2020
…ubpages and clean up some warnings" (pytorch#37778)

Summary:
Original PR: pytorch#37419

cc mattip suo
Pull Request resolved: pytorch#37778

Differential Revision: D21385774

Pulled By: ezyang

fbshipit-source-id: 5de532faab8bae132736b6b5189e0ee2ac9935be
@mattip
Copy link
Copy Markdown
Contributor Author

mattip commented May 6, 2020

I am not sure whether to close gh-32838, gh-34032. There is (and probbly will always be) more to do here:

  • quantization.html and maybe other pages still could be broken into smaller units.
  • remaining warnings should be fixed, and we could turn on sphinx warning-as-error once warnings reach 0 in order to prevent new warnings from appearing
  • css and SEO improvements probably better left to web designers:
    • left navbar: subtopic indentation, using standard triangles to collapse topics,
    • right navbar that appears in subtopics should be used in sub-subtopics as well
    • keywords to help search engines
    • robot.txt to prevent search engines finding older versions of the documentation
  • I did not look at the site on mobile

@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented May 6, 2020

I think it's ok to file new issues for these, since the main issue has been addressed.

@mattip
Copy link
Copy Markdown
Contributor Author

mattip commented May 7, 2020

xref
gh-38010 to split more files
gh-38011 to remove warnings
gh-38012 to improve formatting.
I see that searching for "pytorch autograd" already points to the stable documentation, so SEO seems OK.

I think we can close the main issues gh-32838, gh-34032 now.

@mrshenli
Copy link
Copy Markdown
Contributor

Hey @mattip, we noticed that rpc/index.rst is removed from this PR. That page is the landing page for the RPC package. Is there any plan for adding it back before v1.6 branch cut?

cc @rohan-varma @jlin27

@mattip
Copy link
Copy Markdown
Contributor Author

mattip commented Jun 15, 2020

That page is the landing page for the RPC package

Since much of the content of docs/source/rpc/index.rst page was repeated on docs/source/rpc.rst I took the liberty of consolidating them into the latter. If there are external references to the former and not the latter, maybe we should switch it around? It seemed strange to me that there was an index.rst page but no other pages. The content is rendered at https://pytorch.org/docs/master/rpc.html.

@mrshenli
Copy link
Copy Markdown
Contributor

Hey @mattip

Thanks for the info. And the change looks OK to me. Just one concern, it seems like the RPC package disappeared from the main indexing page (and the left navigation bar) on master: https://pytorch.org/docs/master/

Do we plan to fix that?

In the stable release (https://pytorch.org/docs/stable/), there is a Distributed RPC Framework link points to the rpc.rst page.

facebook-github-bot pushed a commit that referenced this pull request Jun 16, 2020
Summary:
Fixes gh-40046

PR gh-37419 refactored the content of `docs/source/rpc/index.rst` into `docs/source/rpc.rst` but did not link to the latter from `doc/source/index.rst` so the top-level RPC documentation is missing from https://pytorch.org/docs/master/.
Pull Request resolved: #40077

Differential Revision: D22068128

Pulled By: mrshenli

fbshipit-source-id: 394433f98f86509e0c9cb6d910a86fb8a2932683
xwang233 pushed a commit to xwang233/pytorch that referenced this pull request Jun 20, 2020
Summary:
Fixes pytorchgh-40046

PR pytorchgh-37419 refactored the content of `docs/source/rpc/index.rst` into `docs/source/rpc.rst` but did not link to the latter from `doc/source/index.rst` so the top-level RPC documentation is missing from https://pytorch.org/docs/master/.
Pull Request resolved: pytorch#40077

Differential Revision: D22068128

Pulled By: mrshenli

fbshipit-source-id: 394433f98f86509e0c9cb6d910a86fb8a2932683
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
This PR allows the build artifacts for python docs to be stored on CircieCI, which helps the reviewer to preview doc changes before merging.

The artifacts can be found in the [`ARTIFACTS` tab](  https://app.circleci.com/pipelines/github/pytorch/pytorch/162986/workflows/a969f256-3243-414f-8a02-1234b9dac149/jobs/5320907/artifacts) of the test **pytorch_cpp_doc_push**, and the website is served at https://5320907-65600975-gh.circle-artifacts.com/0/docs/index.html

This PR is inspired by rgommers's comment under pytorch#37419 (comment)

> There's a CircleCI job pytorch_python_doc_push that builds the docs, however it doesn't store any artifacts for PRs. Controlled by .circleci/scripts/python_doc_push_script.sh. I think that's the only doc build (?). Not sure why it doesn't store the artifacts, that would be useful.
Pull Request resolved: pytorch#37658

Differential Revision: D21380094

Pulled By: ezyang

fbshipit-source-id: 1dd44bf836ebc74454f4444ae9321807dccdb313
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…rch#37419)

Summary:
xref pytorchgh-32838, pytorchgh-34032

This is a major refactor of parts of the documentation to split it up using sphinx's `autosummary` feature which will build out `autofuction` and `autoclass` stub files and link to them. The end result is that the top module pages like torch.nn.rst and torch.rst are now more like table-of-contents to the actual single-class or single-function documentations pages.

Along the way, I modified many of the docstrings to eliminate sphinx warnings when building. I think the only thing I changed from a non-documentation perspective is to add names to `__all__` when adding them to `globals()` in `torch.__init__.py`

I do not know the CI system: are the documentation build artifacts available after the build, so reviewers can preview before merging?
Pull Request resolved: pytorch#37419

Differential Revision: D21337640

Pulled By: ezyang

fbshipit-source-id: d4ad198780c3ae7a96a9f22651e00ff2d31a0c0f
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…ubpages and clean up some warnings" (pytorch#37778)

Summary:
Original PR: pytorch#37419

cc mattip suo
Pull Request resolved: pytorch#37778

Differential Revision: D21385774

Pulled By: ezyang

fbshipit-source-id: 5de532faab8bae132736b6b5189e0ee2ac9935be
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Fixes pytorchgh-40046

PR pytorchgh-37419 refactored the content of `docs/source/rpc/index.rst` into `docs/source/rpc.rst` but did not link to the latter from `doc/source/index.rst` so the top-level RPC documentation is missing from https://pytorch.org/docs/master/.
Pull Request resolved: pytorch#40077

Differential Revision: D22068128

Pulled By: mrshenli

fbshipit-source-id: 394433f98f86509e0c9cb6d910a86fb8a2932683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue open source

Projects

None yet

Development

Successfully merging this pull request may close these issues.