Skip to content

[ROCm] Fix GPU memory fault in batched_unary_embeddings backward - #6261

Open
avbokovoy wants to merge 5 commits into
pytorch:mainfrom
ROCm:abokovoi/fix-batched-unary-embeddings-backward-test
Open

[ROCm] Fix GPU memory fault in batched_unary_embeddings backward#6261
avbokovoy wants to merge 5 commits into
pytorch:mainfrom
ROCm:abokovoi/fix-batched-unary-embeddings-backward-test

Conversation

@avbokovoy

Copy link
Copy Markdown
Contributor

Problem

batched_unary_embeddings_test.py::test_gpu crashed with a GPU memory access fault on ROCm. The permute sub-test passed
offsets of length 8 (7 segments) for a T=2 module, violating the op's offsets.numel() == T*B+1 contract. Forward silently truncated
B=3 and dropped the trailing segment; backward walked all 7 segments, deriving an out-of-range table id t=2 that indexed
grad_weight out of bounds.

Fix

  • Correct the test offsets to [0..8] (9 entries -> T*B+1 for B=4).
  • Add host-side TORCH_CHECK guards on the offsets length in forward (CPU/CUDA/HIP) and backward (CUDA/HIP), so malformed input fails loudly instead of faulting/corrupting grads.

@meta-codesync

meta-codesync Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@q10 has imported this pull request. If you are a Meta employee, you can view this in D118492251.

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eager paths now reject malformed offsets, but batched_unary_embeddings_forward_meta still floor-divides (offsets.sym_numel() - 1) / T without enforcing the new T > 0 / divisibility invariant. FakeTensor/export can therefore accept an input shape that eager now rejects and report a misleading B. Could the Meta implementation mirror the new validation?

@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@avbokovoy

Copy link
Copy Markdown
Contributor Author

The eager paths now reject malformed offsets, but batched_unary_embeddings_forward_meta still floor-divides (offsets.sym_numel() - 1) / T without enforcing the new T > 0 / divisibility invariant. FakeTensor/export can therefore accept an input shape that eager now rejects and report a misleading B. Could the Meta implementation mirror the new validation?

Sure, done in df219f4. Added dedicated test in 99737ef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants