Skip to content

Add type annotations to distribution.py#87577

Closed
EPronovost wants to merge 2 commits intopytorch:masterfrom
EPronovost:distribution-type-annotations
Closed

Add type annotations to distribution.py#87577
EPronovost wants to merge 2 commits intopytorch:masterfrom
EPronovost:distribution-type-annotations

Conversation

@EPronovost
Copy link
Contributor

As title.

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 23, 2022

🔗 Helpful Links

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

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

✅ No Failures, 1 Pending

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

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

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 23, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: EPronovost / name: Ethan Pronovost (b89ef23)

@EPronovost EPronovost marked this pull request as ready for review October 23, 2022 20:57
@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 24, 2022
@kit1980
Copy link
Contributor

kit1980 commented Oct 25, 2022

@EPronovost The linter says the types are not correct.

Copy link
Contributor

@kit1980 kit1980 left a comment

Choose a reason for hiding this comment

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

Please fix lint issues.

@EPronovost
Copy link
Contributor Author

Thanks @kit1980 . Fixed.

@kit1980
Copy link
Contributor

kit1980 commented Oct 26, 2022

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

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 @EPronovost.
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.

@EPronovost
Copy link
Contributor Author

Hi @kit1980 , thanks for the review. The github action bot says I should add release notes and topic labels to the PR, but the github UI says I don't have permission to add labels to PRs. Is there something I should do here?

@kit1980
Copy link
Contributor

kit1980 commented Oct 27, 2022

@EPronovost It's fine ignore it for now. You can add labels by commenting to pytorchbot, see https://github.com/pytorch/pytorch/wiki/Bot-commands#labeling

return self.rsample(sample_shape)

def rsample(self, sample_shape=torch.Size()):
def rsample(self, sample_shape: torch.Size = torch.Size()) -> torch.Tensor:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@EPronovost @kit1980

torch.Size is too strict here since something like

dist = torch.distributions.Uniform(0.0, 1.0)
dist.sample((2, 3))

is no longer allowed since (2, 3) is not a torch.Size. This forces users to do

dist.sample(torch.Size((2, 3)))

which is likely not intended, is it? We should use torch.types._size

_size = Union[torch.Size, List[_int], Tuple[_int, ...]]

as annotation here and in all other occurrences of this annotation.

Copy link
Contributor

Choose a reason for hiding this comment

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

@pmeier Thanks! Do you want to send a PR?

kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Nov 5, 2022
kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Dec 10, 2022
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 Merged open source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants