Skip to content

Fix non-contiguous inputs in fused RoPE - #334

Merged
pragupta merged 1 commit into
ROCm:masterfrom
albmalamd:ROCM-25579
Jul 1, 2026
Merged

Fix non-contiguous inputs in fused RoPE#334
pragupta merged 1 commit into
ROCm:masterfrom
albmalamd:ROCM-25579

Conversation

@albmalamd

@albmalamd albmalamd commented Jun 18, 2026

Copy link
Copy Markdown

Motivation

The aiter RoPE kernels require the head (last) dim to be unit-stride, but inputs
can arrive non-contiguous: transposed layouts in forward, and broadcast/expanded
gradients (e.g. from .sum()) in backward.

Technical Details

This enforces contiguity at the apex↔aiter boundary across all aiter RoPE variants
(standard, cached, THD, 2D), centralized in a single _ensure_last_dim_contiguous
helper that copies only when stride(-1) != 1, leaving outer strides untouched.

Test Plan

Run the fused RoPE tests on ROCm with the aiter backend enabled, exercising the
standard, cached, THD, and 2D variants (covers transposed inputs and the
.sum() reduction loss that produces broadcast/expanded gradients):
USE_ROCM_AITER_ROPE_BACKEND=1 APEX_TEST_WITH_ROCM=1 python tests/L0/run_transformer/test_fused_rope.py

Test Result

  • Before: test_2d_forward_backward aborts with
    RuntimeError: rope_2d_bwd_impl requires all stride_d to be 1.
  • After: all RoPE forward/backward tests pass; fused vs. unfused outputs and
    gradients match within tolerance.

Submission Checklist

@albmalamd
albmalamd marked this pull request as ready for review June 25, 2026 13:09
@albmalamd albmalamd changed the title A fix for ROCM-25579 Fix non-contiguous inputs in fused RoPE Jun 25, 2026
@jithunnair-amd

Copy link
Copy Markdown
Collaborator

@albmalamd Please fill out the Test Plan and Rest Results sections.

@pragupta
pragupta merged commit 77b96da into ROCm:master Jul 1, 2026
2 of 3 checks passed
albmalamd added a commit to ROCm/pytorch that referenced this pull request Jul 3, 2026
Update the apex pinned commit in related_commits from 7e4aca3 to
ad1376f2 on the ROCm apex release/1.12.0 branch. This release tracks
only a single ubuntu apex line.

This bump brings in a cherry-pick of ROCm/apex PR #334
(ROCm/apex#334), which fixes non-contiguous
inputs in the fused RoPE aiter backend by enforcing last-dim
contiguity at the apex/aiter boundary (fixing the
"rope_2d_bwd_impl requires all stride_d to be 1" crash on transposed
inputs and broadcast/expanded gradients). This is purely a dependency
pin update to pull in the fix, not a PyTorch code change.

Test Plan: Metadata-only change to the related_commits pin file; no
build or test run. Verified the diff updates only the apex line.

Authored-with: Claude (Anthropic AI assistant).
albmalamd added a commit to ROCm/pytorch that referenced this pull request Jul 3, 2026
Update the apex pinned commit in related_commits (ubuntu and centos)
from 973a3632 to c0f56f7e on the ROCm apex release/1.11.0 branch.

This bump brings in a cherry-pick of ROCm/apex PR #334
(ROCm/apex#334), which fixes non-contiguous
inputs in the fused RoPE aiter backend by enforcing last-dim
contiguity at the apex/aiter boundary (fixing the
"rope_2d_bwd_impl requires all stride_d to be 1" crash on transposed
inputs and broadcast/expanded gradients). This is purely a dependency
pin update to pull in the fix, not a PyTorch code change.

Test Plan: Metadata-only change to the related_commits pin file; no
build or test run. Verified the diff updates only the two apex lines.

Authored-with: Claude (Anthropic AI assistant).
albmalamd added a commit to ROCm/pytorch that referenced this pull request Jul 3, 2026
Update the apex pinned commit in related_commits (ubuntu and centos)
from 57295015 to e97c6656 on the ROCm apex release/1.10.0 branch.

This bump brings in a cherry-pick of ROCm/apex PR #334
(ROCm/apex#334), which fixes non-contiguous
inputs in the fused RoPE aiter backend by enforcing last-dim
contiguity at the apex/aiter boundary (fixing the
"rope_2d_bwd_impl requires all stride_d to be 1" crash on transposed
inputs and broadcast/expanded gradients). This is purely a dependency
pin update to pull in the fix, not a PyTorch code change.

Test Plan: Metadata-only change to the related_commits pin file; no
build or test run. Verified the diff updates only the two apex lines.

Authored-with: Claude (Anthropic AI assistant).
jithunnair-amd pushed a commit to ROCm/pytorch that referenced this pull request Jul 3, 2026
## Summary
Updates the apex pinned commit in `related_commits` for the ROCm apex
`release/1.10.0` branch, from `57295015408696edf0d03ed09f6f17b42a0be2b6`
to `e97c6656fb57d03e5fa48ad417853aa497f123ce` (both ubuntu and centos
lines).

This bump brings in a cherry-pick of ROCm/apex PR #334
(ROCm/apex#334), which fixes non-contiguous
inputs in the fused RoPE aiter backend by enforcing last-dim contiguity
at the apex/aiter boundary (fixing the "rope_2d_bwd_impl requires all
stride_d to be 1" crash on transposed inputs and broadcast/expanded
gradients). This is purely a dependency pin update to pull in the fix,
not a PyTorch code change.

## Test plan
- [ ] Metadata-only change to the `related_commits` pin file; CI
validates apex builds against the new pin.

Authored with the assistance of Claude (Anthropic AI assistant).
jithunnair-amd pushed a commit to ROCm/pytorch that referenced this pull request Jul 3, 2026
## Summary
Updates the apex pinned commit in `related_commits` for the ROCm apex
`release/1.11.0` branch, from `973a363235cd056e9da83716aabdd2691df9e70a`
to `c0f56f7eccd343a08a1b0d0be59f1e7e0e9b90b7` (both ubuntu and centos
lines).

This bump brings in a cherry-pick of ROCm/apex PR #334
(ROCm/apex#334), which fixes non-contiguous
inputs in the fused RoPE aiter backend by enforcing last-dim contiguity
at the apex/aiter boundary (fixing the "rope_2d_bwd_impl requires all
stride_d to be 1" crash on transposed inputs and broadcast/expanded
gradients). This is purely a dependency pin update to pull in the fix,
not a PyTorch code change.

## Test plan
- [ ] Metadata-only change to the `related_commits` pin file; CI
validates apex builds against the new pin.

Authored with the assistance of Claude (Anthropic AI assistant).
jithunnair-amd pushed a commit to ROCm/pytorch that referenced this pull request Jul 3, 2026
## Summary
Updates the apex pinned commit in `related_commits` for the ROCm apex
`release/1.12.0` branch, from `7e4aca37812b99e9c3e302d7d1d2e37ad6377f8c`
to `ad1376f20dc0ac107040b6077c96aed52bd14298`.

This bump brings in a cherry-pick of ROCm/apex PR #334
(ROCm/apex#334), which fixes non-contiguous
inputs in the fused RoPE aiter backend by enforcing last-dim contiguity
at the apex/aiter boundary (fixing the "rope_2d_bwd_impl requires all
stride_d to be 1" crash on transposed inputs and broadcast/expanded
gradients). This is purely a dependency pin update to pull in the fix,
not a PyTorch code change.

## Test plan
- [ ] Metadata-only change to the `related_commits` pin file; CI
validates apex builds against the new pin.

Authored with the assistance of Claude (Anthropic AI assistant).
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