Skip to content

Fix uninitialized embedding indices in test_embedding_meta_indices - #188002

Closed
aorenste wants to merge 1 commit into
gh/aorenste/323/basefrom
gh/aorenste/323/head
Closed

aorenste wants to merge 1 commit into
gh/aorenste/323/basefrom
gh/aorenste/323/head

Conversation

@aorenste

@aorenste aorenste commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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
#187836/#187867/#187895/#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.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/188002

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 996af1f with merge base efda467 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Jun 24, 2026
@pytorch-bot

pytorch-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/rocm.
Currently recognized labels are

  • ciflow/b200
  • ciflow/b200-distributed
  • ciflow/b200-symm-mem
  • ciflow/binaries
  • ciflow/binaries_libtorch
  • ciflow/binaries_wheel
  • ciflow/docker
  • ciflow/dtensor
  • ciflow/dynamo
  • ciflow/h100
  • ciflow/h100-cutlass-backend
  • ciflow/h100-distributed
  • ciflow/h100-symm-mem
  • ciflow/inductor
  • ciflow/inductor-cu126
  • ciflow/inductor-micro-benchmark
  • ciflow/inductor-micro-benchmark-cpu-x86
  • ciflow/inductor-pallas
  • ciflow/inductor-perf-compare
  • ciflow/inductor-perf-test-nightly-rocm-mi300
  • ciflow/inductor-perf-test-nightly-rocm-mi350
  • ciflow/inductor-perf-test-nightly-x86-zen
  • ciflow/inductor-perf-test-nightly-xpu
  • ciflow/inductor-periodic
  • ciflow/inductor-rocm-mi200
  • ciflow/inductor-rocm-mi300
  • ciflow/mps
  • ciflow/nightly
  • ciflow/op-benchmark
  • ciflow/periodic
  • ciflow/periodic-rocm-mi200
  • ciflow/periodic-rocm-mi300
  • ciflow/pull
  • ciflow/riscv64
  • ciflow/rocm-mi200
  • ciflow/rocm-mi300
  • ciflow/rocm-navi31
  • ciflow/rocm-nightly
  • ciflow/s390
  • ciflow/slow
  • ciflow/slow-rocm-mi200
  • ciflow/torchtitan
  • ciflow/triton_binaries
  • ciflow/trunk
  • ciflow/tsan
  • ciflow/unstable
  • ciflow/vllm
  • ciflow/win-arm64
  • ciflow/xpu

Please add the new label to .github/pytorch-probot.yml

@aorenste
aorenste requested review from bobrenjc93 and frgossen June 24, 2026 02:23
@aorenste

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 24, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…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
@github-actions
github-actions Bot deleted the gh/aorenste/323/head branch July 25, 2026 02:24
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…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
pragupta pushed a commit to ROCm/pytorch that referenced this pull request Aug 14, 2026
…ytorch#188002) (#3551)

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.

Co-authored-by: Aaron Orenstein <[email protected]>
jithunnair-amd pushed a commit to ROCm/pytorch that referenced this pull request Aug 25, 2026
…l) (#3594)

## Summary

Carry-forward of ROCm-specific commits from `release/2.13` onto
`release/2.14` ? the 2.14 analog of the 2.13 "IFU dedup" ([PR
#3503](#3503)).

Analyzes the full IFU delta from [PR
#3591](#3591) at `release/2.13`'s
tip (`6596a0d`): **81 commits** in `release/2.13` not in `release/2.14`,
each either dropped (already in 2.14, or 2.13-only) or cherry-picked
here.

## Method

Same rules as the [release/2.13 cherry-pick
process](https://amd.atlassian.net/wiki/spaces/MLSE/pages/1819593560):

- **Drop ? already in 2.14**: patch-id equivalence (`git cherry`),
upstream PR already present, or content already relocated/absorbed into
2.14 (verified during cherry-pick).
- **Drop ? 2.13-only**: version bump, `related_commits`,
dependency/requirements pins, release-line CD/build changes.
- **Carry-forward**: ROCm-specific fixes not present in 2.14 in any
form.

## Commits carried forward (13)

| Source | Notes |
|--------|-------|
| Fix reentrant deadlock in `torch.cuda._lazy_call` (#3496) | clean |
| Skip ROCm-failing tests in test_cuda/test_nn (#3504) | **conflict
resolved** ? kept 2.14's `test_graph_capture_error...` cleanup + took
`@skipIfRocm`; kept 2.14's `test_allocator_backend` (already fixes
LD_LIBRARY_PATH via `subprocess_env()`) |
| skip test_hip_device_count (rocprofiler-sdk) | clean |
| skip flaky test_Embedding_discontiguous_cuda | clean |
| Skip profiler check for foreach tests on ROCm (#3262) | clean |
| Skip test_is_pinned_no_context on python 3.14+ | clean |
| Skip flaky test_reentrant_parent_error_on_cpu | clean |
| Filter out CK gemms for gfx1250-only arch (#3545) | clean |
| Fix hipify skipping sources under Windows subst drives (ROCM-29365)
(#3561) | clean |
| Fixed gfx1250_preferred_backend test (#3546) | clean |
| [ROCm] Optimize AMD normalization backward kernel (pytorch#189405) | clean |
| [release/2.13] Build rocSHMEM for the requested gfx target (#3582) |
clean |
| fix PicklingError handling for Python 3.14 | clean |

## Removed from this PR (per team)

- [RELEASE_ONLY] skip test_autoheuristic in-code (pytorch#180927) ? not needed
on 2.14. Upstream
[pytorch#180927](pytorch#180927)
is `RELEASE_ONLY`, merged to upstream `release/2.12` only (never on
`main` or upstream `release/2.14`).

## Reviewed and excluded (team decision: not needed for 2.14)

| Commit | Reason |
|--------|--------|
| Update composable_kernel submodule with gfx1033 support (#3499) |
2.14's CK pin already includes gfx1033; carrying would move the
submodule pointer **backward**. |
| Revert "Skip cudagraphs for kernel-free inductor graphs" (pytorch#187347) |
2.14 already has the fixed upstream **re-land** on top of the revert;
carrying = regressing 2.14. |
| Revert "[Reland] Port index_add fast path" (pytorch#188196) | 2.14 already
has the newer **re-land (pytorch#189506)** on top of the revert; carrying =
regressing 2.14. |

## Dropped as already in 2.14 (verified during cherry-pick)

- rocm-smi deprecation (#3434) ? 2.14 already has zero `rocm_smi` refs.
- Enable linalg via hipSOLVER, remove Magma (#3455) ? all 6 upstream PRs
already in 2.14.
- Stabilize ROCm 7.14 testing (#3525) ? 2.14 already carries the guards
+ skip messages.
- Add gfx1250 support in GroupedBlas (#3532) ? already in 2.14 via
upstream pytorch#190703 (`ScaledBlasDeviceUtils`).
- Fix uninitialized embedding indices `test_embedding_meta_indices`
(pytorch#188002) ? upstream already in 2.14.
- Unskip ROCSHMEM triton UTs on rocm 7.14 (#3578) ? targets a 2.13-only
7.14 module skip that 2.14 never had; tests already run on 2.14.

Remaining commits drop as 2.13-only (version/pins/related_commits/CD) or
as already-in-2.14 by patch-id/upstream.

## Test plan

- [x] TheRock full-stack dev build (torch + torchaudio + torchvision +
triton) on gfx94X-dcgpu for Python 3.10-3.14, all **Build** jobs green
(ROCm `10.1.0a20260822`, on the `aws-linux-scale-rocm-prod` pool), after
bringing the branch up to its base so `related_commits` resolves
torchaudio/torchvision:
  - py3.10  https://github.com/ROCm/TheRock/actions/runs/32863299013
  - py3.11  https://github.com/ROCm/TheRock/actions/runs/32863305363
  - py3.12  https://github.com/ROCm/TheRock/actions/runs/32863311391
  - py3.13  https://github.com/ROCm/TheRock/actions/runs/32863318109
  - py3.14  https://github.com/ROCm/TheRock/actions/runs/32863325370
- [x] TheRock CI wheel build on gfx94X-dcgpu for Python 3.10-3.14 all
green (ROCm `10.1.0a20260822`, torch-only, on the
`aws-linux-scale-rocm-prod` pool, ~1h40m each):
  - py3.10  https://github.com/ROCm/TheRock/actions/runs/32818564344
  - py3.11  https://github.com/ROCm/TheRock/actions/runs/32818568751
  - py3.12  https://github.com/ROCm/TheRock/actions/runs/32818572249
  - py3.13  https://github.com/ROCm/TheRock/actions/runs/32818576288
  - py3.14  https://github.com/ROCm/TheRock/actions/runs/32818580229



## Processed Commits List
Spreasheet with each commit evaluated for cherry-pick & resolution
(drop/include) with reasoning:


[pr3594-commit-outcomes.xlsx](https://github.com/user-attachments/files/31390971/pr3594-commit-outcomes.xlsx)

---------

Signed-off-by: pablo-garay <[email protected]>
Co-authored-by: Iurii Paikov <[email protected]>
Co-authored-by: Chinmay Dattanand Kuchinad <[email protected]>
Co-authored-by: rocm-repo-management-api-6[bot] <212817015+rocm-repo-management-api-6[bot]@users.noreply.github.com>
Co-authored-by: Dmitry Nikolaev <[email protected]>
Co-authored-by: srinivamd <[email protected]>
Co-authored-by: Subramanian <[email protected]>
Co-authored-by: zjliu-amd <[email protected]>
Co-authored-by: Andres Lugo <[email protected]>
Co-authored-by: pablo-garay <[email protected]>
Co-authored-by: Bo Li <[email protected]>
Co-authored-by: Anatoliy Litvinenko <[email protected]>
Co-authored-by: Jeff Daily <[email protected]>
Co-authored-by: Luca Bruni <[email protected]>
Co-authored-by: albmalamd <[email protected]>
Zyq-gg pushed a commit to Zyq-gg/pytorch-das that referenced this pull request Nov 13, 2026
Why: Uninitialized long indices can access outside embedding bounds when FakeTensor propagates real tensors, causing GPU faults on ROCm.
原因:FakeTensor 传播真实张量时,未初始化的 long 索引可能访问 embedding 边界之外,在 ROCm 上导致 GPU 故障。

What: Initialize meta, CPU, and CUDA embedding test indices with zeros.
修改:将 meta、CPU 和 CUDA 的 embedding 测试索引初始化为零。

Impact: Stabilizes test_embedding_meta_indices under real tensor propagation without changing product behavior.
影响:在不改变产品行为的前提下,稳定真实张量传播模式下的 test_embedding_meta_indices。

Upstream: pytorch/pytorch#188002, 996af1f7a90cb066a99ba1ad9e82444aea0e7ad1
(cherry picked from commit 996af1f7a90cb066a99ba1ad9e82444aea0e7ad1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rocm ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants