Skip to content

fix(models): Drop the position-indexed token type lookup in RoPE encoders - #48407

Merged
vasqu merged 2 commits into
huggingface:mainfrom
harshaljanjani:fix/rope-encoder-token-type-lookup
Aug 31, 2026
Merged

vasqu merged 2 commits into
huggingface:mainfrom
harshaljanjani:fix/rope-encoder-token-type-lookup

Conversation

@harshaljanjani

@harshaljanjani harshaljanjani commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

CPU CI GPU run-slow

What does this PR do?

→ nomic_bert and jina_embeddings_v3 are the only two RoPE encoders that carry BERT's buffered token_type_ids gather. The buffer is all zeros, so the gather is a no-op, but indexing it with position_ids still constrains those IDs to max_position_embeddings, which RoPE has no reason to obey. Both original implementations build the zeros directly (nomic, jina) and nomic sets max_position_embeddings = 0 whenever rotary is on, so the cap tmk isn't upstream behaviour either.
→ In practice this caps nomic-embed-text-v1.5 at 2048 tokens on main (RuntimeError: index 2048 is out of bounds for dimension 1 with size 2048) despite n_positions: 8192; it reaches 8192 here. Un-skips test_model_rope_scaling_from_config for nomic, which passes now :)

cc: @vasqu

Before submitting

@vasqu vasqu 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.

Super nice catch, just a small nit on the test design

config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_for_token_classification(*config_and_inputs)

def test_forward_beyond_max_position_embeddings(self):

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.

Can we do the same structure as test_for_token_classification? You can also take a look at mamba which has a few regression tests atp.

Other than that, let's add a small comment/docstring to reference this PR and the reason behind this test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks a lot :)

@harshaljanjani
harshaljanjani requested a review from vasqu August 31, 2026 13:54
@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: jina_embeddings_v3, nomic_bert

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 33399491003:2
Result: success | Jobs: 2 | Tests: 25 | Failures: 0 | Duration: 2m 33s

@vasqu vasqu 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.

🫡 awesome work

@vasqu
vasqu enabled auto-merge August 31, 2026 14:05
@vasqu
vasqu added this pull request to the merge queue Aug 31, 2026
@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.

Merged via the queue into huggingface:main with commit a3f3da8 Aug 31, 2026
38 checks passed
@harshaljanjani
harshaljanjani deleted the fix/rope-encoder-token-type-lookup branch August 31, 2026 14:22
sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Sep 16, 2026
…ders (huggingface#48407)

* fix: Drop the position-indexed token type lookup in RoPE encoders

* fix: Changes
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