From 5b0149d6aaf59b8e41e5aad3e89ad785e0df5fdb Mon Sep 17 00:00:00 2001 From: "Sabnis, Omkar" Date: Wed, 4 Nov 2026 12:28:02 -0800 Subject: [PATCH] ggml-openvino: correct the RESHAPE dynamic-dim comment for size-1 dims The comment above the RESHAPE stride match in compute_node_dynamic_dims() still said the match is unambiguous because result strides are strictly monotone. A size-1 dim has the same stride as the dim after it ([head_dim, T] -> [head_dim, 1, T] with one KV head), so it is not. Explain the size-1 case in the block comment, drop the duplicate comment inside the loop, and name the source dim's size once. --- ggml/src/ggml-openvino/ggml-decoder.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ggml/src/ggml-openvino/ggml-decoder.cpp b/ggml/src/ggml-openvino/ggml-decoder.cpp index 332a17f89ff3..1bf97ba9f2ca 100644 --- a/ggml/src/ggml-openvino/ggml-decoder.cpp +++ b/ggml/src/ggml-openvino/ggml-decoder.cpp @@ -2717,14 +2717,15 @@ void GgmlOvDecoder::compute_node_dynamic_dims() { // have standard compact strides: nb[i] = type_size * prod(ne[0..i-1]). // Match src->nb[dynamic_dim] against result->nb[i] to find the output // dimension whose flat-memory boundary aligns with the source dynamic - // boundary. This is unambiguous (result strides are strictly monotone) - // and handles merged-lower-dim cases that ne-value matching misses. + // boundary. This handles merged-lower-dim cases that ne-value matching + // misses. A size-1 dim has the same stride as the dim after it + // ([head_dim, T] -> [head_dim, 1, T] with one KV head), so prefer the + // matching dim that also has the source dim's size. m_node_dynamic_dims[node] = -1; if (m_node_dynamic_dims[node->src[0]] != -1) { auto dynamic_dim_idx = m_node_dynamic_dims[node->src[0]]; + auto dynamic_dim_value = node->src[0]->ne[dynamic_dim_idx]; auto dynamic_dim_stride = node->src[0]->nb[dynamic_dim_idx]; - // Size-1 dims repeat a stride (e.g. a single KV head in [head_size, 1, n_tokens]), so prefer - // the match that keeps the dynamic size and fall back to the first stride match. for (int i = 0; i < GGML_MAX_DIMS; i++) { if (node->nb[i] != dynamic_dim_stride) { continue; @@ -2732,7 +2733,7 @@ void GgmlOvDecoder::compute_node_dynamic_dims() { if (m_node_dynamic_dims[node] == -1) { m_node_dynamic_dims[node] = i; } - if (node->ne[i] == node->src[0]->ne[dynamic_dim_idx]) { + if (node->ne[i] == dynamic_dim_value) { m_node_dynamic_dims[node] = i; break; }