-
Notifications
You must be signed in to change notification settings - Fork 107
Enable E712 #2641
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
base: main
Are you sure you want to change the base?
Enable E712 #2641
Conversation
Signed-off-by: Masaki Kozuki <mkozuki@nvidia.com>
# with a very negative value that should become ~0 after softmax | ||
if attn_mask.dtype == torch.bool: | ||
attn_mask = torch.masked_fill(torch.zeros_like(attn_mask, dtype=query.dtype), attn_mask == False, -math.inf) | ||
attn_mask = torch.masked_fill(torch.zeros_like(attn_mask, dtype=query.dtype), not attn_mask, -math.inf) |
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.
attn_mask = torch.masked_fill(torch.zeros_like(attn_mask, dtype=query.dtype), not attn_mask, -math.inf) | |
attn_mask = torch.masked_fill(torch.zeros_like(attn_mask, dtype=query.dtype), ~attn_mask, -math.inf) |
To my mind == False
is less "line noise" than ~attn_mask
and the entire E712 is more than dubious.
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.
But of course, we can enable it, given that the linters love it.
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.
I'm not sure about what/how you think so. https://docs.astral.sh/ruff/rules/true-false-comparison/ reads quite reasonable to me
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.
not (torch.randn(5, 5) > 0)
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.
It also misrepresents pep 8, which literally says
Don’t compare boolean values to True or False using ==:
but the check does
Don’t compare any values to True or False using ==:
What does this PR do?
As per title.
Related #2218
cc @Borda