| 5151 | // ggml_rope_back |
| 5152 | |
| 5153 | struct ggml_tensor * ggml_rope_back( |
| 5154 | struct ggml_context * ctx, |
| 5155 | struct ggml_tensor * a, |
| 5156 | struct ggml_tensor * b, |
| 5157 | int n_dims, |
| 5158 | int mode, |
| 5159 | int n_ctx, |
| 5160 | int n_orig_ctx, |
| 5161 | float freq_base, |
| 5162 | float freq_scale, |
| 5163 | float ext_factor, |
| 5164 | float attn_factor, |
| 5165 | float beta_fast, |
| 5166 | float beta_slow, |
| 5167 | float xpos_base, |
| 5168 | bool xpos_down) { |
| 5169 | GGML_ASSERT(ggml_is_vector(b)); |
| 5170 | GGML_ASSERT(b->type == GGML_TYPE_I32); |
| 5171 | GGML_ASSERT(a->ne[2] == b->ne[0]); |
| 5172 | |
| 5173 | GGML_ASSERT((mode & 4) == 0 && "ggml_rope_back() for ChatGLM not implemented yet"); |
| 5174 | |
| 5175 | bool is_node = false; |
| 5176 | |
| 5177 | if (a->grad) { |
| 5178 | is_node = false; // TODO: implement backward |
| 5179 | } |
| 5180 | |
| 5181 | struct ggml_tensor * result = ggml_dup_tensor(ctx, a); |
| 5182 | |
| 5183 | int32_t params[13] = { /*n_past*/ 0, n_dims, mode, n_ctx, n_orig_ctx }; |
| 5184 | memcpy(params + 5, &freq_base, sizeof(float)); |
| 5185 | memcpy(params + 6, &freq_scale, sizeof(float)); |
| 5186 | memcpy(params + 7, &ext_factor, sizeof(float)); |
| 5187 | memcpy(params + 8, &attn_factor, sizeof(float)); |
| 5188 | memcpy(params + 9, &beta_fast, sizeof(float)); |
| 5189 | memcpy(params + 10, &beta_slow, sizeof(float)); |
| 5190 | memcpy(params + 11, &xpos_base, sizeof(float)); |
| 5191 | memcpy(params + 12, &xpos_down, sizeof(bool)); |
| 5192 | ggml_set_op_params(result, params, sizeof(params)); |
| 5193 | |
| 5194 | result->op = GGML_OP_ROPE_BACK; |
| 5195 | result->grad = is_node ? ggml_dup_tensor(ctx, result) : NULL; |
| 5196 | result->src[0] = a; |
| 5197 | result->src[1] = b; |
| 5198 | |
| 5199 | return result; |
| 5200 | } |
| 5201 | |
| 5202 | // ggml_alibi |
| 5203 |
no test coverage detected