| 5027 | // ggml_rope |
| 5028 | |
| 5029 | static struct ggml_tensor * ggml_rope_impl( |
| 5030 | struct ggml_context * ctx, |
| 5031 | struct ggml_tensor * a, |
| 5032 | struct ggml_tensor * b, |
| 5033 | int n_dims, |
| 5034 | int mode, |
| 5035 | int n_ctx, |
| 5036 | int n_orig_ctx, |
| 5037 | float freq_base, |
| 5038 | float freq_scale, |
| 5039 | float ext_factor, |
| 5040 | float attn_factor, |
| 5041 | float beta_fast, |
| 5042 | float beta_slow, |
| 5043 | float xpos_base, |
| 5044 | bool xpos_down, |
| 5045 | bool inplace) { |
| 5046 | GGML_ASSERT(ggml_is_vector(b)); |
| 5047 | GGML_ASSERT(b->type == GGML_TYPE_I32); |
| 5048 | GGML_ASSERT(a->ne[2] == b->ne[0]); |
| 5049 | |
| 5050 | bool is_node = false; |
| 5051 | |
| 5052 | if (a->grad) { |
| 5053 | is_node = true; |
| 5054 | } |
| 5055 | |
| 5056 | struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a); |
| 5057 | |
| 5058 | int32_t params[13] = { /*n_past*/ 0, n_dims, mode, n_ctx, n_orig_ctx }; |
| 5059 | memcpy(params + 5, &freq_base, sizeof(float)); |
| 5060 | memcpy(params + 6, &freq_scale, sizeof(float)); |
| 5061 | memcpy(params + 7, &ext_factor, sizeof(float)); |
| 5062 | memcpy(params + 8, &attn_factor, sizeof(float)); |
| 5063 | memcpy(params + 9, &beta_fast, sizeof(float)); |
| 5064 | memcpy(params + 10, &beta_slow, sizeof(float)); |
| 5065 | memcpy(params + 11, &xpos_base, sizeof(float)); |
| 5066 | memcpy(params + 12, &xpos_down, sizeof(bool)); |
| 5067 | ggml_set_op_params(result, params, sizeof(params)); |
| 5068 | |
| 5069 | result->op = GGML_OP_ROPE; |
| 5070 | result->grad = is_node ? ggml_dup_tensor(ctx, result) : NULL; |
| 5071 | result->src[0] = a; |
| 5072 | result->src[1] = b; |
| 5073 | |
| 5074 | return result; |
| 5075 | } |
| 5076 | |
| 5077 | struct ggml_tensor * ggml_rope( |
| 5078 | struct ggml_context * ctx, |
no test coverage detected