Skip to content

Commit 59080d3

Browse files
authored
feat: change image dimensions requirement for DiT models (#742)
1 parent 8c3c788 commit 59080d3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

examples/cli/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,13 @@ void parse_args(int argc, const char** argv, SDParams& params) {
596596
exit(1);
597597
}
598598

599-
if (params.width <= 0 || params.width % 64 != 0) {
600-
fprintf(stderr, "error: the width must be a multiple of 64\n");
599+
if (params.width <= 0) {
600+
fprintf(stderr, "error: the width must be greater than 0\n");
601601
exit(1);
602602
}
603603

604-
if (params.height <= 0 || params.height % 64 != 0) {
605-
fprintf(stderr, "error: the height must be a multiple of 64\n");
604+
if (params.height <= 0) {
605+
fprintf(stderr, "error: the height must be greater than 0\n");
606606
exit(1);
607607
}
608608

stable-diffusion.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,15 @@ ggml_tensor* generate_init_latent(sd_ctx_t* sd_ctx,
18751875
sd_image_t* generate_image(sd_ctx_t* sd_ctx, const sd_img_gen_params_t* sd_img_gen_params) {
18761876
int width = sd_img_gen_params->width;
18771877
int height = sd_img_gen_params->height;
1878+
if (sd_version_is_dit(sd_ctx->sd->version)) {
1879+
if (width % 16 || height % 16) {
1880+
LOG_ERROR("Image dimensions must be must be a multiple of 16 on each axis for %s models. (Got %dx%d)", model_version_to_str[sd_ctx->sd->version], width, height);
1881+
return NULL;
1882+
}
1883+
} else if (width % 64 || height % 64) {
1884+
LOG_ERROR("Image dimensions must be must be a multiple of 64 on each axis for %s models. (Got %dx%d)", model_version_to_str[sd_ctx->sd->version], width, height);
1885+
return NULL;
1886+
}
18781887
LOG_DEBUG("generate_image %dx%d", width, height);
18791888
if (sd_ctx == NULL || sd_img_gen_params == NULL) {
18801889
return NULL;

0 commit comments

Comments
 (0)