stable-diffusion-webui
stable-diffusion-webui copied to clipboard
[Bug]: Memory Leak using --medvram
Is there an existing issue for this?
- [X] I have searched the existing issues and checked the recent builds/commits
What happened?
When switching out a model using --medvram the old model stays in memory, this doesn't happen without the flag (it might happen with the --lowvram flag too but ihaven't tested it)
Steps to reproduce the problem
- Start a resource monitor and track the memory ussage of the webui
- Start the webui with
--medvram - Switch out the model in the webui
- Watch the memory usage climb
What should have happened?
The memory usage should not change by much when loading a new model (the old one should be unloaded)
Commit where the problem happens
44c46f0ed395967cd3830dd481a2db759fda5b3b
What platforms do you use to access UI ?
Linux
What browsers do you use to access the UI ?
Mozilla Firefox, Google Chrome
Command Line Arguments
No response
Additional information, context and logs
No response
Checkpoints that use the same yaml file just load the new weights, so these won't have a leak.
Checkpoints that use different yaml file require a new model instance, so it is possible to have a leak if something keeps a reference to the old model instance.
The basic features have been checked (by me) to avoid keeping a reference of the model instance, but other features, scripts or extensions may be (and some probably are) keeping a reference of the model instance.
Solving this model instance reference problem in the whole code is a huge task, I solved some of those references but it is not like I am been payed for it, so I just made the code work for my needs. Others after me did the same and solved other parts to make the code work for their needs.
About the medvram/lowvram there was a leak that I solved a month ago, after that it was modified just to enable the SDv2.
What models are you switching from and to?
What did you do before switching between models? Did you used some script or extension?
I think I was switching between robo-diffussion and inkpunk-diffusion (both converted to safetensors), Just by switching models you could see the memory usage go up by 3-4 GB. The only script I was using was the X/Y grid one.
these models are 1.5 or 2.x?
robo-diffussion and inkpunk-diffusion
cause i didn't notice big ram leaks when using 2.x models
I think I was switching between robo-diffussion and inkpunk-diffusion (both converted to safetensors), Just by switching models you could see the memory usage go up by 3-4 GB. The only script I was using was the X/Y grid one.
The x/y grid causes a leak if you try to switch between models that use a different yaml file, I tried to fix it a month ago when I fixed the other leaks, but I wasn't able to fix it :(
duplicate of https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/2858