Skip to content

Commit 0fa3e1a

Browse files
authored
fix: prevent core dump in PM V2 in case of incomplete cmd line (#950)
1 parent c2d8ffc commit 0fa3e1a

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

docs/photo_maker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ Running PMV2 is now a two-step process:
4040
```
4141
python face_detect.py input_image_dir
4242
```
43-
An ```id_embeds.safetensors``` file will be generated in ```input_images_dir```
43+
An ```id_embeds.bin``` file will be generated in ```input_images_dir```
4444

4545
**Note: this step is only needed to run once; the same ```id_embeds``` can be reused**
4646

4747
- Run the same command as in version 1 but replacing ```photomaker-v1.safetensors``` with ```photomaker-v2.safetensors```.
4848

4949
You can download ```photomaker-v2.safetensors``` from [here](https://huggingface.co/bssrdf/PhotoMakerV2)
5050

51-
- All the command line parameters from Version 1 remain the same for Version 2
51+
- All the command line parameters from Version 1 remain the same for Version 2 plus one extra pointing to a valid ```id_embeds``` file: --pm-id-embed-path [path_to__id_embeds.bin]
5252

5353

stable-diffusion.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,18 +2222,24 @@ sd_image_t* generate_image_internal(sd_ctx_t* sd_ctx,
22222222
id_embeds = load_tensor_from_file(work_ctx, pm_params.id_embed_path);
22232223
// print_ggml_tensor(id_embeds, true, "id_embeds:");
22242224
}
2225-
id_cond.c_crossattn = sd_ctx->sd->id_encoder(work_ctx, init_img, id_cond.c_crossattn, id_embeds, class_tokens_mask);
2226-
int64_t t1 = ggml_time_ms();
2227-
LOG_INFO("Photomaker ID Stacking, taking %" PRId64 " ms", t1 - t0);
2228-
if (sd_ctx->sd->free_params_immediately) {
2229-
sd_ctx->sd->pmid_model->free_params_buffer();
2230-
}
2231-
// Encode input prompt without the trigger word for delayed conditioning
2232-
prompt_text_only = sd_ctx->sd->cond_stage_model->remove_trigger_from_prompt(work_ctx, prompt);
2233-
// printf("%s || %s \n", prompt.c_str(), prompt_text_only.c_str());
2234-
prompt = prompt_text_only; //
2235-
if (sample_steps < 50) {
2236-
LOG_WARN("It's recommended to use >= 50 steps for photo maker!");
2225+
if (pmv2 && id_embeds == nullptr) {
2226+
LOG_WARN("Provided PhotoMaker images, but NO valid ID embeds file for PM v2");
2227+
LOG_WARN("Turn off PhotoMaker");
2228+
sd_ctx->sd->stacked_id = false;
2229+
} else {
2230+
id_cond.c_crossattn = sd_ctx->sd->id_encoder(work_ctx, init_img, id_cond.c_crossattn, id_embeds, class_tokens_mask);
2231+
int64_t t1 = ggml_time_ms();
2232+
LOG_INFO("Photomaker ID Stacking, taking %" PRId64 " ms", t1 - t0);
2233+
if (sd_ctx->sd->free_params_immediately) {
2234+
sd_ctx->sd->pmid_model->free_params_buffer();
2235+
}
2236+
// Encode input prompt without the trigger word for delayed conditioning
2237+
prompt_text_only = sd_ctx->sd->cond_stage_model->remove_trigger_from_prompt(work_ctx, prompt);
2238+
// printf("%s || %s \n", prompt.c_str(), prompt_text_only.c_str());
2239+
prompt = prompt_text_only; //
2240+
if (sample_steps < 50) {
2241+
LOG_WARN("It's recommended to use >= 50 steps for photo maker!");
2242+
}
22372243
}
22382244
} else {
22392245
LOG_WARN("Provided PhotoMaker model file, but NO input ID images");

0 commit comments

Comments
 (0)