Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ggml/src/ggml-cpu/ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8599,7 +8599,6 @@ static void ggml_compute_forward_timestep_embedding_f32(
}
if (dim % 2 != 0 && ith == 0) {
embed_data[2 * half] = 0.f;
embed_data[dim] = 0.f;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions ggml/src/ggml-cuda/tsembd.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ static __global__ void timestep_embedding_f32(const float * timesteps, float * d
int j = threadIdx.x + blockIdx.x * blockDim.x;
float * embed_data = (float *)((char *)dst + i*nb1);

if (dim % 2 != 0 && j == ((dim + 1) / 2)) {
embed_data[dim] = 0.f;
int half = dim / 2;
if (dim % 2 != 0 && j == half) {
embed_data[2 * half] = 0.f;
}

int half = dim / 2;
if (j >= half) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion ggml/src/ggml-metal/ggml-metal.metal
Original file line number Diff line number Diff line change
Expand Up @@ -4167,7 +4167,7 @@ kernel void kernel_timestep_embedding_f32(
}

if (args.dim % 2 != 0 && tpitg.x == 0) {
embed_data[args.dim] = 0.f;
embed_data[2 * half_] = 0.f;
}
}

Expand Down
4 changes: 2 additions & 2 deletions ggml/src/ggml-opencl/kernels/tsembd.cl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ kernel void kernel_timestep_embedding(
local_half_dim = logical_dim / 2;
local_embed_data_ptr = (global float *)((global char *)local_dst_output_base_ptr + local_i * dst_nb1_bytes);

if (logical_dim % 2 != 0 && local_j == ((logical_dim + 1) / 2)) {
local_embed_data_ptr[logical_dim] = 0.0f;
if (logical_dim % 2 != 0 && local_j == local_half_dim) {
local_embed_data_ptr[2 * local_half_dim] = 0.0f;
}

if (local_j >= local_half_dim) {
Expand Down
7 changes: 4 additions & 3 deletions ggml/src/ggml-sycl/tsembd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ static void timestep_embedding_f32(
int j = item_ct1.get_local_id(2) + item_ct1.get_group(2) * item_ct1.get_local_range(2);
float * embed_data = (float *)((char *)dst + i*nb1);

if (dim % 2 != 0 && j == ((dim + 1) / 2)) {
embed_data[dim] = 0.f;
int half = dim / 2;

if (dim % 2 != 0 && j == half) {
embed_data[2 * half] = 0.f;
}

int half = dim / 2;
if (j >= half) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions ggml/src/ggml-vulkan/vulkan-shaders/timestep_embedding.comp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ void main() {
const uint j = gl_GlobalInvocationID.x;
const uint d_offset = i * p.nb1;

if (p.dim % 2 != 0 && j == ((p.dim + 1) / 2)) {
data_d[d_offset + p.dim] = 0.f;
const uint half_dim = p.dim / 2;

if (p.dim % 2 != 0 && j == half_dim) {
data_d[d_offset + 2 * half_dim] = 0.f;
}

const uint half_dim = p.dim / 2;
if (j >= half_dim) {
return;
}
Expand Down
6 changes: 1 addition & 5 deletions ggml/src/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -4923,12 +4923,8 @@ struct ggml_tensor * ggml_timestep_embedding(
struct ggml_tensor * timesteps,
int dim,
int max_period) {
int actual_dim = dim;
if (dim % 2 != 0) {
actual_dim = dim + 1;
}

struct ggml_tensor * result = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, actual_dim, timesteps->ne[0]);
struct ggml_tensor * result = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, dim, timesteps->ne[0]);

ggml_set_op_params_i32(result, 0, dim);
ggml_set_op_params_i32(result, 1, max_period);
Expand Down
Loading