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

Use a constant with clearly-defined type for log2e in fwd_kernel_splitK #1181

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

bertmaher
Copy link
Contributor

Summary:
Triton 3.2 made some changes to its interpretation of constants (triton-lang/triton#4613) which makes Triton more consistent with pytorch/numpy, but cause some surprising issues with this kernel. Specifically it seems like log2e is interpreted as float32 in one instance and float64 in another, which leads to reduced prediction accuracy in some cases.

To prevent this, let's make log2e a constant and define it as float32.

@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 Dec 20, 2024
@@ -341,7 +341,8 @@ def _fwd_kernel_splitK(
# scale sm_scale by log_2(e) and use
# 2^x instead of exp in the loop because CSE and LICM
# don't work as expected with `exp` in the loop
qk_scale = sm_scale * 1.44269504
log2e = tl.full((), 1.44269504, tl.float32)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment with an explanation/reference for why the code is this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes definitely, good call

Summary:
Triton 3.2 made some changes to its interpretation of constants
(triton-lang/triton#4613) which makes Triton more
consistent with pytorch/numpy, but cause some surprising issues with this
kernel.  Specifically it seems like log2e is interpreted as float32 in one
instance and float64 in another, which leads to reduced prediction accuracy in
some cases.

To prevent this, let's make log2e a constant and define it as float32.
@bertmaher bertmaher merged commit a2f37f8 into facebookresearch:main Dec 23, 2024
5 of 7 checks passed
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.

4 participants