Skip to content

[glm-moe-dsa] Indexer uses interleaved rope - #46842

Merged
pcuenca merged 4 commits into
mainfrom
indexer-interleave
Jul 2, 2026
Merged

[glm-moe-dsa] Indexer uses interleaved rope#46842
pcuenca merged 4 commits into
mainfrom
indexer-interleave

Conversation

@pcuenca

@pcuenca pcuenca commented Jun 23, 2026

Copy link
Copy Markdown
Member

CI

What does this PR do?

This is a proof-of-concept for discussion, the real fix will be more general (read below).

History as I understand it:

Another data point:

How this manifests in real-life

I'm testing again to exclude the transformers branch as a confounder; I think the result is a not-obvious quality degradation for long sequences.

Confirmed: generation degrades as sequence length increases.

Before this PR, I observed subtle degradation in long-context generation, but not obvious signals such as corrupted text. For example, asking to generate a space invaders game I saw syntax errors like in the following line (0.0.4 is not a number): this.tone(120, 0.0.4, 'sawtooth', 0.1, -80);

These errors did not happen with the fix in this PR. But I can't still rule out the reason might have been different (my "bad output" test was run before the on-going FP8/parallel fixes).

Real Fix

If this is indeed a bug, I think the real fix should be to read indexer_rope_interleave in the DS implementation and act accordingly.

Code Agent Policy

  • I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline and the
    Pull Request checks?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes according to the guidelines?
  • Did you write any new necessary tests?

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@pcuenca

pcuenca commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

Testing confirms the issue. I'll apply the fix to modular.

@pcuenca

pcuenca commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

This is ready for review now.

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, let's avoid having that flag if its set in stone that DSv32 use interleaved and dsa does not

@pcuenca

pcuenca commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

Thanks, let's avoid having that flag if its set in stone that DSv32 use interleaved and dsa does not

The property exists in GLM models. I will hardcode for now, we can revisit if/when more models use DSA.

@pcuenca
pcuenca requested a review from ArthurZucker June 26, 2026 10:55

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ty! if we just re-define properly outside should work? or is this an naming issue that modular does not catch well? (the functions have the same name)


# The indexer uses NON-interleaved (half-split) RoPE — unlike the main MLA attention
q_rot, k_rot = apply_rotary_pos_emb(q_rot, k_rot, cos, sin, unsqueeze_dim=2)
q_rot, k_rot = self.apply_indexer_rotary_pos_emb(q_rot, k_rot, cos, sin)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unsure I understand the need for the self function here!


# The indexer uses NON-interleaved (half-split) RoPE — unlike the main MLA attention
q_rot, k_rot = apply_rotary_pos_emb(q_rot, k_rot, cos, sin, unsqueeze_dim=2)
q_rot, k_rot = self.apply_indexer_rotary_pos_emb(q_rot, k_rot, cos, sin)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here! let' s leave it as defined outside no?

@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: glm_moe_dsa

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 28233301509:1
Result: success | Jobs: 6 | Tests: 650 | Failures: 0 | Duration: 9m 22s

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ty

@pcuenca

pcuenca commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

Thanks a lot for the patience @ArthurZucker, merging now then!

@pcuenca
pcuenca added this pull request to the merge queue Jul 2, 2026
Merged via the queue into main with commit 8698b5a Jul 2, 2026
32 checks passed
@pcuenca
pcuenca deleted the indexer-interleave branch July 2, 2026 12:10
@pcuenca pcuenca changed the title [glm-mode-dsa] Indexer uses interleaved rope [glm-moe-dsa] Indexer uses interleaved rope Jul 17, 2026
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
* [glm-mode-dsa] Indexer uses interleaved rope

* Apply to modular, read from config

* Remove from config

* Copy and modify forward implementation
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