| 301 | |
| 302 | |
| 303 | static struct ggml_cgraph * build_graph_lora( |
| 304 | struct ggml_context * ctx, |
| 305 | struct ggml_tensor * tensor, |
| 306 | struct ggml_tensor * lora_a, |
| 307 | struct ggml_tensor * lora_b, |
| 308 | float scaling |
| 309 | ) { |
| 310 | struct ggml_tensor * ab = ggml_mul_mat(ctx, lora_a, lora_b); |
| 311 | if (scaling != 1.0f) { |
| 312 | ab = ggml_scale(ctx, ab, ggml_new_f32(ctx, scaling)); |
| 313 | } |
| 314 | struct ggml_tensor * res = ggml_add_inplace(ctx, tensor, ab); |
| 315 | |
| 316 | struct ggml_cgraph * gf = ggml_new_graph(ctx); |
| 317 | ggml_build_forward_expand (gf, res); |
| 318 | return gf; |
| 319 | } |
| 320 | |
| 321 | static bool apply_lora(struct ggml_tensor * tensor, struct lora_data * lora, int n_threads) { |
| 322 | if (lora->ctx == NULL) { |
no test coverage detected