YaRN algorithm based on LlamaYaRNScaledRotaryEmbedding.py from https://github.com/jquesnelle/yarn MIT licensed. Copyright (c) 2023 Jeffrey Quesnelle and Bowen Peng.
| 11129 | // YaRN algorithm based on LlamaYaRNScaledRotaryEmbedding.py from https://github.com/jquesnelle/yarn |
| 11130 | // MIT licensed. Copyright (c) 2023 Jeffrey Quesnelle and Bowen Peng. |
| 11131 | static void rope_yarn( |
| 11132 | float theta_extrap, float freq_scale, float corr_dims[2], int64_t i0, float ext_factor, float mscale, |
| 11133 | float * cos_theta, float * sin_theta |
| 11134 | ) { |
| 11135 | // Get n-d rotational scaling corrected for extrapolation |
| 11136 | float theta_interp = freq_scale * theta_extrap; |
| 11137 | float theta = theta_interp; |
| 11138 | if (ext_factor != 0.0f) { |
| 11139 | float ramp_mix = rope_yarn_ramp(corr_dims[0], corr_dims[1], i0) * ext_factor; |
| 11140 | theta = theta_interp * (1 - ramp_mix) + theta_extrap * ramp_mix; |
| 11141 | |
| 11142 | // Get n-d magnitude scaling corrected for interpolation |
| 11143 | mscale *= 1.0f + 0.1f * logf(1.0f / freq_scale); |
| 11144 | } |
| 11145 | *cos_theta = cosf(theta) * mscale; |
| 11146 | *sin_theta = sinf(theta) * mscale; |
| 11147 | } |
| 11148 | |
| 11149 | // Apparently solving `n_rot = 2pi * x * base^((2 * max_pos_emb) / n_dims)` for x, we get |
| 11150 | // `corr_dim(n_rot) = n_dims * log(max_pos_emb / (n_rot * 2pi)) / (2 * log(base))` |
no test coverage detected