Skip to content

Commit 5c82f43

Browse files
committed
ggml-vulkan : fix padding in timestep embedding kernel
This commit fixes the zero padding for odd dimensions in the timestep embedding kernel similar to the fix that was applied to the cpu backend in Commit 9de447d ("ggml-cpu : fix padding in ggml_timestep_embedding (#15917)"). 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.
1 parent 27e8f08 commit 5c82f43

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ggml/src/ggml-vulkan/vulkan-shaders/timestep_embedding.comp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ void main() {
2424
const uint j = gl_GlobalInvocationID.x;
2525
const uint d_offset = i * p.nb1;
2626

27+
const uint half_dim = p.dim / 2;
28+
2729
if (p.dim % 2 != 0 && j == ((p.dim + 1) / 2)) {
30+
data_d[d_offset + 2 * half_dim] = 0.f;
2831
data_d[d_offset + p.dim] = 0.f;
2932
}
3033

31-
const uint half_dim = p.dim / 2;
3234
if (j >= half_dim) {
3335
return;
3436
}

0 commit comments

Comments
 (0)