| 11325 | } |
| 11326 | |
| 11327 | static void ggml_compute_forward_rope_f16( |
| 11328 | const struct ggml_compute_params * params, |
| 11329 | const struct ggml_tensor * src0, |
| 11330 | const struct ggml_tensor * src1, |
| 11331 | struct ggml_tensor * dst, |
| 11332 | const bool forward) { |
| 11333 | if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) { |
| 11334 | return; |
| 11335 | } |
| 11336 | |
| 11337 | float freq_base, freq_scale, ext_factor, attn_factor, beta_fast, beta_slow; |
| 11338 | |
| 11339 | //const int n_past = ((int32_t *) dst->op_params)[0]; |
| 11340 | const int n_dims = ((int32_t *) dst->op_params)[1]; |
| 11341 | const int mode = ((int32_t *) dst->op_params)[2]; |
| 11342 | const int n_ctx = ((int32_t *) dst->op_params)[3]; |
| 11343 | const int n_orig_ctx = ((int32_t *) dst->op_params)[4]; |
| 11344 | memcpy(&freq_base, (int32_t *) dst->op_params + 5, sizeof(float)); |
| 11345 | memcpy(&freq_scale, (int32_t *) dst->op_params + 6, sizeof(float)); |
| 11346 | memcpy(&ext_factor, (int32_t *) dst->op_params + 7, sizeof(float)); |
| 11347 | memcpy(&attn_factor, (int32_t *) dst->op_params + 8, sizeof(float)); |
| 11348 | memcpy(&beta_fast, (int32_t *) dst->op_params + 9, sizeof(float)); |
| 11349 | memcpy(&beta_slow, (int32_t *) dst->op_params + 10, sizeof(float)); |
| 11350 | |
| 11351 | GGML_TENSOR_UNARY_OP_LOCALS |
| 11352 | |
| 11353 | //printf("ne0: %d, ne1: %d, ne2: %d, ne3: %d\n", ne0, ne1, ne2, ne3); |
| 11354 | //printf("n_past = %d, ne2 = %d\n", n_past, ne2); |
| 11355 | |
| 11356 | GGML_ASSERT(nb0 == sizeof(ggml_fp16_t)); |
| 11357 | |
| 11358 | const int ith = params->ith; |
| 11359 | const int nth = params->nth; |
| 11360 | |
| 11361 | const int nr = ggml_nrows(dst); |
| 11362 | |
| 11363 | GGML_ASSERT(n_dims <= ne0); |
| 11364 | GGML_ASSERT(n_dims % 2 == 0); |
| 11365 | |
| 11366 | // rows per thread |
| 11367 | const int dr = (nr + nth - 1)/nth; |
| 11368 | |
| 11369 | // row range for this thread |
| 11370 | const int ir0 = dr*ith; |
| 11371 | const int ir1 = MIN(ir0 + dr, nr); |
| 11372 | |
| 11373 | // row index used to determine which thread to use |
| 11374 | int ir = 0; |
| 11375 | |
| 11376 | const float theta_scale = powf(freq_base, -2.0f/n_dims); |
| 11377 | const float inv_ndims = -1.f/n_dims; |
| 11378 | float corr_dims[2]; |
| 11379 | ggml_rope_yarn_corr_dims(n_dims, n_orig_ctx, freq_base, beta_fast, beta_slow, corr_dims); |
| 11380 | |
| 11381 | const bool is_neox = mode & 2; |
| 11382 | const bool is_glm = mode & 4; |
| 11383 | |
| 11384 | // backward process uses inverse rotation by cos and sin. |
no test coverage detected