-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Relax] Correct YaRN RoPE frequency scaling formula to align with the original paper #18576
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
base: main
Are you sure you want to change the base?
Conversation
Refactor frequency calculations for RoPE (YaRN) scaling and correct range finding
Summary of ChangesHello @Liberatedwinner, 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 addresses critical mathematical inaccuracies in the YaRN RoPE frequency scaling implementation. By aligning the formulas for frequency calculation and correction range determination with the original YaRN paper and a verified Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
There was a problem hiding this 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 correctly aligns the YaRN RoPE frequency scaling formula with the original paper. The changes to remove floor/ceil operations, adjust the frequency calculation to apply scaling linearly, and use the correct dimension range for threshold calculation are all well-justified and improve the implementation's accuracy. I've pointed out a minor syntax error in one of the changes. Overall, this is a great correction.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
Hello, @MasterJH5574 . I would like to gently bump this PR as it has been a week. It seems the CI workflows are currently pending approval. Thank you for your help! |
Summary
Fixed frequency calculations for RoPE (YaRN) scaling and correct range finding.
Description
Greetings:
This PR corrects the mathematical formulation of the YaRN RoPE scaling.
I have verified that this change eliminates the discrepancy observed when comparing against PyTorch baseline (an implementation of
gpt-oss).in
yarn_find_correction_range()low,highRemoved
tir.floorandtir.ceiloperations inyarn_find_correction_dim().In YaRN paper, there is no floor or ceil function within calculations of those values.
In
gpt-oss, the implementation uses floating-point values for these thresholds to ensure smooth interpolation in the ramp function.Rounding them caused quantization errors in the ramp mask.
in
rope_freq_yarn()freq_interCurrently, the implementation calculates the inverse frequency as:
This implies
scaleis also affected by the exponent, leading to non-uniform scaling across dimensions.According to the YaRN method (and an implementation of
gpt-oss), the scaling factor should be applied linearly:d_rangeThe
yarn_find_correction_range()function was incorrectly using the current dimension indexdto calculate thresholds.This caused the ramp boundaries to shift dynamically per dimension.
It has been corrected to use the total dimension size (
d_range) to ensure consistent frequency thresholds.Before:
After:
Thank you very much for reading.