MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_compute_forward_rope_f32

Function ggml_compute_forward_rope_f32

ggml.c:11163–11325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11161}
11162
11163static void ggml_compute_forward_rope_f32(
11164 const struct ggml_compute_params * params,
11165 const struct ggml_tensor * src0,
11166 const struct ggml_tensor * src1,
11167 struct ggml_tensor * dst,
11168 const bool forward) {
11169 if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
11170 return;
11171 }
11172
11173 float freq_base, freq_scale, ext_factor, attn_factor, beta_fast, beta_slow;
11174
11175 // these two only relevant for xPos RoPE:
11176 float xpos_base;
11177 bool xpos_down;
11178
11179 //const int n_past = ((int32_t *) dst->op_params)[0];
11180 const int n_dims = ((int32_t *) dst->op_params)[1];
11181 const int mode = ((int32_t *) dst->op_params)[2];
11182 const int n_ctx = ((int32_t *) dst->op_params)[3];
11183 const int n_orig_ctx = ((int32_t *) dst->op_params)[4];
11184
11185 memcpy(&freq_base, (int32_t *) dst->op_params + 5, sizeof(float));
11186 memcpy(&freq_scale, (int32_t *) dst->op_params + 6, sizeof(float));
11187 memcpy(&ext_factor, (int32_t *) dst->op_params + 7, sizeof(float));
11188 memcpy(&attn_factor, (int32_t *) dst->op_params + 8, sizeof(float));
11189 memcpy(&beta_fast, (int32_t *) dst->op_params + 9, sizeof(float));
11190 memcpy(&beta_slow, (int32_t *) dst->op_params + 10, sizeof(float));
11191 memcpy(&xpos_base, (int32_t *) dst->op_params + 11, sizeof(float));
11192 memcpy(&xpos_down, (int32_t *) dst->op_params + 12, sizeof(bool));
11193
11194 GGML_TENSOR_UNARY_OP_LOCALS
11195
11196 //printf("ne0: %d, ne1: %d, ne2: %d, ne3: %d\n", ne0, ne1, ne2, ne3);
11197 //printf("n_past = %d, ne2 = %d\n", n_past, ne2);
11198
11199 GGML_ASSERT(nb00 == sizeof(float));
11200
11201 const int ith = params->ith;
11202 const int nth = params->nth;
11203
11204 const int nr = ggml_nrows(dst);
11205
11206 GGML_ASSERT(n_dims <= ne0);
11207 GGML_ASSERT(n_dims % 2 == 0);
11208
11209 // rows per thread
11210 const int dr = (nr + nth - 1)/nth;
11211
11212 // row range for this thread
11213 const int ir0 = dr*ith;
11214 const int ir1 = MIN(ir0 + dr, nr);
11215
11216 // row index used to determine which thread to use
11217 int ir = 0;
11218
11219 const float theta_scale = powf(freq_base, -2.0f/n_dims);
11220 const float inv_ndims = -1.f/n_dims;

Callers 2

Calls 3

ggml_nrowsFunction · 0.70
ggml_rope_yarn_corr_dimsFunction · 0.70
rope_yarnFunction · 0.70

Tested by

no test coverage detected