-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Add missing boundary checks to cunn_SoftMaxForward #140682
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
Conversation
This fixes OOB memory access for followng code ``` import torch qk = torch.randn((1024,587), dtype=torch.float64, device='cuda') smqk = torch.softmax(qk, dim=-1) ```
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/140682
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 9f8c51c with merge base 99c8d5a ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
The segfault can be reproduced on ROCM platform reliably with the following env vars , which add guard pages to detect OOB memory access. |
|
@jithunnair-amd @pruthvistony @jataylo @jeffdaily |
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.
If you have a reproducer, could you add a test case for this change please?
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.
@xinyazhang please add some sort of a test to the PR description, but otherwise looks good to me (we can not have unittest unfortunately, because at least on CUDA something like that would not be detectable without compute sanitizer)
I think PR description should be sufficient, testing it with compute sanitizer now. And it fails: |
Would we get some signal with |
Nope, as GPU maps memory into its address space in a pretty large chunks(A100 page size is probably 2Mb or something), see vs launching the same with compute sanitizer, that will catch an error |
|
@pytorchbot merge -f "Looks reasonable" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
For documentation @malfet @eqy @jeffdaily @jithunnair-amd here is the independent unit test code. #!/usr/bin/env python
import torch
import pytest
@pytest.mark.parametrize("dtype",
[torch.float16, torch.bfloat16, torch.float32, torch.float64],
ids=['fp16', 'bf16', 'fp32', 'fp64'])
def test_softmax_oob_access(dtype):
qk_with_margin = torch.randn((1024+1, 587), dtype=dtype, device="cuda");
qk_with_margin[-1].fill_(float('nan'))
qk = qk_with_margin[:-1, :]
smqk = torch.softmax(qk, dim=-1)
assert not torch.isnan(smqk).any(), 'NaN indicates OOB memory access'It only fails on float64 apparently, (but our SDPA's UT suffers from it and has to use CPU implementation on certain cases) |
|
@xinyazhang that's smart and indeed reliable, please do not hesitate to propose a PR that adds this unites |
This fixes OOB memory access for following code ```python import torch qk = torch.randn((1024,587), dtype=torch.float64, device='cuda') smqk = torch.softmax(qk, dim=-1) ``` Pull Request resolved: pytorch#140682 Approved by: https://github.com/jeffdaily, https://github.com/malfet
This fixes OOB memory access for following code
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @dllehr-amd @jataylo @hongxiayang @naromero77amd