-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Add MaskedTensor passthrough: unfold, F.Unfold, F.Fold, stack #125262
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
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/125262
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit e919719 with merge base 52c7c89 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Most likely the right fix indeed. |
|
Hi @nowtryz - Thanks for sending the PR! The tests are in https://github.com/pytorch/pytorch/blob/main/test/test_maskedtensor.py . |
|
Hi,
Is it possible to have a bit of help to understand how the test framework
works? Or a link to a documentation?
When I used the debugger, I did not see the pass through dispatch being
called.
Thank you
|
|
@nowtryz - You should be able to run this with pytorch/test/test_maskedtensor.py Lines 714 to 725 in e3627d0
TestBasics (not that it's a basic op, but because it doesn't fit the other buckets).
|
|
Hi, Ok perfect, I confused From what I see |
|
@nowtryz - Yes, exactly. A |
|
Hi, From what I understand, In the meantime, I added support for |
|
@nowtryz - Hm, on reduction semantics see details here: https://pytorch.org/tutorials/prototype/maskedtensor_advanced_semantics#reduction-semantics and also pytorch/rfcs#27 . One way to derive semantics of composites such as Fold (or matmul) is by inferring them from the semantics of its components. Or said different (and maybe less confusingly), if you were to implement Fold in terms of existing MaskedTensor operations (if that's possible), what would it do? These kind of discussions are really important (in my very biased opinion) to separate out all the subtly different use cases: raggedness ( So, for example, if you mask out an element it doesn't have a value, but it does still have a position. Should that influence the denominator in |
|
Hi @cpuhrsch, I'm trying to catch with the Fold/Unfold operators as they are different from Tensor.unfold. Looking at the operator's documentation, I understand the masked semantics of this operator like this: If we have blocks of size If I am correct, then I am not sure how to implement if efficiently. My first idea (to reuse the existing ATen operator without further modifications) is the following:
I don't know if it is more optimized, but I can also combine (1) and (3) by performing (3) and converting the result back to boolean to obtain the new mask. What do you think? |
b202d11 to
c2b41b0
Compare
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
|
@nowtryz I had to unexpectedly go on leave due to family reasons, but let's revisit this. Are there tests for im2col or col2im that you could add the additional dtype to? Otherwise this looks fine, thank you for sending this :) |
|
Hi @cpuhrsch, No problem! If I understand correctly, updating torch/testing/_internal/common_methods_invocations.py should have generated the correct tests for im2col and col2im. Though the tests fail for these functions on cuda with the dtype I added. I have to check the cuda kernel but the fix should be easy (however I do not know cuda) |
|
@nowtryz - Thanks for double checking, please ping again if you need more pointers. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
0127168 to
e919719
Compare
|
Hi @cpuhrsch! |
|
@pytorchbot merge |
|
This PR needs to be approved by an authorized maintainer before merge. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
|
I believe this caused a memory leak in test_maskedtensor.py::TestBasicsCUDA::test_stack_cuda GH job link HUD commit link, @nowtryz could you take a look? |
|
@clee2000 - I think we'll need to revert this again then. |
|
@clee2000 That's strange, the test is just doing a passthrough to the stack function, there is no change in the cuda kernels as part of this test, I will need to take a deeper look |
…h#125262) Hi, I noticed the `unfold` operator was missing on MaskedTensor. I tested that my change works when calling unfold and backward on a `MaskedTensor` but I didn't find the tests for the dispatch of such operation. Where is it? Pull Request resolved: pytorch#125262 Approved by: https://github.com/cpuhrsch
…pytorch#125262)" This reverts commit f685018. Reverted pytorch#125262 on behalf of https://github.com/ZainRizvi due to Hi, this PR appears to be calling maskedtensor tests to fail on main. Please rebase your changes onto the latest trunk build to repro the failure. test_maskedtensor.py::TestOperatorsCUDA::test_like_empty_like_layout1_cuda_bool [GH job link](https://github.com/pytorch/pytorch/actions/runs/10604716811/job/29393256312) [HUD commit link](https://hud.pytorch.org/pytorch/pytorch/commit/f685018ea9d08f98cbd7106028db134f967f74d3) ([comment](pytorch#125262 (comment)))
…h#125262) Hi, I noticed the `unfold` operator was missing on MaskedTensor. I tested that my change works when calling unfold and backward on a `MaskedTensor` but I didn't find the tests for the dispatch of such operation. Where is it? Pull Request resolved: pytorch#125262 Approved by: https://github.com/cpuhrsch
This test is currently failing in trunk when memory leak check is enabled, for example https://github.com/pytorch/pytorch/actions/runs/11296206361/job/31422348823#step:22:1970. When testing locally, calling `backward` on a masked tensor always causes memory leak until I clean up the data and the mask manually. This is probably related to this warning from masked tensor `UserWarning: It is not recommended to create a MaskedTensor with a tensor that requires_grad. To avoid this, you can use data.clone().detach()`, but I don't know much about the internal details here to go further. So, let's just fix the test first/ ### Testing ``` PYTORCH_TEST_CUDA_MEM_LEAK_CHECK=1 python test/test_maskedtensor.py TestBasicsCUDA.test_stack_cuda ``` passes and doesn't warn about memory leak anymore. The test itself came from #125262 (comment) Pull Request resolved: #137815 Approved by: https://github.com/kit1980
Hi,
I noticed the
unfoldoperator was missing on MaskedTensor.I tested that my change works when calling unfold and backward on a
MaskedTensorbut I didn't find the tests for the dispatch of such operation. Where is it?