Skip to content

update rope_scaling #5421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 18, 2025
Merged

Conversation

Jintao-Huang
Copy link
Collaborator

No description provided.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Jintao-Huang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the rope_scaling initialization logic within the ModelArguments class. The primary goal is to improve how the original_max_position_embeddings (or origin_max_model_len) is determined, providing a more robust and flexible calculation. Additionally, a strict validation assertion related to model length has been converted into a warning, allowing for greater configuration tolerance.

Highlights

  • Enhanced origin_max_model_len determination: The logic for determining origin_max_model_len within the _init_rope_scaling method has been improved. It now includes a more robust search order and a new fallback calculation that derives the original length from self.model_info.max_model_len and self.model_info['factor'] if original_max_position_embeddings is not directly found.
  • Explicit storage of origin_max_model_len: The calculated origin_max_model_len is now explicitly added to the rope_scaling dictionary, ensuring this derived value is consistently available for further use.
  • Relaxed model length validation from assert to warning: A critical assertion that self.max_model_len must be less than or equal to the calculated rope_model_len has been replaced with a logger.warning. This change allows the system to proceed with configurations where max_model_len might exceed rope_model_len, while still alerting the user to this condition.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 updates the logic for rope_scaling initialization. The changes introduce more complex logic for determining origin_max_model_len and replace a strict assertion with a warning for better user experience.

However, I've found a critical issue in the new logic where a ModelInfo object is incorrectly accessed as a dictionary, which will cause a runtime error. I've also identified a potential issue with using .get() for boolean checks which could lead to incorrect behavior with falsy values. My review comment includes a suggested fix for these issues.

Comment on lines 122 to 128
if rope_scaling and rope_scaling.get('original_max_position_embeddings'):
origin_max_model_len = rope_scaling['original_max_position_embeddings']
elif self.model_info.rope_scaling and 'original_max_position_embeddings' in self.model_info.rope_scaling:
origin_max_model_len = self.model_info.rope_scaling['original_max_position_embeddings']
else:
elif self.model_info.rope_scaling:
if self.model_info.rope_scaling.get('original_max_position_embeddings'):
origin_max_model_len = self.model_info.rope_scaling['original_max_position_embeddings']
elif self.model_info.get('factor'):
origin_max_model_len = self.model_info.max_model_len // self.model_info['factor']
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This block has a couple of issues:

  1. Using .get() in a boolean context can be problematic if the values for 'original_max_position_embeddings' or 'factor' can be falsy (e.g., 0) but still valid. It's safer to check for key existence explicitly.
  2. self.model_info is a ModelInfo object, not a dictionary. Accessing it with .get() or [] will raise an error. You likely intended to access self.model_info.rope_scaling.

The logic can also be simplified to be less nested and more readable.

Suggested change
if rope_scaling and rope_scaling.get('original_max_position_embeddings'):
origin_max_model_len = rope_scaling['original_max_position_embeddings']
elif self.model_info.rope_scaling and 'original_max_position_embeddings' in self.model_info.rope_scaling:
origin_max_model_len = self.model_info.rope_scaling['original_max_position_embeddings']
else:
elif self.model_info.rope_scaling:
if self.model_info.rope_scaling.get('original_max_position_embeddings'):
origin_max_model_len = self.model_info.rope_scaling['original_max_position_embeddings']
elif self.model_info.get('factor'):
origin_max_model_len = self.model_info.max_model_len // self.model_info['factor']
if rope_scaling and 'original_max_position_embeddings' in rope_scaling:
origin_max_model_len = rope_scaling['original_max_position_embeddings']
elif self.model_info.rope_scaling:
if 'original_max_position_embeddings' in self.model_info.rope_scaling:
origin_max_model_len = self.model_info.rope_scaling['original_max_position_embeddings']
elif 'factor' in self.model_info.rope_scaling:
origin_max_model_len = self.model_info.max_model_len // self.model_info.rope_scaling['factor']

@Jintao-Huang Jintao-Huang merged commit 16da9d3 into modelscope:main Aug 18, 2025
1 of 2 checks passed
Jintao-Huang added a commit that referenced this pull request Aug 18, 2025
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