-
-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Fix error in Dynamic NTK scaling #41277
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
Changes from all commits
5a376ea
a0e54dd
d22b844
021e6c1
37bc16e
d4d3d0f
fbf8949
2c7f105
4a9d75b
7b37831
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -38,12 +38,14 @@ def __init__( | |||
| head_size: int, | ||||
| rotary_dim: int, | ||||
| max_position_embeddings: int, | ||||
| max_trained_positions: int, | ||||
| base: float, | ||||
| is_neox_style: bool, | ||||
| scaling_factor: float, | ||||
| dtype: torch.dtype, | ||||
| ) -> None: | ||||
| self.scaling_factor = scaling_factor | ||||
| self.max_trained_positions = max_trained_positions | ||||
| super().__init__( | ||||
| head_size, rotary_dim, max_position_embeddings, base, is_neox_style, dtype | ||||
| ) | ||||
|
|
@@ -53,13 +55,16 @@ def _compute_cos_sin_cache(self) -> torch.Tensor: | |||
| # maximum length before applying the rope scaling. | ||||
| # Thus, the maximum length after applying the rope scaling is | ||||
| # self.max_position_embeddings * self.scaling_factor. | ||||
| max_len = self.max_position_embeddings * self.scaling_factor | ||||
| base = self.base * ( | ||||
| (self.scaling_factor * max_len / self.max_position_embeddings) | ||||
| ( | ||||
| self.scaling_factor | ||||
| * self.max_position_embeddings | ||||
| / self.max_trained_positions | ||||
| ) | ||||
| - (self.scaling_factor - 1) | ||||
| ) ** (self.rotary_dim / (self.rotary_dim - 2)) | ||||
| inv_freq = self._compute_inv_freq(base) | ||||
| t = torch.arange(max_len, dtype=torch.float) | ||||
| t = torch.arange(self.max_position_embeddings, dtype=torch.float) | ||||
|
|
||||
|
Comment on lines
57
to
68
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @tjtanaa @WoosukKwon @mgoin @Isotr0py Could you please help double-check this?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @vadiklyutiy Could you please help double-check this? CODEOWNERS for rotary_embedding have not been updated. Line 13 in ef34592
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @noooop the fix looks good to me. Nice to see example above with embeddings comparison of sentence-transformers and vllm. @maxdebayser @noooop maybe it makes sense to add it as a test? As far as i see current max len test only checks for correct config? For example, for ColBERT models we were adding tests that compared HF embeddings are equal to vllm embeddings. UPD: i see there does exists a test for embeds comparison. Din't see yet whether it tests it with extended context.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hello @mgoin
These code changes date back to September 2023. Can we safely land this PR, or should we have more people double-check it?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this change makes a lot of sense and I appreciate Max's justification, I'm good with landing it. |
||||
| freqs = torch.einsum("i,j -> ij", t, inv_freq) | ||||
| cos = freqs.cos() | ||||
|
|
||||

Uh oh!
There was an error while loading. Please reload this page.