| 3190 | // ggml_add_cast |
| 3191 | |
| 3192 | static struct ggml_tensor * ggml_add_cast_impl( |
| 3193 | struct ggml_context * ctx, |
| 3194 | struct ggml_tensor * a, |
| 3195 | struct ggml_tensor * b, |
| 3196 | enum ggml_type type) { |
| 3197 | // TODO: support less-strict constraint |
| 3198 | // GGML_ASSERT(ggml_can_repeat(b, a)); |
| 3199 | GGML_ASSERT(ggml_can_repeat_rows(b, a)); |
| 3200 | GGML_ASSERT(ggml_is_quantized(a->type) || a->type == GGML_TYPE_F16); // currently only supported for quantized input and f16 |
| 3201 | |
| 3202 | bool is_node = false; |
| 3203 | |
| 3204 | if (a->grad || b->grad) { |
| 3205 | // TODO: support backward pass for broadcasting |
| 3206 | GGML_ASSERT(ggml_are_same_shape(a, b)); |
| 3207 | is_node = true; |
| 3208 | } |
| 3209 | |
| 3210 | struct ggml_tensor * result = ggml_new_tensor(ctx, type, a->n_dims, a->ne); |
| 3211 | |
| 3212 | result->op = GGML_OP_ADD; |
| 3213 | result->grad = is_node ? ggml_new_tensor(ctx, GGML_TYPE_F32, a->n_dims, a->ne) : NULL; |
| 3214 | result->src[0] = a; |
| 3215 | result->src[1] = b; |
| 3216 | |
| 3217 | return result; |
| 3218 | } |
| 3219 | |
| 3220 | static struct ggml_tensor * ggml_add_idx_impl( |
| 3221 | struct ggml_context * ctx, |
no test coverage detected