MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / ggml_mrope_cache_init

Function ggml_mrope_cache_init

ggml/src/ggml-cpu/ops.cpp:5643–5711  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5641}
5642
5643static void ggml_mrope_cache_init(
5644 float theta_base_t, float theta_base_h, float theta_base_w, float theta_base_e, int sections[4], bool is_imrope, bool indep_sects,
5645 float freq_scale, const float * freq_factors, float corr_dims[2], int64_t ne0, float ext_factor, float mscale,
5646 float * cache, float sin_sign, float theta_scale) {
5647 // ref: https://github.com/jquesnelle/yarn/blob/master/scaled_rope/LlamaYaRNScaledRotaryEmbedding.py
5648 float theta_t = theta_base_t;
5649 float theta_h = theta_base_h;
5650 float theta_w = theta_base_w;
5651 float theta_e = theta_base_e; // extra position id for vision encoder
5652 int sect_dims = sections[0] + sections[1] + sections[2] + sections[3];
5653 int sec_w = sections[1] + sections[0];
5654 int sec_e = sections[2] + sec_w;
5655 GGML_ASSERT(sect_dims <= ne0);
5656
5657 for (int64_t i0 = 0; i0 < ne0; i0 += 2) {
5658 const float ff = freq_factors ? freq_factors[i0/2] : 1.0f;
5659
5660 int sector = (i0 / 2) % sect_dims;
5661 if (indep_sects) {
5662 // compute theta independently for each dim sections
5663 // (i.e. reset corresponding theta when `i0` go from one section to another)
5664 if (sector == 0) {
5665 theta_t = theta_base_t;
5666 }
5667 else if (sector == sections[0]) {
5668 theta_h = theta_base_h;;
5669 }
5670 else if (sector == sec_w) {
5671 theta_w = theta_base_w;
5672 }
5673 else if (sector == sec_e) {
5674 theta_e = theta_base_e;
5675 }
5676 }
5677
5678 float theta = theta_t;
5679 if (is_imrope) { // qwen3vl apply interleaved mrope
5680 if (sector % 3 == 1 && sector < 3 * sections[1]) {
5681 theta = theta_h;
5682 } else if (sector % 3 == 2 && sector < 3 * sections[2]) {
5683 theta = theta_w;
5684 } else if (sector % 3 == 0 && sector < 3 * sections[0]) {
5685 theta = theta_t;
5686 } else {
5687 theta = theta_e;
5688 }
5689 } else {
5690 if (sector >= sections[0] && sector < sec_w) {
5691 theta = theta_h;
5692 }
5693 else if (sector >= sec_w && sector < sec_w + sections[2]) {
5694 theta = theta_w;
5695 }
5696 else if (sector >= sec_w + sections[2]) {
5697 theta = theta_e;
5698 }
5699 }
5700

Callers 1

Calls 1

rope_yarnFunction · 0.70

Tested by

no test coverage detected