Skip to content

Commit 7be9018

Browse files
committed
ggml-metal : 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 fb826c6 commit 7be9018

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

ggml/src/ggml-metal/ggml-metal.metal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,6 +4167,7 @@ kernel void kernel_timestep_embedding_f32(
41674167
}
41684168

41694169
if (args.dim % 2 != 0 && tpitg.x == 0) {
4170+
embed_data[2 * half_] = 0.f;
41704171
embed_data[args.dim] = 0.f;
41714172
}
41724173
}

0 commit comments

Comments
 (0)