Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(draft): read RoPE parameters from Transformers v5 configs - #702

Merged
jiapingW merged 2 commits into
sgl-project:mainfrom
wiketool:main
Jul 24, 2026
Merged

fix(draft): read RoPE parameters from Transformers v5 configs#702
jiapingW merged 2 commits into
sgl-project:mainfrom
wiketool:main

Conversation

@wiketool

Copy link
Copy Markdown
Contributor

Motivation

Transformers v5 refactored RoPE configuration in [huggingface/transformers#39847]. Starting from Transformers 5.0.0, RoPE parameters are standardized under config.rope_parameters, and config.rope_theta is no longer guaranteed to exist.

In Transformers 4.57.1, Llama configs stored the values as top-level attributes, configuration_llama.py.:

# Transformers 4.57.1
self.rope_theta = rope_theta
self.rope_scaling = rope_scaling

In Transformers 5.x, legacy values are moved into rope_parameters during config initialization, modeling_rope_utils.py:

# Transformers 5.8.1
rope_scaling = kwargs.pop("rope_scaling", None)
self.rope_parameters = rope_scaling or self.rope_parameters
rope_theta = kwargs.pop("rope_theta", getattr(self, "rope_theta", self.default_theta))
self.rope_parameters.setdefault("rope_theta", rope_theta)

After SpecForge upgraded Transformers from 4.57.1 to 5.8.1, the custom EAGLE3 and P-EAGLE RoPE implementations still read the legacy top-level config.rope_theta. For configs using a non-default RoPE base, this could silently fall back to 10000 and produce rotary embeddings inconsistent with the target model.

Modifications

  • Add a shared get_rope_config helper compatible with both Transformers v4 and v5:
    • Prefer config.rope_parameters when available.
    • Fall back to the legacy config.rope_theta and config.rope_scaling attributes.
  • Update the EAGLE3 attention implementation to use the resolved rope_theta and RoPE parameters without mutating the Transformers config object.
  • Propagate the configured RoPE base to all local rotary embedding variants, including default RoPE, linear scaling, dynamic NTK scaling, Llama 3 scaling, MRoPE, and YaRN.
  • Store the resolved parameters in self.rope_scaling so all MRoPE attention backends use the same configuration source.
  • Update P-EAGLE's shared rotary embedding initialization and checkpoint rebuild path to use the same compatibility helper.
  • Add regression coverage for:
    • Transformers v4- and v5-style RoPE configuration layouts.
    • Non-default rope_theta propagation in EAGLE3 and MRoPE.
    • P-EAGLE initialization and rotary embedding rebuild.

Checklist

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a helper function get_rope_config to support both v4 and v5 RoPE configurations across llama3_eagle.py and peagle.py, ensuring robust extraction of rope_theta and rope_scaling. Corresponding unit tests have also been added to verify this behavior. The review feedback correctly identifies a potential KeyError or TypeError when directly indexing rope_params["rope_theta"] and suggests a safer fallback implementation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +121 to +124
rope_params = getattr(config, "rope_parameters", None)
if rope_params is not None:
return rope_params["rope_theta"], rope_params
return getattr(config, "rope_theta", 10000), getattr(config, "rope_scaling", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Accessing rope_params["rope_theta"] directly can raise a KeyError if the key is missing from the dictionary, or a TypeError if rope_params is not a dictionary (e.g., if it is a custom configuration object). To ensure robustness across different Transformers versions and custom model configurations, we should safely retrieve rope_theta using .get() or getattr(), with a fallback to config.rope_theta or 10000.

Suggested change
rope_params = getattr(config, "rope_parameters", None)
if rope_params is not None:
return rope_params["rope_theta"], rope_params
return getattr(config, "rope_theta", 10000), getattr(config, "rope_scaling", None)
rope_params = getattr(config, "rope_parameters", None)
if rope_params is not None:
if isinstance(rope_params, dict):
rope_theta = rope_params.get("rope_theta")
else:
rope_theta = getattr(rope_params, "rope_theta", None)
if rope_theta is None:
rope_theta = getattr(config, "rope_theta", 10000)
return rope_theta, rope_params
return getattr(config, "rope_theta", 10000), getattr(config, "rope_scaling", None)

@jiapingW

Copy link
Copy Markdown
Collaborator

I have tested the failed unittest, it's OK.

@jiapingW
jiapingW self-requested a review July 24, 2026 06:00
@jiapingW
jiapingW merged commit 43c5f8f into sgl-project:main Jul 24, 2026
1 of 3 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.

2 participants