stable-diffusion.cpp icon indicating copy to clipboard operation
stable-diffusion.cpp copied to clipboard

txt2img can not be called multiple times.

Open chinshou opened this issue 10 months ago • 4 comments

txt2img can not be called multiple times. when calling txt2img the second time it will crash at following line

cond_stage_model->compute(n_threads, input_ids, input_ids2, max_token_idx, false, &chunk_hidden_states, work_ctx);

I suspect there is some resource not freed after the first time txt2img call.

If I call free_sd_ctx and new_sd_ctx again then I can call the txt2img again. But it is obviously not reasonble because new_sd_ctx is very slow and time-consuming that need to load the model again.

chinshou avatar Apr 23 '24 18:04 chinshou

I found the crash caused by free_params_immediately=true when calling new_sd_ctx. So I assume we should check this param when user call the txt2img multiple times. Or point out the problem in the api document.

chinshou avatar Apr 24 '24 20:04 chinshou

;p you can try this commits branch:

https://github.com/leejet/stable-diffusion.cpp/pull/236

I think it already fixed early, which currently is working on svd-xt heavy output check & waiting accept.

Windsander avatar Apr 25 '24 04:04 Windsander

;p you can try this commits branch:

#236

I think it already fixed early, which currently is working on svd-xt heavy output check & waiting accept.

Thanks for your patch. Because I have some trouble to compile the cuda dll. It is too slow to test with cpu only dll. I will hold on until maintainer accept your merge. No rush for the patch.

chinshou avatar Apr 25 '24 05:04 chinshou

If you wish to generate images multiple times, simply set "free_params_immediately" to false.

leejet avatar Apr 29 '24 14:04 leejet