Repository navigation
Fix uninitialized embedding indices in test_embedding_meta_indices (#188002) - #3551
Merged
Merged
Conversation
…ytorch#188002) test_embedding_meta_indices built its embedding index tensors with torch.empty(..., dtype=torch.long), i.e. uninitialized memory. The values never mattered for the FakeTensorMode metadata assertions, but under PropagateRealTensorsFakeTensorTest (fake_tensor_propagate_real_tensors) the real embedding gather actually executes on the device with those garbage indices. Garbage longs are almost always far outside the 20-row weight table, so the real gather reads out of bounds. On CUDA this is silently tolerated (index_select/embedding does not bounds check; the OOB read returns garbage), which is why the test was always green on NVIDIA CI. On ROCm gfx950 the same OOB read raises a hard GPU hardware exception (HSA_STATUS_ERROR_EXCEPTION, surfaced as "CUDA error: unspecified launch failure"), which poisons the HIP context for the rest of the process. Subsequent tests then fail at their first CUDA call (e.g. in setUp's manual_seed), so the failures were misattributed to unrelated tests (test_index_cuda_with_cpu_* for int16/float8), and the per-test disables pytorch#187836/pytorch#187867/pytorch#187895/pytorch#187942 were treating victims, not the cause. The fault was nondeterministic because torch.empty returns recycled allocator memory: in a fresh process it is often small/in-range, but after other tests churn the allocator it holds large/OOB values. It was localized by running only test_fake_tensor on gfx950 with AMD_SERIALIZE_KERNEL=3, which reports the fault at the actual launching test instead of a later victim. Fix: use in-range indices (torch.zeros) for the index tensors. Weights stay uninitialized since their contents are irrelevant. This removes the out-of- bounds access on every backend. Follow-up (separate change): with the trigger fixed, the int16/float8 test_index_cuda_with_cpu_* disables should be re-enabled and confirmed. Test Plan: ``` python test/test_fake_tensor.py -v -k embedding_meta_indices lintrunner -a test/test_fake_tensor.py ``` All embedding_meta_indices variants pass locally on CUDA, including test_embedding_meta_indices_propagate_real_tensors. The no-fault behavior is inherently gfx950-specific (CUDA tolerates the OOB read), so end-to-end confirmation is via re-running test_fake_tensor on an MI350 runner. Authored with Claude. Pull Request resolved: pytorch#188002 Approved by: https://github.com/frgossen
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.
Cherry-pick the upstream commit to fix MI450 test crash caused by following:
test_fake_tensor.py::PropagateRealTensorsFakeTensorTest::test_embedding_meta_indices_propagate_real_tensors
Verified test is passed after this fix.