Skip to content

[None][fix] Fix unfused RoPE for yarn models: double rotation and GPT-OSS pairing - #16378

Merged
Hudayday merged 1 commit into
NVIDIA:mainfrom
Hudayday:fix-gptoss-unfused-rope
Jul 17, 2026
Merged

[None][fix] Fix unfused RoPE for yarn models: double rotation and GPT-OSS pairing#16378
Hudayday merged 1 commit into
NVIDIA:mainfrom
Hudayday:fix-gptoss-unfused-rope

Conversation

@Hudayday

@Hudayday Hudayday commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Description

With rope_fusion=False, GPT-OSS (and any yarn-scaled model on the unfused
path) generates position-dependent garbage: short outputs look fine, long
generations degrade into fragments. Two independent bugs stack on this path,
and both are needed for a correct rotation — one fix controls how many
times
RoPE is applied, the other how it is applied.

Bug 1: RoPE applied twice (yarn missing from is_rope())

create_attention hands pos_embd_params to the backend whenever the
embedding type is not in PositionEmbeddingType.is_rope(). yarn was missing
from that list, so with rope_fusion=False the Python RotaryEmbedding
rotated q/k once and the C++ QKV preprocess (which maps yarn onto its NeoX
rotation branch) rotated them again before writing the KV cache. The cached
K ends up mscale²-scaled and rotated by twice the angle, so the error grows
with position.

Fix: add yarn to is_rope(). The existing condition then keeps the
rope params away from the backend on the unfused path, and the existing
"rope types must carry rope params" validation now covers yarn too.

Bug 2: wrong pairing convention (GPT-OSS is_neox=False)

GPT-OSS applies NeoX-style (rotate-half) RoPE, matching the HF reference,
but declared is_neox=False (GPT-J interleaved). The fused kernel ignores
this flag for yarn and always rotates NeoX-style, which masked the wrong
value since the model landed (#6645); the unfused path honors the flag and
paired the rotary dims incorrectly.

Fix: is_neox=True. No effect on the fused path (the flag is unused
there). modeling_mistral.py also declares is_neox=False for yarn and may
deserve the same audit.

Why both are required

Fixing only Bug 2 still double-rotates; fixing only Bug 1 leaves the single
rotation incorrectly paired. Either alone still produces garbage.

Evidence (GPT-OSS-20B)

  • Post-fix, the unfused K cache is bitwise-aligned with the fused path at
    every position (cos = 1.0, norm ratio = 1.0). Pre-fix it decayed to
    cos = −0.18 by position 150 with a norm ratio equal to the yarn mscale
    (1.3466) — the fingerprint of a second yarn rotation.
  • AIME25 avg pass@1 (n=8, official sampling): **70.83 fused vs 70.00
  • unfused** (parity within noise). Pre-fix unfused scored 0.
  • Affects any code path that disables rope fusion for a yarn model, e.g.
    sparse-attention methods that require unfused RoPE.

Test Coverage

Two regression tests in tests/unittest/_torch/modules/test_rotary_embedding.py
(registered in l0_h100.yml):

  • unfused yarn ⇒ the backend receives no position-embedding params (RoPE
    cannot be applied twice);
  • the unfused yarn rotation matches the fused kernel's NeoX rotate-half
    convention on the same cos/sin table (bit-level comparison).

Summary by CodeRabbit

  • Bug Fixes

    • Corrected YARN rotary positional embedding behavior for GPT-OSS models.
    • Prevented duplicate application of YARN embeddings when rotary fusion is disabled.
    • Improved numerical correctness for unfused YARN rotary calculations.
  • Tests

    • Added coverage validating YARN embedding configuration and output accuracy.

@Hudayday
Hudayday requested review from a team as code owners July 14, 2026 15:18
@Hudayday Hudayday changed the title [None][fix] Fix unfused RoPE for yarn models: double rotation and GPT-OSS pairing [None][fix] Fix unfused RoPE for yarn models: double rotation and GPT-OSS pairing Jul 14, 2026
Two stacked bugs made rope_fusion=False produce position-dependent
garbage for GPT-OSS (and would for any yarn-scaled model):

1. Double RoPE: create_attention hands pos_embd_params to the backend
   whenever the embedding type is not in PositionEmbeddingType.is_rope().
   yarn was missing from that list, so with rope_fusion=False the Python
   RotaryEmbedding rotated q/k once and the C++ QKV preprocess (which
   maps yarn onto its NeoX rotation branch) rotated them again before
   writing the KV cache: cached K ended up mscale^2-scaled and rotated by
   twice the angle, so the error grows with position and long generations
   degrade into fragments. Adding yarn to is_rope() restores the intended
   ownership (Python side rotates, backend receives no rope params) and
   extends the existing params validation to yarn.

2. GPT-OSS declared is_neox=False, but the model applies NeoX-style
   (rotate-half) RoPE, as in the HF reference. The fused kernel ignores
   the flag for yarn and always rotates NeoX-style, which masked the
   wrong value; the unfused path honors it and applied interleaved
   pairing. (modeling_mistral.py declares is_neox=False for yarn too and
   may deserve the same audit.)

Verified on GPT-OSS-20B: post-fix unfused K cache is bitwise-aligned
with the fused path at every position (cos=1.0, norm ratio=1.0); AIME25
avg pass@1 (n=8, official sampling) is 70.83 fused vs 70.00 unfused.
Pre-fix unfused scored 0. Regression tests cover backend ownership and
pairing-convention parity against the kernel cos/sin table.

Signed-off-by: tianruih <tianruih@nvidia.com>
@Hudayday
Hudayday force-pushed the fix-gptoss-unfused-rope branch from c1455b4 to 11e2ba3 Compare July 14, 2026 15:22
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ef64dfda-d53e-44aa-bf70-d58e818bfbc7

📥 Commits

Reviewing files that changed from the base of the PR and between 671bfec and c1455b4.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/models/modeling_gpt_oss.py
  • tensorrt_llm/functional.py
  • tests/unittest/_torch/modules/test_rotary_embedding.py

📝 Walkthrough

Walkthrough

YARN is now classified as a RoPE type, GPT-OSS uses NeoX YARN parameterization, and tests cover unfused YARN ownership and numerical rotation behavior.

Changes

YARN RoPE handling

Layer / File(s) Summary
YARN RoPE configuration
tensorrt_llm/functional.py, tensorrt_llm/_torch/models/modeling_gpt_oss.py
Classifies YARN as RoPE and sets GPT-OSS RopeParams.is_neox to True, with comments describing fused and unfused behavior.
Unfused YARN validation
tests/unittest/_torch/modules/test_rotary_embedding.py
Verifies that unfused attention does not pass position-embedding parameters to the backend and that Python YARN rotation matches the NeoX rotate-half reference.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: perkzzheng, yunruis

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main fixes for unfused YaRN RoPE and GPT-OSS rotary pairing.
Description check ✅ Passed The description includes the issue, fixes, and test coverage and is mostly complete relative to the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@Hudayday

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59223 [ run ] triggered by Bot. Commit: 11e2ba3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59223 [ run ] completed with state FAILURE. Commit: 11e2ba3
/LLM/main/L0_MergeRequest_PR pipeline #47720 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Hudayday

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59318 [ run ] triggered by Bot. Commit: 11e2ba3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59318 [ run ] completed with state SUCCESS. Commit: 11e2ba3
/LLM/main/L0_MergeRequest_PR pipeline #47801 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Hudayday

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@Hudayday
Hudayday enabled auto-merge (squash) July 15, 2026 06:03
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59374 [ run ] triggered by Bot. Commit: 11e2ba3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59374 [ run ] completed with state SUCCESS. Commit: 11e2ba3
/LLM/main/L0_MergeRequest_PR pipeline #47848 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Hudayday

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59403 [ run ] triggered by Bot. Commit: 11e2ba3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59403 [ run ] completed with state SUCCESS. Commit: 11e2ba3
/LLM/main/L0_MergeRequest_PR pipeline #47875 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Hudayday

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59434 [ run ] triggered by Bot. Commit: 11e2ba3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59434 [ run ] completed with state SUCCESS. Commit: 11e2ba3
/LLM/main/L0_MergeRequest_PR pipeline #47903 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Hudayday

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59449 [ run ] triggered by Bot. Commit: 11e2ba3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59449 [ run ] completed with state SUCCESS. Commit: 11e2ba3
/LLM/main/L0_MergeRequest_PR pipeline #47917 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Hudayday

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59460 [ run ] triggered by Bot. Commit: 11e2ba3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59460 [ run ] completed with state SUCCESS. Commit: 11e2ba3
/LLM/main/L0_MergeRequest_PR pipeline #47927 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Hudayday

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59570 [ run ] triggered by Bot. Commit: 11e2ba3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59570 [ run ] completed with state SUCCESS. Commit: 11e2ba3
/LLM/main/L0_MergeRequest_PR pipeline #48014 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Hudayday
Hudayday merged commit 29f4552 into NVIDIA:main Jul 17, 2026
8 checks passed
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.

6 participants