Repository navigation
Skip fully-masked-out slices in masked softmax OpInfo samples - #196300
Closed
bodapatisaikrishna wants to merge 1 commit into
Closed
bodapatisaikrishna wants to merge 1 commit into
bodapatisaikrishna wants to merge 1 commit into
Conversation
torch.masked.{softmax,softmin,log_softmax} leave a reduction slice whose
elements are all masked out undefined (see torch/masked/_ops.py).
sample_inputs_masked_softmax draws its masks at random via make_tensor, so
for the 0-d input case a scalar False mask -- and other fully-masked
masks -- can occur. The eager result is then nan while the vmap result is
0, so test_vmapvjpvjp for masked.softmax fails a nan-vs-0 comparison
depending on the device's RNG stream (CPU carried an xfail for this;
a test-class rename shifted the draw and started hitting it on other
devices too).
Drop mask samples that leave any slice along the softmax dim fully masked
out, and remove the now-unnecessary CPU xfail on
test_vmapvjpvjp_masked_softmax.
Fixes pytorch#196289
bodapatisaikrishna
requested review from
Chillee,
kshitij12345 and
zou3519
as code owners
September 8, 2026 09:25
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/196300
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Contributor
Author
|
@pytorchbot label "topic: not user facing" |
zou3519
reviewed
Oct 16, 2026
zou3519
left a comment
Contributor
There was a problem hiding this comment.
sorry, this is not worth fixing, I don't think we support the _masked ops anymore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test/functorch/test_ops.py::TestOperators::test_vmapvjpvjp_masked_softmax_*(and
..._masked_softmin_*) can fail with ananvs0mismatch,depending on the RNG stream of the device under test.
The failing sample is the 0-d case from
sample_inputs_masked_softmax: ascalar input with
dim=0and a mask drawn by_generate_masked_op_maskvia
make_tensor(shape, dtype=torch.bool). For a 0-d input that mask is asingle random bool; when it is
Falsethe input is fully masked out,which
torch/masked/_ops.pyexplicitly documents as undefined:The eager path yields
nanand the vmap path yields0, so thegradient check compares values the op makes no promise about. CPU has
carried an
xfail("masked.softmax", device_type="cpu")for this;#193412 renamed the test class, which reshuffled the RNG draw and made
CUDA / ROCm / XPU start hitting the fully-masked mask too.
Changes
torch/testing/_internal/opinfo/definitions/_masked.py:sample_inputs_masked_softmaxnow skips a mask that leaves any slicealong the softmax
dimfully masked out (coversmasked.softmax,masked.softmin,masked.log_softmax).test/functorch/test_ops.py: remove the now-unnecessaryxfail("masked.softmax", device_type="cpu")intest_vmapvjpvjp.The change only drops the degenerate samples — with a fixed seed, the
generator went from 24 samples (2 with a fully-masked slice) to 22 (0),
and all non-degenerate samples are unchanged.
Testing
Verified on CPU (
torch==2.14.0runtime with the patched_masked.py/test_ops.pyoverlaid):Issue
Fixes #196289