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

Function ggml_rope_impl

subprojects/llama.cpp/ggml/src/ggml.c:4056–4111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4054// ggml_rope
4055
4056static struct ggml_tensor * ggml_rope_impl(
4057 struct ggml_context * ctx,
4058 struct ggml_tensor * a,
4059 struct ggml_tensor * b,
4060 struct ggml_tensor * c,
4061 int n_dims,
4062 int sections[GGML_MROPE_SECTIONS],
4063 int mode,
4064 int n_ctx_orig,
4065 float freq_base,
4066 float freq_scale,
4067 float ext_factor,
4068 float attn_factor,
4069 float beta_fast,
4070 float beta_slow,
4071 bool inplace) {
4072 GGML_ASSERT((mode & 1) == 0 && "mode & 1 == 1 is no longer supported");
4073
4074 GGML_ASSERT(ggml_is_vector(b));
4075 GGML_ASSERT(b->type == GGML_TYPE_I32);
4076
4077 bool mrope_used = mode & GGML_ROPE_TYPE_MROPE;
4078 if (mrope_used) {
4079 GGML_ASSERT(a->ne[2] * 4 == b->ne[0]); // mrope expecting 4 position ids per token
4080 } else {
4081 GGML_ASSERT(a->ne[2] == b->ne[0]);
4082 }
4083
4084 if (c) {
4085 GGML_ASSERT(c->type == GGML_TYPE_F32);
4086 GGML_ASSERT(c->ne[0] >= n_dims / 2);
4087 }
4088
4089 struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a);
4090
4091 int32_t params[15] = { /*n_past*/ 0, n_dims, mode, /*n_ctx*/ 0, n_ctx_orig };
4092 memcpy(params + 5, &freq_base, sizeof(float));
4093 memcpy(params + 6, &freq_scale, sizeof(float));
4094 memcpy(params + 7, &ext_factor, sizeof(float));
4095 memcpy(params + 8, &attn_factor, sizeof(float));
4096 memcpy(params + 9, &beta_fast, sizeof(float));
4097 memcpy(params + 10, &beta_slow, sizeof(float));
4098 if (mrope_used && sections) {
4099 memcpy(params + 11, sections, sizeof(int32_t) * GGML_MROPE_SECTIONS);
4100 } else {
4101 memset(params + 11, 0, sizeof(int32_t) * GGML_MROPE_SECTIONS);
4102 }
4103 ggml_set_op_params(result, params, sizeof(params));
4104
4105 result->op = GGML_OP_ROPE;
4106 result->src[0] = a;
4107 result->src[1] = b;
4108 result->src[2] = c;
4109
4110 return result;
4111}
4112
4113struct ggml_tensor * ggml_rope(

Callers 8

ggml_ropeFunction · 0.85
ggml_rope_multiFunction · 0.85
ggml_rope_multi_inplaceFunction · 0.85
ggml_rope_inplaceFunction · 0.85
ggml_rope_extFunction · 0.85
ggml_rope_ext_inplaceFunction · 0.85
ggml_rope_customFunction · 0.85
ggml_rope_custom_inplaceFunction · 0.85

Calls 4

ggml_is_vectorFunction · 0.85
ggml_view_tensorFunction · 0.85
ggml_dup_tensorFunction · 0.85
ggml_set_op_paramsFunction · 0.85

Tested by

no test coverage detected