From: Daniel Bevenius Date: Wed, 10 Sep 2025 15:31:40 +0000 (+0200) Subject: ggml-cpu : fix padding in ggml_timestep_embedding (#15917) X-Git-Tag: upstream/0.0.6527~85 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=9de447d94e1ae9d1a36e5a2e5bf47483352c0d9c;p=pkg%2Fggml%2Fsources%2Fllama.cpp ggml-cpu : fix padding in ggml_timestep_embedding (#15917) This commit fixes the zero padding for odd dimensions in ggml_compute_forward_timestep_embedding_f32. The motivation for this is that currently if an odd dimension is used, the padding check incorrectly uses the dimension value for indexing. For example, with dim=15: Elements 0-6 are set to cosine values Elements 7-13 are set to sine values Element 14 is left uninitialized (contains garbage) Element 15 is correctly set to zero This fix changes embed_data[dim] to embed_data[2 * half] so that element 14 (the first unused element) is properly set to zero as well as the last element. Resolves: https://github.com/ggml-org/ggml/issues/1324 --- diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp index 9adf9107..212e52ef 100644 --- a/ggml/src/ggml-cpu/ops.cpp +++ b/ggml/src/ggml-cpu/ops.cpp @@ -8598,6 +8598,7 @@ static void ggml_compute_forward_timestep_embedding_f32( embed_data[j + half] = sinf(arg); } if (dim % 2 != 0 && ith == 0) { + embed_data[2 * half] = 0.f; embed_data[dim] = 0.f; } }