leejet / stable-diffusion.cpp

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

Can not release memory #141

Open wuxianjun666 opened 10 months ago

wuxianjun666 commented 10 months ago

in ggml_extend.hpp, the destructor function ~GGMLModule(), ~GGMLModule() noexcept(false){ LOG_DEBUG("BEGIN TO SUPER RELEASE ........."); free_params_buffer(); LOG_DEBUG("SUPER RELEASE FINISHED........."); }
It always gets stuck here. because of this function: free_params_buffer(); there ara many things succeed GGMLModule(), such as LoraModel, AutoEncoderKL, UNetModel, FrozenCLIPEmbedderWithCustomWords

wuxianjun666 commented 10 months ago

image can not delete sd_ctx->sd; when delete sd_ctx->sd, it should delete GGMLModule many times, because there are many struct succeed GGMLModule, image but always gets stuck here, image

leejet commented 10 months ago

Can you provide more information, such as the operating system you're using, the compiler version, the command-line arguments you're using, and the corresponding output?

wuxianjun666 commented 10 months ago

Can you provide more information, such as the operating system you're using, the compiler version, the command-line arguments you're using, and the corresponding output?

I run in windows10, and the command is "cmake .. and cmake --build ." the output is:

Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe

Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6/bin/nvcc.exe

the error happened in when i finished generate image and save it, it begin to delete ctx->sd, but the program gets stuck. The stuck position is in the function ~GGMLModule(), because the unet, vae, clip all succeed the struct GGMLModule, so the function ~GGMLModule() will run many time. so i add some print in the function "void free_params_buffer()" when run the code "LOG_DEBUG("params_ctx != NULL, BEGIN TO free .........");" the program gets stuck. there is the screenshot

image

image

wuxianjun666 commented 10 months ago

Can you provide more information, such as the operating system you're using, the compiler version, the command-line arguments you're using, and the corresponding output?

So I had to eliminate this function so it would run fine and not get stuck.

image

image

snowyu commented 9 months ago

Also this error occurs on Ubuntu 22.04.3 whenever Lora is used.

build/bin/sd -m models/Stable-diffusion/v1-5-pruned-emaonly.safetensors  --lora-model-dir models/Lora -v  -p "a cute cat<lora:lcm-lora-sdv1-5:1>" --cfg-scale 1 --steps 4
[DEBUG] ggml_extend.hpp:601  - unet compute buffer size: 560.71 MB
  |==================================================| 4/4 - 2.54s/it
[INFO ] stable-diffusion.cpp:1247 - sampling completed, taking 11.80s
[INFO ] stable-diffusion.cpp:1255 - generating 1 latent images completed, taking 11.94s
[INFO ] stable-diffusion.cpp:1257 - decoding 1 latents
[DEBUG] ggml_extend.hpp:601  - vae compute buffer size: 1665.00 MB
[DEBUG] stable-diffusion.cpp:1076 - computing vae [mode: DECODE] graph completed, taking 8.78s
[INFO ] stable-diffusion.cpp:1267 - latent 1 decoded, taking 8.78s
[INFO ] stable-diffusion.cpp:1271 - decode_first_stage completed, taking 8.78s
[INFO ] stable-diffusion.cpp:1288 - txt2img completed in 20.78s
save result image to 'output.png'
Segment fault(core dumped)
wuxianjun666 commented 9 months ago

yes,when i do not use lora, it is normal

wuxianjun666 commented 9 months ago

I found out what the problem is, in lora.hpp, comment out(注释) this line of code and it works! image