premerge fixes

This commit is contained in:
Vladimir Mandic
2023-10-17 08:01:33 -04:00
parent 36bef98cd5
commit 8aa2d0347c
5 changed files with 11 additions and 20 deletions
+2 -15
View File
@@ -39,23 +39,10 @@ module_types = [
def assign_network_names_to_compvis_modules(sd_model):
"""
if shared.sd_model.is_sdxl:
for i, embedder in enumerate(shared.sd_model.conditioner.embedders):
if not hasattr(embedder, 'wrapped'):
continue
for name, module in embedder.wrapped.named_modules():
network_name = f'{i}_{name.replace(".", "_")}'
network_layer_mapping[network_name] = module
module.network_layer_name = network_name
else:
for name, module in shared.sd_model.cond_stage_model.wrapped.named_modules():
network_name = name.replace(".", "_")
network_layer_mapping[network_name] = module
module.network_layer_name = network_name
"""
network_layer_mapping = {}
if shared.backend == shared.Backend.DIFFUSERS:
if not hasattr(shared.sd_model, 'text_encoder') or not hasattr(shared.sd_model, 'unet'):
return
for name, module in shared.sd_model.text_encoder.named_modules():
prefix = "lora_te1_" if shared.sd_model_type == "sdxl" else "lora_te_"
network_name = prefix + name.replace(".", "_")
+1 -1
View File
@@ -365,7 +365,7 @@ def check_torch():
torch_command = os.environ.get('TORCH_COMMAND', 'torch torchvision --index-url https://download.pytorch.org/whl/cu121')
else:
torch_command = os.environ.get('TORCH_COMMAND', 'torch torchvision --index-url https://download.pytorch.org/whl/cu118')
xformers_package = os.environ.get('XFORMERS_PACKAGE', '--pre xformers<0.0.24' if opts.get('cross_attention_optimization', '') == 'xFormers' else 'none')
xformers_package = os.environ.get('XFORMERS_PACKAGE', '--pre xformers' if opts.get('cross_attention_optimization', '') == 'xFormers' else 'none')
elif allow_rocm and (shutil.which('rocminfo') is not None or os.path.exists('/opt/rocm/bin/rocminfo') or os.path.exists('/dev/kfd')):
log.info('AMD ROCm toolkit detected')
os.environ.setdefault('PYTORCH_HIP_ALLOC_CONF', 'garbage_collection_threshold:0.8,max_split_size_mb:512')
+5 -2
View File
@@ -379,8 +379,9 @@ def read_metadata_from_safetensors(filename):
def read_state_dict(checkpoint_file, map_location=None): # pylint: disable=unused-argument
#if shared.backend == shared.Backend.DIFFUSERS:
#return None
if not os.path.isfile(checkpoint_file):
shared.log.error(f"Model is not a file: {checkpoint_file}")
return None
try:
pl_sd = None
with progress.open(checkpoint_file, 'rb', description=f'[cyan]Loading weights: [yellow]{checkpoint_file}', auto_refresh=True, console=shared.console) as f:
@@ -413,6 +414,8 @@ def read_state_dict(checkpoint_file, map_location=None): # pylint: disable=unuse
def get_checkpoint_state_dict(checkpoint_info: CheckpointInfo, timer):
if not os.path.isfile(checkpoint_info.filename):
return None
if checkpoint_info in checkpoints_loaded:
shared.log.info("Model weights loading: from cache")
return checkpoints_loaded[checkpoint_info]
+2 -1
View File
@@ -182,8 +182,9 @@ class ExtraNetworksPage:
shared.log.warning(f'Extra network removing invalid image: {f}')
try:
if img is None:
img = None
os.remove(f)
if img is not None and img.width > 1024 or img.height > 1024 or os.path.getsize(f) > 65536:
elif img.width > 1024 or img.height > 1024 or os.path.getsize(f) > 65536:
img = img.convert('RGB')
img.thumbnail((512, 512), Image.HAMMING)
img.save(fn, quality=50)