mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 01:04:32 +02:00
fix lora memory leak
This commit is contained in:
@@ -20,6 +20,7 @@ Stuff to be added...
|
||||
- Auto-test `torch.layer_norm` for FP16
|
||||
- Monitor file changes by misbehaving extensions
|
||||
- Kitchen theme: <https://github.com/canisminor1990/sd-webui-kitchen-theme>
|
||||
- Lightbox improvements
|
||||
|
||||
## Investigate
|
||||
|
||||
|
||||
@@ -260,6 +260,9 @@ def lora_apply_weights(self: Union[torch.nn.Conv2d, torch.nn.Linear, torch.nn.Mu
|
||||
If not, restores orginal weights from backup and alters weights according to loras.
|
||||
"""
|
||||
|
||||
if len(loaded_loras) == 0:
|
||||
return
|
||||
|
||||
lora_layer_name = getattr(self, 'lora_layer_name', None)
|
||||
if lora_layer_name is None:
|
||||
return
|
||||
|
||||
@@ -236,6 +236,7 @@ def read_metadata_from_safetensors(filename):
|
||||
|
||||
def read_state_dict(checkpoint_file, map_location=None): # pylint: disable=unused-argument
|
||||
try:
|
||||
pl_sd = None
|
||||
with progress.open(checkpoint_file, 'rb', description=f'Loading weights: [cyan]{checkpoint_file}', auto_refresh=True) as f:
|
||||
_, extension = os.path.splitext(checkpoint_file)
|
||||
if 'v1-5-pruned-emaonly.safetensors' or 'vae-ft-mse-840000-ema-pruned.ckpt' in checkpoint_file:
|
||||
@@ -251,6 +252,7 @@ def read_state_dict(checkpoint_file, map_location=None): # pylint: disable=unuse
|
||||
buffer = io.BytesIO(f.read())
|
||||
pl_sd = torch.load(buffer, map_location='cpu')
|
||||
sd = get_state_dict_from_checkpoint(pl_sd)
|
||||
del pl_sd
|
||||
except Exception as e:
|
||||
errors.display(e, f'loading model: {checkpoint_file}')
|
||||
sd = None
|
||||
|
||||
+2
-2
@@ -5,12 +5,12 @@ import json
|
||||
import datetime
|
||||
import gradio as gr
|
||||
import tqdm
|
||||
from modules import errors, ui_components, shared_items, cmd_args
|
||||
from modules.paths_internal import models_path, script_path, data_path, sd_configs_path, sd_default_config, sd_model_file, default_sd_model_file, extensions_dir, extensions_builtin_dir # pylint: disable=W0611
|
||||
import modules.interrogate
|
||||
import modules.memmon
|
||||
import modules.styles
|
||||
import modules.devices as devices
|
||||
from modules import errors, ui_components, shared_items, cmd_args
|
||||
from modules.paths_internal import models_path, script_path, data_path, sd_configs_path, sd_default_config, sd_model_file, default_sd_model_file, extensions_dir, extensions_builtin_dir # pylint: disable=W0611
|
||||
import modules.paths_internal as paths
|
||||
from installer import log as central_logger # pylint: disable=E0611
|
||||
|
||||
|
||||
Reference in New Issue
Block a user