Skip to content

Fix uninitialized embedding indices in test_embedding_meta_indices (#188002) - #3551

Merged
pragupta merged 1 commit into
release/2.13from
fix_embedding_meta_indices
Aug 14, 2026
Merged

pragupta merged 1 commit into
release/2.13from
fix_embedding_meta_indices

Conversation

@BLOrange-AMD

Copy link
Copy Markdown

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.

…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
@BLOrange-AMD
BLOrange-AMD requested a review from pragupta August 10, 2026 15:48
@pragupta
pragupta merged commit 6d72da1 into release/2.13 Aug 14, 2026
3 checks passed
@pragupta
pragupta deleted the fix_embedding_meta_indices branch August 14, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants