| 4054 | // ggml_rope |
| 4055 | |
| 4056 | static 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 | |
| 4113 | struct ggml_tensor * ggml_rope( |
no test coverage detected