Skip to content

RoPE: 64-bit cos / sin row offsets for tables past 2**31 elements - #14714

Merged
danielhanchen merged 5 commits into
mainfrom
decode-rope-int64-offsets
Oct 25, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
decode-rope-int64-offsets

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What

The RoPE kernel loads cos + rot_position * cos_row_stride with an int32 position. For a cos / sin table with more than 2**31 elements (16.8M positions at head_dim 128, 4.2M at head_dim 512) the product wraps negative and the load reads before the table. #14599 routes single-token decode through this kernel, so decode at those positions now hits it; the training path with explicit position ids already could.

This PR adds cos and sin to the tensors long_indexing checks and widens the position to int64 when LONG_INDEXING is set. LONG_INDEXING is a constexpr, so every table below 2**31 elements compiles the exact same kernel as before.

Evidence (B200, fp16, head_dim 128)

position offset before after
1000 128000 ok ok
16777214 2147483392 ok ok
16777219 2147484032 illegal memory access matches the reference

No shipped model decodes that far today, so this is a bound fix, not a hot path change.

Tests

tests/test_decode_fused_rope.py: a meta-tensor check that a table past int32 offsets takes 64-bit indexing, and a GPU test (marked gpu, skips without about 9 GiB free) that decodes at position 2**31 / 128 + 3 against a reference. The GPU test crashes on main and passes here.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T05:29:26.802197Z 69ecdcd Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 8ede11e2a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

[skip ci]
Conflict in tests/test_decode_fused_rope.py: main (#14752) replaced the
atol = 0.05 asserts in test_decode_rope_on_another_device_orders_with_the_copy
with a bitwise check against a same-device rotation plus a 2 ulp bound vs
the unfused ops. Kept main's assertions verbatim and appended this branch's
two new tests (64-bit indexing selection on meta tensors, and the decode
RoPE reference check past int32 cache offsets) after that test.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 42d777ffcd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen danielhanchen self-assigned this Oct 25, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 69ecdcdce2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 37eec0a into main Oct 25, 2026
35 of 37 checks passed
@danielhanchen
danielhanchen deleted the decode-rope-int64-offsets branch October 25, 2026 09:07
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.

1 participant