mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-02-03 06:47:23 +00:00
add clip vison and remove shits
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import torch
|
||||
import os
|
||||
import time
|
||||
import safetensors
|
||||
import ldm_patched.modules.samplers
|
||||
|
||||
from ldm_patched.modules.controlnet import ControlBase
|
||||
@@ -193,6 +195,40 @@ def patched_load_models_gpu(*args, **kwargs):
|
||||
return y
|
||||
|
||||
|
||||
def build_loaded(module, loader_name):
|
||||
original_loader_name = loader_name + '_origin'
|
||||
|
||||
if not hasattr(module, original_loader_name):
|
||||
setattr(module, original_loader_name, getattr(module, loader_name))
|
||||
|
||||
original_loader = getattr(module, original_loader_name)
|
||||
|
||||
def loader(*args, **kwargs):
|
||||
result = None
|
||||
try:
|
||||
result = original_loader(*args, **kwargs)
|
||||
except Exception as e:
|
||||
result = None
|
||||
exp = str(e) + '\n'
|
||||
for path in list(args) + list(kwargs.values()):
|
||||
if isinstance(path, str):
|
||||
if os.path.exists(path):
|
||||
exp += f'File corrupted: {path} \n'
|
||||
corrupted_backup_file = path + '.corrupted'
|
||||
if os.path.exists(corrupted_backup_file):
|
||||
os.remove(corrupted_backup_file)
|
||||
os.replace(path, corrupted_backup_file)
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
exp += f'Forge has tried to move the corrupted file to {corrupted_backup_file} \n'
|
||||
exp += f'You may try again now and Fooocus will download models again. \n'
|
||||
raise ValueError(exp)
|
||||
return result
|
||||
|
||||
setattr(module, loader_name, loader)
|
||||
return
|
||||
|
||||
|
||||
def patch_all_basics():
|
||||
if not hasattr(model_management, 'load_models_gpu_origin'):
|
||||
model_management.load_models_gpu_origin = model_management.load_models_gpu
|
||||
@@ -201,4 +237,7 @@ def patch_all_basics():
|
||||
|
||||
ControlBase.control_merge = patched_control_merge
|
||||
ldm_patched.modules.samplers.calc_cond_uncond_batch = patched_calc_cond_uncond_batch
|
||||
|
||||
build_loaded(safetensors.torch, 'load_file')
|
||||
build_loaded(torch, 'load')
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user