From b15dd9bbce525ee9b1775a3e4fa69c404de68233 Mon Sep 17 00:00:00 2001 From: Piotr Wilkin Date: Tue, 27 Oct 2026 11:55:43 +0100 Subject: [PATCH] moss-image : view qkv slices instead of slice+reshape The qkv projections were split with ggml_ext_slice followed by ggml_reshape_4d, which materialised a copy of each slice. A ggml_view_4d over the fused qkv tensor reads the same elements in place. Together with the ggml submodule bump this takes 50-step 1024x1024 sampling from 379.49 s to 356.12 s (-6.16%) with byte-identical output. --- ggml | 2 +- src/model/diffusion/moss_image.hpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ggml b/ggml index a5915eb0e4..de86b954e8 160000 --- a/ggml +++ b/ggml @@ -1 +1 @@ -Subproject commit a5915eb0e47adef21c3f25b889a008925ea838c2 +Subproject commit de86b954e8f74b9c5f0829c4b9955fcaa17e2426 diff --git a/src/model/diffusion/moss_image.hpp b/src/model/diffusion/moss_image.hpp index f1cbbc7f37..c3807de1c1 100644 --- a/src/model/diffusion/moss_image.hpp +++ b/src/model/diffusion/moss_image.hpp @@ -83,7 +83,8 @@ namespace MOSSImage { auto y = norm("norm1", x); auto qkv = linear("qkv", y); auto split = [&](int i) { - return ggml_reshape_4d(c, ggml_ext_slice(c, qkv, 0, i * config.dim, (i + 1) * config.dim), config.head_dim, config.dim / config.head_dim, x->ne[1], x->ne[2]); + // q/k feed rms_norm and v a permuted copy, which read these strided views in place. + return ggml_view_4d(c, qkv, config.head_dim, config.dim / config.head_dim, x->ne[1], x->ne[2], config.head_dim * qkv->nb[0], qkv->nb[1], qkv->nb[2], i * config.dim * qkv->nb[0]); }; auto q = norm("q_norm", split(0)); auto k = norm("k_norm", split(1)); @@ -122,7 +123,8 @@ namespace MOSSImage { y = ggml_add(c, ggml_add(c, y, ggml_mul(c, y, part(1))), part(0)); auto qkv = linear("proj.qkv", y); auto split = [&](int i) { - return ggml_reshape_4d(c, ggml_ext_slice(c, qkv, 0, i * config.dim, (i + 1) * config.dim), config.head_dim, config.dim / config.head_dim, x->ne[1], x->ne[2]); + // q/k feed rms_norm and v a permuted copy, which read these strided views in place. + return ggml_view_4d(c, qkv, config.head_dim, config.dim / config.head_dim, x->ne[1], x->ne[2], config.head_dim * qkv->nb[0], qkv->nb[1], qkv->nb[2], i * config.dim * qkv->nb[0]); }; auto q = norm("q_norm", split(0)); auto k = norm("k_norm", split(1));