MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / build_rope_shift

Method build_rope_shift

subprojects/llama.cpp/src/llama-kv-cache.cpp:1533–1576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1531}
1532
1533ggml_tensor * llama_kv_cache::build_rope_shift(
1534 const llama_cparams & cparams,
1535 ggml_context * ctx,
1536 ggml_tensor * cur,
1537 ggml_tensor * shift,
1538 ggml_tensor * factors,
1539 float freq_base,
1540 float freq_scale) const {
1541 const auto & n_ctx_orig = cparams.n_ctx_orig_yarn;
1542
1543 const auto & yarn_ext_factor = cparams.yarn_ext_factor;
1544 const auto & yarn_beta_fast = cparams.yarn_beta_fast;
1545 const auto & yarn_beta_slow = cparams.yarn_beta_slow;
1546 const auto & yarn_attn_factor = cparams.yarn_attn_factor;
1547
1548 const auto & n_rot = hparams.n_rot;
1549 const auto & rope_type = hparams.rope_type == LLAMA_ROPE_TYPE_MROPE || hparams.rope_type == LLAMA_ROPE_TYPE_IMROPE
1550 // @ngxson : this is a workaround
1551 // for M-RoPE, we want to rotate the whole vector when doing KV shift
1552 // a normal RoPE should work, we just need to use the correct ordering
1553 // ref: https://github.com/ggml-org/llama.cpp/pull/13870
1554 ? LLAMA_ROPE_TYPE_NEOX
1555 : hparams.rope_type;
1556
1557 ggml_tensor * tmp;
1558
1559 if (ggml_is_quantized(cur->type)) {
1560 // dequantize to f32 -> RoPE -> quantize back
1561 tmp = ggml_cast(ctx, cur, GGML_TYPE_F32);
1562
1563 tmp = ggml_rope_ext(ctx, tmp,
1564 shift, factors, n_rot, rope_type, n_ctx_orig, freq_base, freq_scale,
1565 yarn_ext_factor, yarn_attn_factor, yarn_beta_fast, yarn_beta_slow);
1566
1567 tmp = ggml_cpy(ctx, tmp, cur);
1568 } else {
1569 // we rotate only the first n_rot dimensions
1570 tmp = ggml_rope_ext_inplace(ctx, cur,
1571 shift, factors, n_rot, rope_type, n_ctx_orig, freq_base, freq_scale,
1572 yarn_ext_factor, yarn_attn_factor, yarn_beta_fast, yarn_beta_slow);
1573 }
1574
1575 return tmp;
1576}
1577
1578class llm_graph_input_k_shift : public llm_graph_input_i {
1579public:

Callers

nothing calls this directly

Calls 5

ggml_is_quantizedFunction · 0.85
ggml_castFunction · 0.85
ggml_rope_extFunction · 0.85
ggml_cpyFunction · 0.85
ggml_rope_ext_inplaceFunction · 0.85

Tested by

no test coverage detected