Skip to content

Commit 6d6dc1b

Browse files
authored
fix: make PhotoMakerV2 more robust by image count check (#970)
1 parent 199e675 commit 6d6dc1b

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

stable-diffusion.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,18 +2660,24 @@ sd_image_t* generate_image_internal(sd_ctx_t* sd_ctx,
26602660
LOG_WARN("Turn off PhotoMaker");
26612661
sd_ctx->sd->stacked_id = false;
26622662
} else {
2663-
id_cond.c_crossattn = sd_ctx->sd->id_encoder(work_ctx, init_img, id_cond.c_crossattn, id_embeds, class_tokens_mask);
2664-
int64_t t1 = ggml_time_ms();
2665-
LOG_INFO("Photomaker ID Stacking, taking %" PRId64 " ms", t1 - t0);
2666-
if (sd_ctx->sd->free_params_immediately) {
2667-
sd_ctx->sd->pmid_model->free_params_buffer();
2668-
}
2669-
// Encode input prompt without the trigger word for delayed conditioning
2670-
prompt_text_only = sd_ctx->sd->cond_stage_model->remove_trigger_from_prompt(work_ctx, prompt);
2671-
// printf("%s || %s \n", prompt.c_str(), prompt_text_only.c_str());
2672-
prompt = prompt_text_only; //
2673-
if (sample_steps < 50) {
2674-
LOG_WARN("It's recommended to use >= 50 steps for photo maker!");
2663+
if (pm_params.id_images_count != id_embeds->ne[1]) {
2664+
LOG_WARN("PhotoMaker image count (%d) does NOT match ID embeds (%d). You should run face_detect.py again.", pm_params.id_images_count, id_embeds->ne[1]);
2665+
LOG_WARN("Turn off PhotoMaker");
2666+
sd_ctx->sd->stacked_id = false;
2667+
} else {
2668+
id_cond.c_crossattn = sd_ctx->sd->id_encoder(work_ctx, init_img, id_cond.c_crossattn, id_embeds, class_tokens_mask);
2669+
int64_t t1 = ggml_time_ms();
2670+
LOG_INFO("Photomaker ID Stacking, taking %" PRId64 " ms", t1 - t0);
2671+
if (sd_ctx->sd->free_params_immediately) {
2672+
sd_ctx->sd->pmid_model->free_params_buffer();
2673+
}
2674+
// Encode input prompt without the trigger word for delayed conditioning
2675+
prompt_text_only = sd_ctx->sd->cond_stage_model->remove_trigger_from_prompt(work_ctx, prompt);
2676+
// printf("%s || %s \n", prompt.c_str(), prompt_text_only.c_str());
2677+
prompt = prompt_text_only; //
2678+
if (sample_steps < 50) {
2679+
LOG_WARN("It's recommended to use >= 50 steps for photo maker!");
2680+
}
26752681
}
26762682
}
26772683
} else {

0 commit comments

Comments
 (0)