leejet / stable-diffusion.cpp

Stable Diffusion and Flux in pure C/C++
MIT License
3.31k stars 279 forks source link

txt2img can not be called multiple times. #238

Open chinshou opened 5 months ago

chinshou commented 5 months ago

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 commented 5 months ago

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.

Windsander commented 5 months ago

;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.

chinshou commented 5 months ago

;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.

leejet commented 5 months ago

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