Skip to content

Commit 8553862

Browse files
committed
lokr: disable "optimization" for convolutions
1 parent b486097 commit 8553862

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

ggml_extend.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,7 @@ __STATIC_INLINE__ struct ggml_tensor* ggml_ext_lokr_forward(
26832683
return ggml_scale(ctx, out, scale);
26842684

26852685
} else {
2686+
#if 0
26862687
// very slow implementation for now (can this be optimized?)
26872688
int batch = (int)h->ne[3];
26882689

@@ -2745,6 +2746,32 @@ __STATIC_INLINE__ struct ggml_tensor* ggml_ext_lokr_forward(
27452746
struct ggml_tensor* out = ggml_reshape_4d(ctx, out_cont, w_out, h_out, up * vp, batch);
27462747

27472748
return ggml_scale(ctx, out, scale);
2749+
#else
2750+
// compute the weight diff and do a single conv
2751+
if (w1 == NULL) {
2752+
w1 = ggml_ext_merge_lora(ctx, w1b, w1a);
2753+
}
2754+
if(ggml_n_dims(w1) < 4){
2755+
w1 = ggml_reshape_4d(ctx, w1, 1, 1, w1->ne[0], w1->ne[1]);
2756+
}
2757+
if (w2 == NULL) {
2758+
w2 = ggml_ext_merge_lora(ctx, w2b, w2a);
2759+
}
2760+
if(ggml_n_dims(w2) < 4){
2761+
w2 = ggml_reshape_4d(ctx, w2, 1, 1, w2->ne[0], w2->ne[1]);
2762+
}
2763+
if(w2->ne[2] * w1->ne[2] != h->ne[2]){
2764+
int k = sqrt(w2->ne[2] * w1->ne[2]/h->ne[2]);
2765+
GGML_ASSERT(k*k * h->ne[2] == w2->ne[2] * w1->ne[2]);
2766+
w2 = ggml_reshape_4d(ctx, w2, w2->ne[0]*k, w2->ne[1]*k, w2->ne[2]/(k*k), w2->ne[3]);
2767+
}
2768+
w1 = ggml_ext_cast_f32(ctx, w1);
2769+
w2 = ggml_ext_cast_f32(ctx, w2);
2770+
struct ggml_tensor* w = ggml_ext_kronecker(ctx, w1, w2);
2771+
struct ggml_tensor* out = ggml_conv_2d(ctx, w, h, conv_params.s0, conv_params.s1, conv_params.p0, conv_params.p1, conv_params.d0, conv_params.d1);
2772+
2773+
return ggml_scale(ctx, out, scale);
2774+
#endif
27482775
}
27492776
}
27502777

0 commit comments

Comments
 (0)