Commit 9578bd3fe for llama.cpp
commit 9578bd3fe48b793cf193c2e4615ec2f24a2ea92a
Author: Aman Gupta <amangupta052@gmail.com>
Date: Tue Nov 24 20:48:02 2026 +0800
CUDA: ignore strides of size-1 dims in bin_bcast (#32854)
After collapsing contiguous dims, the stride of a trailing dim of size 1
becomes the size of the whole tensor. Its index is always 0, but the
uint32 stride asserts still fire once the tensor has more than 2^32
elements, e.g. the per-head relative-position mask add of inkling2 at
n_kv > ~87k with -ub 2048.
Fixes #32804
Assisted-by: Claude Opus 5.5
diff --git a/ggml/src/ggml-cuda/binbcast.cu b/ggml/src/ggml-cuda/binbcast.cu
index f7c3a7322..7e1c5c300 100644
--- a/ggml/src/ggml-cuda/binbcast.cu
+++ b/ggml/src/ggml-cuda/binbcast.cu
@@ -256,6 +256,18 @@ static void launch_bin_bcast_pack(const ggml_tensor * src0, const ggml_tensor *
size_t s02 = nb02 / sizeof(src0_t);
size_t s03 = nb03 / sizeof(src0_t);
+ // the index of a dim of size 1 is always 0, so its stride is never applied,
+ // but after collapsing contiguous dims it can be the whole tensor size and exceed 32 bits
+ if (cne0[1] == 1) { s01 = 0; }
+ if (cne0[2] == 1) { s02 = 0; }
+ if (cne0[3] == 1) { s03 = 0; }
+ if (cne1[1] == 1) { s11 = 0; }
+ if (cne1[2] == 1) { s12 = 0; }
+ if (cne1[3] == 1) { s13 = 0; }
+ if (ne1 == 1) { s1 = 0; }
+ if (ne2 == 1) { s2 = 0; }
+ if (ne3 == 1) { s3 = 0; }
+
GGML_ASSERT(ne0 <= std::numeric_limits<uint32_t>::max());
GGML_ASSERT(ne1 <= std::numeric_limits<uint32_t>::max());
GGML_ASSERT(ne2 <= std::numeric_limits<uint32_t>::max());