fix: preserve singleton output dimension when merging LoRA (#2116)

This commit is contained in:
leejet
2026-10-10 01:12:03 +08:00
committed by GitHub
parent 7867f6da4a
commit f2f168fa70
+3 -1
View File
@@ -11,7 +11,9 @@ ggml_tensor* ggml_ext_merge_lora(ggml_context* ctx,
ggml_tensor* lora_mid) {
ggml_tensor* updown;
// flat lora tensors to multiply it
int64_t lora_up_rows = lora_up->ne[ggml_n_dims(lora_up) - 1];
// ggml_n_dims drops the output dimension when a linear layer has one output.
int lora_up_n_dims = ggml_n_dims(lora_up);
int64_t lora_up_rows = lora_up_n_dims == 1 ? 1 : lora_up->ne[lora_up_n_dims - 1];
lora_up = ggml_reshape_2d(ctx, lora_up, ggml_nelements(lora_up) / lora_up_rows, lora_up_rows);
auto lora_down_n_dims = ggml_n_dims(lora_down);
// assume n_dims should always be a multiple of 2 (otherwise rank 1 doesn't work)