Skip to content

Commit

Permalink
SD3: fixed padding with negative size
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Jan 11, 2025
1 parent fb7c4d7 commit 4c7de37
Show file tree
Hide file tree
Showing 2 changed files with 13 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
4 changes: 4 additions & 0 deletions tools/who_what_benchmark/tests/test_cli_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def test_image_model_genai(model_id, model_type):
if ("flux" in model_id or "stable-diffusion-3" in model_id) and model_type != "text-to-image":
pytest.skip(reason="FLUX or SD3 are supported as text to image only")

if "flux" in model_id:
pytest.skip(reason="katuni4ka/tiny-random-flux contains ClipTextModel instead of T5TextModel \
as second text encoder, which is not supported by OpenVINO GenAI FLUX pipeline")

with tempfile.TemporaryDirectory() as temp_dir:
GT_FILE = os.path.join(temp_dir, "gt.csv")
MODEL_PATH = os.path.join(MODEL_CACHE, model_id.replace("/", "--"))
Expand Down

0 comments on commit 4c7de37

Please sign in to comment.