Skip to content

Commit

Permalink
SD3: fixed padding with negative size (#1528)
Browse files Browse the repository at this point in the history
Fix for
[yujiepan/stable-diffusion-3-tiny-random](https://huggingface.co/yujiepan/stable-diffusion-3-tiny-random)
  • Loading branch information
ilya-lavrenov authored Jan 13, 2025
1 parent b62145b commit 2adceba
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cpp/src/image_generation/stable_diffusion_3_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ void padding_right(ov::Tensor src, ov::Tensor res) {
OPENVINO_ASSERT(src_shape.size() == 3 && src_shape.size() == res_shape.size(), "Rank of tensors within 'padding_right' must be 3");
OPENVINO_ASSERT(src_shape[0] == res_shape[0] && src_shape[1] == res_shape[1], "Tensors for padding_right must have the same dimensions");

// since torch.nn.functional.pad can also perform trancation in case of negative pad size value
// we need to find minimal amoung src and res and respect it
size_t min_size = std::min(src_shape[2], res_shape[2]);

const float* src_data = src.data<const float>();
float* res_data = res.data<float>();

Expand All @@ -33,8 +37,11 @@ void padding_right(ov::Tensor src, ov::Tensor res) {
size_t offset_1 = (i * res_shape[1] + j) * res_shape[2];
size_t offset_2 = (i * src_shape[1] + j) * src_shape[2];

std::memcpy(res_data + offset_1, src_data + offset_2, src_shape[2] * sizeof(float));
std::fill_n(res_data + offset_1 + src_shape[2], res_shape[2] - src_shape[2], 0.0f);
std::memcpy(res_data + offset_1, src_data + offset_2, min_size * sizeof(float));
if (res_shape[2] > src_shape[2]) {
// peform actual padding if required
std::fill_n(res_data + offset_1 + src_shape[2], res_shape[2] - src_shape[2], 0.0f);
}
}
}
}
Expand Down

0 comments on commit 2adceba

Please sign in to comment.