Skip to content

Conversation

crcrpar
Copy link
Collaborator

@crcrpar crcrpar commented Oct 14, 2025

What does this PR do?

As per title.

Related #2218

cc @Borda

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

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)

Copy link
Collaborator

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 ==:

@crcrpar crcrpar marked this pull request as ready for review October 15, 2025 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants