Skip to content
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

Add TorchScopedLibraryVisitor #22

Merged
merged 1 commit into from
Feb 5, 2024
Merged

Add TorchScopedLibraryVisitor #22

merged 1 commit into from
Feb 5, 2024

Conversation

kit1980
Copy link
Contributor

@kit1980 kit1980 commented Feb 3, 2024

This PR adds a new category of rules, 'internal': rules that are used for PyTorch code itself, not for PyTorch users.
These rules starts with TOR9 and are not enabled by default.

The TorchScopedLibraryVisitor rule is based on pytorch/pytorch#118318 and a lint-only for now.
I'll try to add a codemod for it in the next PR. Codemod would be somewhat complicated, but probably worth it as the pytorch/test/test_python_dispatch.py file is thousands of lines of code.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 3, 2024
@kit1980 kit1980 requested review from zou3519 and malfet February 3, 2024 01:12
@kit1980 kit1980 marked this pull request as ready for review February 3, 2024 01:12
@@ -0,0 +1 @@
3:11 TOR901 Use `torch.library._scoped_library` instead of `torch.library.Library` in PyTorch tests files. See https://github.com/pytorch/pytorch/pull/118318 for details.
Copy link

Choose a reason for hiding this comment

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

Is there is a way to suppress the lint? We'll probably want to allow some usages of torch.library.Library (just to test that API).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's disabled by default. When we enable it for some files, usual flake8 noqa comments can be used to ignore some lines.

cst.metadata.WhitespaceInclusivePositionProvider, node
)

self.violations.append(
Copy link

Choose a reason for hiding this comment

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

what limits this rule to files under test/ ?

Copy link
Contributor Author

@kit1980 kit1980 Feb 5, 2024

Choose a reason for hiding this comment

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

The rule is disabled by default. We can enable it for test/ in the CI config in pytorch/pytorch.

Copy link

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

thanks for the explanation, this is cool!

@kit1980 kit1980 merged commit bfe27bc into main Feb 5, 2024
2 checks passed
@kit1980 kit1980 deleted the scoped_library branch February 6, 2024 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants