aboutsummaryrefslogtreecommitdiffstats
path: root/stable-diffusion.cpp-vulkan
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-28 21:21:36 +0200
committerDanilo M. <danix@danix.xyz>2026-09-28 21:21:36 +0200
commit5c08d1f69d6d110172f393ae0f9765e0fa46e5a3 (patch)
treee02555e09c746c274a4c9ba878524e560afbf6a9 /stable-diffusion.cpp-vulkan
parent293b629d7db2f1c24fac76c0c89102bdf500b7f6 (diff)
downloadmy-slackbuilds-5c08d1f69d6d110172f393ae0f9765e0fa46e5a3.tar.gz
my-slackbuilds-5c08d1f69d6d110172f393ae0f9765e0fa46e5a3.zip
stable-diffusion.cpp-vulkan: fix LoKr LoRAs on Krea2main
Runtime LoKr assumed 2D linear inputs ([q, batch]). Krea2 feeds [q, tokens, batch], so every LoKr LoRA aborted on a reshape assert at the first sampling step. Flatten the extra dims before the Kronecker split and restore the shape on output. Not upstream yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'stable-diffusion.cpp-vulkan')
-rw-r--r--stable-diffusion.cpp-vulkan/patches/lokr-nd-input.patch27
-rw-r--r--stable-diffusion.cpp-vulkan/stable-diffusion.cpp-vulkan.SlackBuild4
2 files changed, 31 insertions, 0 deletions
diff --git a/stable-diffusion.cpp-vulkan/patches/lokr-nd-input.patch b/stable-diffusion.cpp-vulkan/patches/lokr-nd-input.patch
new file mode 100644
index 0000000..6dd2d01
--- /dev/null
+++ b/stable-diffusion.cpp-vulkan/patches/lokr-nd-input.patch
@@ -0,0 +1,27 @@
+diff --git a/src/model/adapter/lora_ops.cpp b/src/model/adapter/lora_ops.cpp
+index 7dacfd1..686b8d3 100644
+--- a/src/model/adapter/lora_ops.cpp
++++ b/src/model/adapter/lora_ops.cpp
+@@ -65,6 +65,13 @@ ggml_tensor* ggml_ext_lokr_forward(
+ ggml_tensor* hb;
+
+ if (!is_conv) {
++ // Linear inputs may carry extra dims ([q, tokens, batch, ...], e.g. Krea2):
++ // flatten them into one batch dim and restore the shape on output.
++ ggml_tensor* h_in = h;
++ if (!ggml_is_contiguous(h)) {
++ h = ggml_cont(ctx, h);
++ }
++ h = ggml_reshape_2d(ctx, h, h->ne[0], ggml_nelements(h) / h->ne[0]);
+ int batch = (int)h->ne[1];
+ int merge_batch_uq = batch;
+ int merge_batch_vp = batch;
+@@ -118,7 +125,7 @@ ggml_tensor* ggml_ext_lokr_forward(
+ }
+
+ ggml_tensor* hc = ggml_transpose(ctx, hc_t);
+- ggml_tensor* out = ggml_reshape_2d(ctx, ggml_cont(ctx, hc), up * vp, batch);
++ ggml_tensor* out = ggml_reshape_4d(ctx, ggml_cont(ctx, hc), up * vp, h_in->ne[1], h_in->ne[2], h_in->ne[3]);
+ return ggml_ext_scale(ctx, out, scale);
+ } else {
+ int batch = (int)h->ne[3];
diff --git a/stable-diffusion.cpp-vulkan/stable-diffusion.cpp-vulkan.SlackBuild b/stable-diffusion.cpp-vulkan/stable-diffusion.cpp-vulkan.SlackBuild
index 450e3a8..13c16fd 100644
--- a/stable-diffusion.cpp-vulkan/stable-diffusion.cpp-vulkan.SlackBuild
+++ b/stable-diffusion.cpp-vulkan/stable-diffusion.cpp-vulkan.SlackBuild
@@ -84,6 +84,10 @@ find -L . \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
+# Runtime LoKr assumed 2D linear inputs; Krea2 feeds [q, tokens, batch]
+# and every LoKr LoRA aborted on a reshape assert. Not upstream yet.
+patch -p1 < $CWD/patches/lokr-nd-input.patch
+
# Build the server web UI offline. Every npm tarball listed in the .info
# (the linux-x64 closure of the pnpm lockfile minus typescript/vue-tsc,
# which only type-check) is unpacked into a flat node_modules; the lockfile