Skip to content

Conversation

ShawnZhong
Copy link
Contributor

@ShawnZhong ShawnZhong commented Jun 8, 2022

Fixes #44964

Use type hints in the code to show type annotations in the parameters section of the docs.

For the parameters already documented in the docstring, but lack the type annotation, the type hints from the code are used:

Before After
image image
Before After
image image

Ref:

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jun 8, 2022

🔗 Helpful links

❌ 1 New Failures, 1 Pending

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

Expand to see more
  • 1/1 failures introduced in this PR

🕵️ 1 new failure recognized by patterns

The following CI failures do not appear to be due to upstream breakages

See GitHub Actions build pull / linux-focal-py3.7-gcc7 / test (backwards_compat, 1, 1, linux.2xlarge) (1/1)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-06-09T22:39:10.2484735Z The PR is introduc...m to confirm whether this change is wanted or not.
2022-06-09T22:39:10.2471728Z processing existing schema:  text(__torch__.torch.classes.profiling.SourceRef _0) -> str _0
2022-06-09T22:39:10.2472804Z processing existing schema:  count(__torch__.torch.classes.profiling.InstructionStats _0) -> int _0
2022-06-09T22:39:10.2474074Z processing existing schema:  duration_ns(__torch__.torch.classes.profiling.InstructionStats _0) -> int _0
2022-06-09T22:39:10.2475414Z processing existing schema:  source(__torch__.torch.classes.profiling.SourceStats _0) -> __torch__.torch.classes.profiling.SourceRef _0
2022-06-09T22:39:10.2477281Z processing existing schema:  line_map(__torch__.torch.classes.profiling.SourceStats _0) -> Dict(int, __torch__.torch.classes.profiling.InstructionStats) _0
2022-06-09T22:39:10.2478257Z processing existing schema:  __init__(__torch__.torch.classes.profiling._ScriptProfile _0) -> NoneType _0
2022-06-09T22:39:10.2479581Z processing existing schema:  enable(__torch__.torch.classes.profiling._ScriptProfile _0) -> NoneType _0
2022-06-09T22:39:10.2480822Z processing existing schema:  disable(__torch__.torch.classes.profiling._ScriptProfile _0) -> NoneType _0
2022-06-09T22:39:10.2482744Z processing existing schema:  _dump_stats(__torch__.torch.classes.profiling._ScriptProfile _0) -> __torch__.torch.classes.profiling.SourceStats[] _0
2022-06-09T22:39:10.2484276Z processing existing schema:  __init__(__torch__.torch.classes.dist_rpc.WorkerInfo _0, str _1, int _2) -> NoneType _0
2022-06-09T22:39:10.2484735Z The PR is introducing backward incompatible changes to the operator library. Please contact PyTorch team to confirm whether this change is wanted or not. 
2022-06-09T22:39:10.2484747Z 
2022-06-09T22:39:10.2484887Z Broken ops: [
2022-06-09T22:39:10.2485205Z 	aten::linalg_lu_solve(Tensor LU, Tensor pivots, Tensor B, *, bool left=True, bool adjoint=False) -> Tensor
2022-06-09T22:39:10.2485603Z 	aten::linalg_lu_solve.out(Tensor LU, Tensor pivots, Tensor B, *, bool left=True, bool adjoint=False, Tensor(a!) out) -> Tensor(a!)
2022-06-09T22:39:10.2485666Z ]
2022-06-09T22:39:10.3652677Z + cleanup
2022-06-09T22:39:10.3652807Z + retcode=1
2022-06-09T22:39:10.3652927Z + set +x
2022-06-09T22:39:10.3691117Z ##[error]Process completed with exit code 1.
2022-06-09T22:39:10.3728304Z ##[group]Run pytorch/pytorch/.github/actions/get-workflow-job-id@master

This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@rgommers
Copy link
Collaborator

rgommers commented Jun 8, 2022

Thanks for working on this @ShawnZhong!

CI isn't being all that helpful here just yet it looks like:

image

There's a lot of CI failures though, the first one I looked at contained:

...
File "/opt/conda/lib/python3.7/site-packages/torch/jit/annotations.py", line 408, in ann_to_type
    raise ValueError(f"Unknown type annotation: '{ann}' at {loc.highlight()}")
ValueError: Unknown type annotation: 'Tensor' at 

so as happens more often, there may be a conflict between what Mypy/Sphinx wants and what the PyTorch JIT can actually understand.

@ShawnZhong
Copy link
Contributor Author

Yep. It seems that there is some issue with postponed annotations (PEP 563) and JIT. I'm trying to fix them in a separate PR: #79096. If the JIT issue cannot be easily fixed, I might leave this PR without autodoc_type_aliases.

For future reference, the current commit is 646b745 and one error message is available at https://github.com/pytorch/pytorch/runs/6784944582?check_suite_focus=true.

@ShawnZhong ShawnZhong marked this pull request as ready for review June 10, 2022 07:21
@ShawnZhong ShawnZhong requested a review from albanD as a code owner June 10, 2022 07:21
@albanD
Copy link
Collaborator

albanD commented Jun 10, 2022

You can ignore the backward compat test failure as it is a master breakage.

Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

The change sounds ok to me.
Do we want to merge this without the autodoc_type_aliases as it is an improvement already?

Do we have any way to check which part of the doc this is changing to make sure it all behaves well? Or we can just spot check some functions?

cc @svekars

@gchanan gchanan added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 10, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2022

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions bot added the Stale label Aug 9, 2022
@justinchuby justinchuby removed the Stale label Aug 9, 2022
@justinchuby
Copy link
Collaborator

justinchuby commented Sep 30, 2022

@albanD can we include this for the new release, as this greatly improve the documentation reading experience?

@justinchuby
Copy link
Collaborator

Taking the liberty to add it to the milestone. Please feel free to change

@justinchuby justinchuby linked an issue Sep 30, 2022 that may be closed by this pull request
28 tasks
@justinchuby justinchuby removed a link to an issue Sep 30, 2022
28 tasks
@justinchuby justinchuby added this to the 1.13.0 milestone Sep 30, 2022
@justinchuby justinchuby added topic: docs topic category module: docs Related to our documentation, both in docs/ and docblocks labels Sep 30, 2022
@albanD
Copy link
Collaborator

albanD commented Sep 30, 2022

Hey!
Could you rebase this on top of latest master? Make sure all CI passes and the generated doc looks good?

@justinchuby
Copy link
Collaborator

@ShawnZhong thanks!

@facebook-github-bot
Copy link
Contributor

/easycla

As part of the transition to the PyTorch Foundation, this project now requires contributions be covered under the new CLA. See #85559 for additional details.

This comment will trigger a new check of this PR. If you are already covered, you will simply see a new "EasyCLA" check that passes. If you are not covered, a bot will leave a new comment with a link to sign.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 4, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ShawnZhong / name: Shawn Zhong (a33365a)

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 4, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/79086

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures, 2 Pending

As of commit a33365a:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@ShawnZhong
Copy link
Contributor Author

Just rebased the branch to the latest master. I went over some generated docs, and they look good to me. Something worth noting:

@justinchuby justinchuby requested a review from albanD October 4, 2022 02:36
@ShawnZhong
Copy link
Contributor Author

Any updates on the review?

@justinchuby
Copy link
Collaborator

@albanD bump

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 12, 2022
@malfet
Copy link
Contributor

malfet commented Oct 12, 2022

@pytorchbot merge -f "This is just a doc config update"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
Copy link
Contributor

Hey @ShawnZhong.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

malfet pushed a commit that referenced this pull request Oct 12, 2022
Fixes #44964

Use type hints in the code to show type annotations in the parameters section of the docs.

For the parameters already documented in the docstring, but lack the type annotation, the type hints from the code are used:

| [Before](https://pytorch.org/docs/master/generated/torch.nn.AdaptiveMaxPool1d.html) | [After](https://docs-preview.pytorch.org/79086/generated/torch.nn.AdaptiveMaxPool1d.html) |
| --- | --- |
| <img width="462" alt="image" src="https://user-images.githubusercontent.com/6421097/172954756-96d2d8a6-7df9-4c0f-ad34-c12912a5a740.png"> | <img width="479" alt="image" src="https://user-images.githubusercontent.com/6421097/172954770-a6ce2425-99a6-4853-ac2c-e182c3849344.png"> |

| [Before](https://pytorch.org/docs/master/generated/torch.nn.Linear.html) | [After](https://docs-preview.pytorch.org/79086/generated/torch.nn.Linear.html) |
| --- | --- |
| <img width="482" alt="image" src="https://user-images.githubusercontent.com/6421097/172954992-10ce6b48-44a2-487e-b855-2a15a50805bb.png"> | <img width="471" alt="image" src="https://user-images.githubusercontent.com/6421097/172954839-84012ce6-bf42-432c-9226-d3e81500e72d.png"> |

Ref:
- PR #49294 removed type annotations from signatures in HTML docs.
- Sphinx version was bumped to 5.0.0 in PR #70309
- Duplicated (closed) issues: #78311 and #77501

Pull Request resolved: #79086
Approved by: https://github.com/malfet

(cherry picked from commit e552cf1)
malfet added a commit that referenced this pull request Oct 13, 2022
Fixes #44964

Use type hints in the code to show type annotations in the parameters section of the docs.

For the parameters already documented in the docstring, but lack the type annotation, the type hints from the code are used:

| [Before](https://pytorch.org/docs/master/generated/torch.nn.AdaptiveMaxPool1d.html) | [After](https://docs-preview.pytorch.org/79086/generated/torch.nn.AdaptiveMaxPool1d.html) |
| --- | --- |
| <img width="462" alt="image" src="https://user-images.githubusercontent.com/6421097/172954756-96d2d8a6-7df9-4c0f-ad34-c12912a5a740.png"> | <img width="479" alt="image" src="https://user-images.githubusercontent.com/6421097/172954770-a6ce2425-99a6-4853-ac2c-e182c3849344.png"> |

| [Before](https://pytorch.org/docs/master/generated/torch.nn.Linear.html) | [After](https://docs-preview.pytorch.org/79086/generated/torch.nn.Linear.html) |
| --- | --- |
| <img width="482" alt="image" src="https://user-images.githubusercontent.com/6421097/172954992-10ce6b48-44a2-487e-b855-2a15a50805bb.png"> | <img width="471" alt="image" src="https://user-images.githubusercontent.com/6421097/172954839-84012ce6-bf42-432c-9226-d3e81500e72d.png"> |

Ref:
- PR #49294 removed type annotations from signatures in HTML docs.
- Sphinx version was bumped to 5.0.0 in PR #70309
- Duplicated (closed) issues: #78311 and #77501

Pull Request resolved: #79086
Approved by: https://github.com/malfet

(cherry picked from commit e552cf1)

Co-authored-by: Shawn Zhong <github@shawnzhong.com>
@ShawnZhong ShawnZhong deleted the typehints branch October 13, 2022 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request cla signed Merged module: docs Related to our documentation, both in docs/ and docblocks open source topic: docs topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve how type annotations show up in html docs
9 participants