diff --git a/.pylintrc b/.pylintrc index ceb7c1e94..90a288a7c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -24,6 +24,7 @@ ignore-paths=/usr/lib/.*$, modules/unipc, modules/xadapter, repositories, + modules/prompt_parser_xhinker.py, extensions-builtin/sd-webui-agent-scheduler, extensions-builtin/sd-extension-chainner/nodes, extensions-builtin/sdnext-modernui/node_modules, diff --git a/.ruff.toml b/.ruff.toml index ea91ba5a5..f18b29ce2 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -18,6 +18,8 @@ exclude = [ "modules/segmoe", "modules/control/proc", "modules/control/units", + "modules/prompt_parser_xhinker.py", + "modules/postprocess/aurasr_arch.py", "repositories", "extensions-builtin/sd-extension-chainner/nodes", "extensions-builtin/sd-webui-agent-scheduler", @@ -80,4 +82,4 @@ line-ending = "auto" docstring-code-format = false [lint.mccabe] -max-complexity = 99 +max-complexity = 150 diff --git a/CHANGELOG.md b/CHANGELOG.md index debc5a47c..6fe9b8691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ Plus tons of minor items and fixes - see [changelog](https://github.com/vladmand can speed up generate enable via *settings -> compute -> fused projections* -**Other improvements:** +**Other improvements & Fixes:** - [CogVideoX](https://huggingface.co/THUDM/CogVideoX-5b) - support for both **2B** and **5B** variations - support for both **text2video** and **video2video** modes @@ -93,13 +93,12 @@ Plus tons of minor items and fixes - see [changelog](https://github.com/vladmand improves quality of the flow-matching samplers - **t5** support manually downloaded models applies to all models that use t5 transformer -- **modern-ui** add override field +- **modern-ui** add override field +- full **lint** updates - use `diffusers` from main branch, no longer tied to release - -**Fixes:** - fix handling of model configs if offline config is not available -- fix vae decode in backend original -- fix model path typos +- fix vae decode in backend original +- fix model path typos ## Update for 2024-08-31 diff --git a/extensions-builtin/Lora/lora_patches.py b/extensions-builtin/Lora/lora_patches.py index 7b0916e3a..532782c80 100644 --- a/extensions-builtin/Lora/lora_patches.py +++ b/extensions-builtin/Lora/lora_patches.py @@ -22,8 +22,8 @@ class LoraPatches: return if "Model" in shared.opts.optimum_quanto_weights or "Text Encoder" in shared.opts.optimum_quanto_weights: from optimum import quanto - self.QLinear_forward = patches.patch(__name__, quanto.nn.QLinear, 'forward', networks.network_QLinear_forward) - self.QConv2d_forward = patches.patch(__name__, quanto.nn.QConv2d, 'forward', networks.network_QConv2d_forward) + self.QLinear_forward = patches.patch(__name__, quanto.nn.QLinear, 'forward', networks.network_QLinear_forward) # pylint: disable=attribute-defined-outside-init + self.QConv2d_forward = patches.patch(__name__, quanto.nn.QConv2d, 'forward', networks.network_QConv2d_forward) # pylint: disable=attribute-defined-outside-init self.Linear_forward = patches.patch(__name__, torch.nn.Linear, 'forward', networks.network_Linear_forward) self.Linear_load_state_dict = patches.patch(__name__, torch.nn.Linear, '_load_from_state_dict', networks.network_Linear_load_state_dict) self.Conv2d_forward = patches.patch(__name__, torch.nn.Conv2d, 'forward', networks.network_Conv2d_forward) @@ -44,8 +44,8 @@ class LoraPatches: return if "Model" in shared.opts.optimum_quanto_weights or "Text Encoder" in shared.opts.optimum_quanto_weights: from optimum import quanto - self.QLinear_forward = patches.undo(__name__, quanto.nn.QLinear, 'forward') # pylint: disable=E1128 - self.QConv2d_forward = patches.undo(__name__, quanto.nn.QConv2d, 'forward') # pylint: disable=E1128 + self.QLinear_forward = patches.undo(__name__, quanto.nn.QLinear, 'forward') # pylint: disable=E1128, attribute-defined-outside-init + self.QConv2d_forward = patches.undo(__name__, quanto.nn.QConv2d, 'forward') # pylint: disable=E1128, attribute-defined-outside-init self.Linear_forward = patches.undo(__name__, torch.nn.Linear, 'forward') # pylint: disable=E1128 self.Linear_load_state_dict = patches.undo(__name__, torch.nn.Linear, '_load_from_state_dict') # pylint: disable=E1128 self.Conv2d_forward = patches.undo(__name__, torch.nn.Conv2d, 'forward') # pylint: disable=E1128 diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index 004b2605e..1bc7a74f7 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -206,7 +206,7 @@ def load_networks(names, te_multipliers=None, unet_multipliers=None, dyn_dims=No if recompile_model: backup_cuda_compile = shared.opts.cuda_compile sd_models.unload_model_weights(op='model') - shared.opts.cuda_compile = False + shared.opts.cuda_compile = [] sd_models.reload_model_weights(op='model') shared.opts.cuda_compile = backup_cuda_compile @@ -261,7 +261,7 @@ def load_networks(names, te_multipliers=None, unet_multipliers=None, dyn_dims=No if recompile_model: shared.log.info("LoRA recompiling model") backup_lora_model = shared.compiled_model_state.lora_model - if shared.opts.cuda_compile: + if 'Model' in shared.opts.cuda_compile: shared.sd_model = sd_models_compile.compile_diffusers(shared.sd_model) shared.compiled_model_state.lora_model = backup_lora_model diff --git a/installer.py b/installer.py index 4ac3ae51e..00b699e5d 100644 --- a/installer.py +++ b/installer.py @@ -437,13 +437,16 @@ def check_python(supported_minors=[9, 10, 11, 12], reason=None): # check diffusers version def check_diffusers(): + sha = '8cdcdd9e32925200ce5e1cf410fe14a774f3c3a6' pkg = pkg_resources.working_set.by_key.get('diffusers', None) minor = int(pkg.version.split('.')[1] if pkg is not None else 0) - if minor < 31: - log.debug(f'Diffusers {"install" if minor == 0 else "upgrade"}') + cur = opts.get('diffusers_version', '') if minor > 0 else '' + if (minor == 0) or (cur != sha): + log.debug(f'Diffusers {"install" if minor == 0 else "upgrade"}: current={pkg}@{cur} target={sha}') if minor > 0: pip('uninstall --yes diffusers', ignore=True, quiet=True, uv=False) - pip('install --upgrade git+https://github.com/huggingface/diffusers@d269cc8a4e9b7380d52daef1ee7ec4c82c942a13', ignore=False, quiet=True, uv=False) + pip(f'install --upgrade git+https://github.com/huggingface/diffusers@{sha}', ignore=False, quiet=True, uv=False) + opts['diffusers_version'] = sha # check onnx version @@ -495,7 +498,7 @@ def install_rocm_zluda(): break log.info(f'ROCm version detected: {rocm.version}') - + torch_command = '' if sys.platform == "win32": #if args.use_zluda: log.warning("ZLUDA support: experimental") diff --git a/modules/control/run.py b/modules/control/run.py index f41c82dd2..64a54d5d4 100644 --- a/modules/control/run.py +++ b/modules/control/run.py @@ -217,10 +217,9 @@ def control_run(units: List[unit.Unit] = [], inputs: List[Image.Image] = [], ini debug(f'Control unit offload: model="{u.controlnet.model_id}" device={devices.cpu}') sd_models.move_model(u.controlnet.model, devices.cpu) continue - else: - if u.controlnet is not None and u.controlnet.model is not None: - debug(f'Control unit offload: model="{u.controlnet.model_id}" device={devices.device}') - sd_models.move_model(u.controlnet.model, devices.device) + if u.controlnet is not None and u.controlnet.model is not None: + debug(f'Control unit offload: model="{u.controlnet.model_id}" device={devices.device}') + sd_models.move_model(u.controlnet.model, devices.device) if unit_type == 't2i adapter' and u.adapter.model is not None: active_process.append(u.process) active_model.append(u.adapter) @@ -548,7 +547,7 @@ def control_run(units: List[unit.Unit] = [], inputs: List[Image.Image] = [], ini elif unit_type == 'controlnet' and has_models: if input_type == 0: # Control only if shared.sd_model_type == 'f1': - p.task_args['control_image'] = p.init_images # TODO flux controlnet mandates this + p.task_args['control_image'] = p.init_images # flux controlnet mandates this p.task_args['strength'] = p.denoising_strength elif input_type == 1: # Init image same as control p.task_args['control_image'] = p.init_images # switch image and control_image diff --git a/modules/img2img.py b/modules/img2img.py index 38620ebd0..e576f1058 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -103,7 +103,7 @@ def process_batch(p, input_files, input_dir, output_dir, inpaint_mask_dir, args) for k, v in items.items(): image.info[k] = v images.save_image(image, path=output_dir, basename=basename, seed=None, prompt=None, extension=ext, info=geninfo, short_filename=True, no_prompt=True, grid=False, pnginfo_section_name="extras", existing_info=image.info, forced_filename=forced_filename) - proce = modules.scripts.scripts_img2img.after(p, proc, *args) + proc = modules.scripts.scripts_img2img.after(p, proc, *args) shared.log.debug(f'Processed: images={len(batch_image_files)} memory={memory_stats()} batch') diff --git a/modules/model_flux.py b/modules/model_flux.py index b85aa220a..0fd4e39ca 100644 --- a/modules/model_flux.py +++ b/modules/model_flux.py @@ -25,7 +25,7 @@ def get_quant(file_path): return 'none' -def load_flux_quanto(checkpoint_info, diffusers_load_config): +def load_flux_quanto(checkpoint_info): transformer, text_encoder_2 = None, None from installer import install install('optimum-quanto', quiet=True) @@ -132,11 +132,11 @@ def load_transformer(file_path): # triggered by opts.sd_unet change shared.log.info(f'Loading UNet: type=FLUX file="{file_path}" offload={shared.opts.diffusers_offload_mode} quant={quant} dtype={devices.dtype}') if 'nf4' in quant: from modules.model_flux_nf4 import load_flux_nf4 - _transformer, _text_encoder_2 = load_flux_nf4(file_path, diffusers_load_config) + _transformer, _text_encoder_2 = load_flux_nf4(file_path) if _transformer is not None: transformer = _transformer elif quant == 'qint8' or quant == 'qint4': - _transformer, _text_encoder_2 = load_flux_quanto(file_path, diffusers_load_config) + _transformer, _text_encoder_2 = load_flux_quanto(file_path) if _transformer is not None: transformer = _transformer elif quant == 'fp8' or quant == 'fp4': @@ -206,7 +206,7 @@ def load_flux(checkpoint_info, diffusers_load_config): # triggered by opts.sd_ch if quant == 'nf4': try: from modules.model_flux_nf4 import load_flux_nf4 - _transformer, _text_encoder = load_flux_nf4(checkpoint_info, diffusers_load_config) + _transformer, _text_encoder = load_flux_nf4(checkpoint_info) if _transformer is not None: transformer = _transformer if _text_encoder is not None: @@ -218,7 +218,7 @@ def load_flux(checkpoint_info, diffusers_load_config): # triggered by opts.sd_ch errors.display(e, 'FLUX NF4:') if quant == 'qint8' or quant == 'qint4': try: - _transformer, _text_encoder = load_flux_quanto(checkpoint_info, diffusers_load_config) + _transformer, _text_encoder = load_flux_quanto(checkpoint_info) if _transformer is not None: transformer = _transformer if _text_encoder is not None: @@ -239,7 +239,7 @@ def load_flux(checkpoint_info, diffusers_load_config): # triggered by opts.sd_ch components['vae'] = vae shared.log.debug(f'Loading FLUX: preloaded={list(components)}') if repo_id == 'sayakpaul/flux.1-dev-nf4': - repo_id = 'black-forest-labs/FLUX.1-dev' # TODO fix for since sayakpaul model is missing model_index.json + repo_id = 'black-forest-labs/FLUX.1-dev' # workaround since sayakpaul model is missing model_index.json pipe = diffusers.FluxPipeline.from_pretrained(repo_id, cache_dir=shared.opts.diffusers_dir, **components, **diffusers_load_config) try: diffusers.pipelines.auto_pipeline.AUTO_TEXT2IMAGE_PIPELINES_MAPPING["flux"] = diffusers.FluxPipeline diff --git a/modules/model_flux_nf4.py b/modules/model_flux_nf4.py index b91e8fa28..1644a667a 100644 --- a/modules/model_flux_nf4.py +++ b/modules/model_flux_nf4.py @@ -162,7 +162,7 @@ def create_quantized_param( module._parameters[tensor_name] = new_value # pylint: disable=protected-access -def load_flux_nf4(checkpoint_info, diffusers_load_config): +def load_flux_nf4(checkpoint_info): load_bnb() transformer = None text_encoder_2 = None diff --git a/modules/model_t5.py b/modules/model_t5.py index 6a1f15dd5..828d05ecd 100644 --- a/modules/model_t5.py +++ b/modules/model_t5.py @@ -78,7 +78,7 @@ def set_t5(pipe, module, t5=None, cache_dir=None): return pipe t5 = load_t5(t5=t5, cache_dir=cache_dir) if module == "text_encoder_2" and t5 is None: # do not unload te2 - return + return None setattr(pipe, module, t5) if shared.opts.diffusers_offload_mode == "sequential": from accelerate import cpu_offload diff --git a/modules/processing_class.py b/modules/processing_class.py index 0b8b80d1a..5b052e354 100644 --- a/modules/processing_class.py +++ b/modules/processing_class.py @@ -169,7 +169,7 @@ class StableDiffusionProcessing: def setup_scripts(self): self.scripts_setup_complete = True - self.scripts.setup_scrips(self, is_ui=not self.is_api) + self.scripts.setup_scripts() def comment(self, text): self.comments[text] = 1 diff --git a/modules/processing_diffusers.py b/modules/processing_diffusers.py index a5714e775..583c93ea1 100644 --- a/modules/processing_diffusers.py +++ b/modules/processing_diffusers.py @@ -26,20 +26,6 @@ def process_diffusers(p: processing.StableDiffusionProcessing): return p.enable_hr and p.refiner_steps > 0 and p.refiner_start > 0 and p.refiner_start < 1 and shared.sd_refiner is not None def update_pipeline(sd_model, p: processing.StableDiffusionProcessing): - """ - import diffusers - if p.sag_scale > 0 and is_txt2img(): - update_sampler(shared.sd_model) - supported = ['DDIMScheduler', 'PNDMScheduler', 'DDPMScheduler', 'DEISMultistepScheduler', 'UniPCMultistepScheduler', 'DPMSolverMultistepScheduler', 'DPMSolverSinlgestepScheduler'] - if hasattr(sd_model, 'sfast'): - shared.log.warning(f'SAG incompatible compile mode: backend={shared.opts.cuda_compile_backend}') - elif sd_model.scheduler.__class__.__name__ in supported: - sd_model = sd_models.switch_pipe(diffusers.StableDiffusionSAGPipeline, sd_model) - p.extra_generation_params["SAG scale"] = p.sag_scale - p.task_args['sag_scale'] = p.sag_scale - else: - shared.log.warning(f'SAG incompatible scheduler: current={sd_model.scheduler.__class__.__name__} supported={supported}') - """ if sd_models.get_diffusers_task(sd_model) == sd_models.DiffusersTaskType.INPAINTING and getattr(p, 'image_mask', None) is None and p.task_args.get('image_mask', None) is None and getattr(p, 'mask', None) is None: shared.log.warning('Processing: mode=inpaint mask=None') sd_model = sd_models.set_diffuser_pipe(sd_model, sd_models.DiffusersTaskType.IMAGE_2_IMAGE) diff --git a/modules/processing_vae.py b/modules/processing_vae.py index 60cf50444..1e7900ff0 100644 --- a/modules/processing_vae.py +++ b/modules/processing_vae.py @@ -33,6 +33,7 @@ def create_latents(image, p, dtype=None, device=None): def full_vae_decode(latents, model): t0 = time.time() + base_device = None if shared.opts.diffusers_move_unet and not getattr(model, 'has_accelerate', False): base_device = sd_models.move_base(model, devices.cpu) if shared.opts.diffusers_offload_mode == "balanced": @@ -66,7 +67,7 @@ def full_vae_decode(latents, model): decoded = model.vae.decode(latents, return_dict=False)[0] # delete vae after OpenVINO compile - if shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx" and shared.compiled_model_state.first_pass_vae: + if 'VAE' in shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx" and shared.compiled_model_state.first_pass_vae: shared.compiled_model_state.first_pass_vae = False if not shared.opts.openvino_disable_memory_cleanup and hasattr(shared.sd_model, "vae"): model.vae.apply(sd_models.convert_to_faketensors) @@ -136,8 +137,6 @@ def vae_decode(latents, model, output_type='np', full_quality=True): decoded = full_vae_decode(latents=latents, model=shared.sd_model) else: decoded = taesd_vae_decode(latents=latents) - # TODO validate decoded sample diffusers - # decoded = validate_sample(decoded) if hasattr(model, 'image_processor'): imgs = model.image_processor.postprocess(decoded, output_type=output_type) else: diff --git a/modules/prompt_parser_xhinker.py b/modules/prompt_parser_xhinker.py index b1c3efc69..6a8acf8c6 100644 --- a/modules/prompt_parser_xhinker.py +++ b/modules/prompt_parser_xhinker.py @@ -679,12 +679,12 @@ def get_weighted_text_embeddings_sdxl_refiner( for j in range(len(weight_tensor_2)): if weight_tensor_2[j] != 1.0: - ow = weight_tensor_2[j] - 1 + # ow = weight_tensor_2[j] - 1 # optional process # To map number of (0,1) to (-1,1) - tanh_weight = (math.exp(ow) / (math.exp(ow) + 1) - 0.5) * 2 - weight = 1 + tanh_weight + # tanh_weight = (math.exp(ow) / (math.exp(ow) + 1) - 0.5) * 2 + # weight = 1 + tanh_weight # add weight method 1: # token_embedding[j] = token_embedding[j] * weight diff --git a/modules/scripts.py b/modules/scripts.py index 464117c5e..c44fe6d14 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -491,6 +491,7 @@ class ScriptRunner: if hasattr(script, 'run'): processed = script.run(p, *parsed) else: + processed = None errors.log.error(f'Script: file="{script.filename}" no run function defined') s.record(script.title()) s.report() diff --git a/modules/sd_hijack_dynamic_atten.py b/modules/sd_hijack_dynamic_atten.py index fb2befc18..1c17e024c 100644 --- a/modules/sd_hijack_dynamic_atten.py +++ b/modules/sd_hijack_dynamic_atten.py @@ -1,7 +1,7 @@ from functools import cache, wraps import torch -from diffusers.utils import USE_PEFT_BACKEND +from diffusers.utils import USE_PEFT_BACKEND # pylint: disable=unused-import from modules import shared, devices @@ -107,8 +107,7 @@ class DynamicAttnProcessorBMM: based on AttnProcessor V1 """ - def __call__(self, attn, hidden_states: torch.Tensor, encoder_hidden_states=None, attention_mask=None, - temb=None, *args, **kwargs) -> torch.Tensor: # pylint: disable=too-many-statements, too-many-locals, too-many-branches + def __call__(self, attn, hidden_states: torch.Tensor, encoder_hidden_states=None, attention_mask=None, temb=None, *args, **kwargs) -> torch.Tensor: # pylint: disable=too-many-statements, too-many-locals, too-many-branches, keyword-arg-before-vararg residual = hidden_states diff --git a/modules/sd_models.py b/modules/sd_models.py index 906cf6b13..3f2d717fa 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -907,7 +907,7 @@ def move_model(model, device=None, force=False): if hasattr(model, "prior_pipe"): model.prior_pipe.to(device) except Exception as e0: - if 'Cannot copy out of meta tensor' in str(e0) or 'must be Tensor, not NoneType': + if 'Cannot copy out of meta tensor' in str(e0) or 'must be Tensor, not NoneType' in str(e0): if hasattr(model, "components"): for _name, component in model.components.items(): if hasattr(component, 'modules'): @@ -1316,7 +1316,7 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No insert_parser_highjack(sd_model.__class__.__name__) set_diffuser_options(sd_model, vae, op, offload=False) - if shared.opts.nncf_compress_weights and not (shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx"): + if shared.opts.nncf_compress_weights and not ('Model' in shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx"): sd_model = sd_models_compile.nncf_compress_weights(sd_model) # run this before move model so it can be compressed in CPU if shared.opts.optimum_quanto_weights: sd_model = sd_models_compile.optimum_quanto_weights(sd_model) # run this before move model so it can be compressed in CPU @@ -1337,7 +1337,7 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No if shared.opts.ipex_optimize: sd_model = sd_models_compile.ipex_optimize(sd_model) - if (shared.opts.cuda_compile and shared.opts.cuda_compile_backend != 'none'): + if ('Model' in shared.opts.cuda_compile and shared.opts.cuda_compile_backend != 'none'): sd_model = sd_models_compile.compile_diffusers(sd_model) timer.record("compile") @@ -1488,7 +1488,7 @@ def set_diffuser_pipe(pipe, new_pipe_type): return pipe # skip specific pipelines - if n in ['StableDiffusionReferencePipeline', 'StableDiffusionAdapterPipeline', 'AnimateDiffPipeline', 'AnimateDiffSDXLPipeline', 'FluxControlNetPipeline']: # TODO flux does not have inpaint/img2img yet + if n in ['StableDiffusionReferencePipeline', 'StableDiffusionAdapterPipeline', 'AnimateDiffPipeline', 'AnimateDiffSDXLPipeline', 'FluxControlNetPipeline']: return pipe if 'Onnx' in pipe.__class__.__name__: return pipe @@ -1832,7 +1832,7 @@ def unload_model_weights(op='model'): from modules import sd_hijack move_model(model_data.sd_model, devices.cpu) sd_hijack.model_hijack.undo_hijack(model_data.sd_model) - elif not (shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx"): + elif not ('Model' in shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx"): disable_offload(model_data.sd_model) move_model(model_data.sd_model, 'meta') model_data.sd_model = None diff --git a/modules/sd_models_compile.py b/modules/sd_models_compile.py index 6cd11fb18..26c4e570a 100644 --- a/modules/sd_models_compile.py +++ b/modules/sd_models_compile.py @@ -421,7 +421,7 @@ def compile_torch(sd_model): except Exception as e: shared.log.error(f"Torch inductor config error: {e}") - sd_model = apply_compile_to_model(sd_model, torch_compile_model, shared.opts.cuda_compile, op="compile") + sd_model = apply_compile_to_model(sd_model, function=torch_compile_model, options=shared.opts.cuda_compile, op="compile") setup_logging() # compile messes with logging so reset is needed if shared.opts.cuda_compile_precompile: @@ -462,7 +462,7 @@ def compile_deepcache(sd_model): def compile_diffusers(sd_model): - if not shared.opts.cuda_compile: + if 'Model' not in shared.opts.cuda_compile: return sd_model if shared.opts.cuda_compile_backend == 'none': shared.log.warning('Model compile enabled but no backend specified') @@ -518,7 +518,7 @@ def dynamic_quantization(sd_model): def openvino_recompile_model(p, hires=False, refiner=False): # recompile if a parameter changes - if shared.opts.cuda_compile and shared.opts.cuda_compile_backend != 'none': + if 'Model' in shared.opts.cuda_compile and shared.opts.cuda_compile_backend != 'none': if shared.opts.cuda_compile_backend == "openvino_fx": compile_height = p.height if not hires and hasattr(p, 'height') else p.hr_upscale_to_y compile_width = p.width if not hires and hasattr(p, 'width') else p.hr_upscale_to_x @@ -541,7 +541,7 @@ def openvino_recompile_model(p, hires=False, refiner=False): # recompile if a pa def openvino_post_compile(op="base"): # delete unet after OpenVINO compile - if shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx": + if 'Model' in shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx": if shared.compiled_model_state.first_pass and op == "base": shared.compiled_model_state.first_pass = False if not shared.opts.openvino_disable_memory_cleanup and hasattr(shared.sd_model, "unet"): diff --git a/modules/sd_samplers_common.py b/modules/sd_samplers_common.py index b49e981f1..1d4db96cb 100644 --- a/modules/sd_samplers_common.py +++ b/modules/sd_samplers_common.py @@ -61,7 +61,7 @@ def single_sample_to_image(sample, approximation=None): if approximation == 2: # TAESD x_sample = sd_vae_taesd.decode(sample) x_sample = (1.0 + x_sample) / 2.0 # preview requires smaller range - elif sd_cascade and not approximation == 3: + elif sd_cascade and approximation != 3: x_sample = sd_vae_stablecascade.decode(sample) elif approximation == 0: # Simple x_sample = sd_vae_approx.cheap_approximation(sample) * 0.5 + 0.5 diff --git a/modules/shared.py b/modules/shared.py index 7be446482..b8c9e57e0 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -419,6 +419,7 @@ options_templates.update(options_section(('sd', "Execution & Models"), { "sd_checkpoint_cache": OptionInfo(0, "Cached models", gr.Slider, {"minimum": 0, "maximum": 10, "step": 1, "visible": not native }), "sd_vae_checkpoint_cache": OptionInfo(0, "Cached VAEs", gr.Slider, {"minimum": 0, "maximum": 10, "step": 1, "visible": False}), "sd_disable_ckpt": OptionInfo(False, "Disallow models in ckpt format", gr.Checkbox, {"visible": False}), + "diffusers_version": OptionInfo("", "Diffusers version", gr.Textbox, {"visible": False}), })) options_templates.update(options_section(('cuda', "Compute Settings"), { diff --git a/modules/textual_inversion/textual_inversion.py b/modules/textual_inversion/textual_inversion.py index ed8acceca..7ad0166e7 100644 --- a/modules/textual_inversion/textual_inversion.py +++ b/modules/textual_inversion/textual_inversion.py @@ -23,12 +23,12 @@ def open_embeddings(filename): """ Load Embedding files from drive. Image embeddings not currently supported. """ - if filename is None: - return - filenames = list(filename) - exts = [".SAFETENSORS", '.BIN', '.PT'] embeddings = [] skipped = [] + if filename is None: + return embeddings, skipped + filenames = list(filename) + exts = [".SAFETENSORS", '.BIN', '.PT'] for _filename in filenames: # debug(f'Embedding check: {filename}') fullname = _filename @@ -274,15 +274,15 @@ class EmbeddingDatabase: """ overwrite = bool(data) if not shared.sd_loaded: - return 0 + return embeddings, skipped = open_embeddings(filename) or convert_bundled(data) for skip in skipped: self.skipped_embeddings[skip.name] = skipped if not embeddings: - return 0 + return text_encoders, tokenizers, hiddensizes = get_text_encoders() if not all([text_encoders, tokenizers, hiddensizes]): - return 0 + return for embedding in embeddings: try: embedding.vector_sizes = [v.shape[-1] for v in embedding.vec] @@ -320,20 +320,20 @@ class EmbeddingDatabase: if ext in ['.PNG', '.WEBP', '.JXL', '.AVIF']: if '.preview' in filename.lower(): - return None + return embed_image = Image.open(path) if hasattr(embed_image, 'text') and 'sd-ti-embedding' in embed_image.text: data = embedding_from_b64(embed_image.text['sd-ti-embedding']) else: data = extract_image_data_embed(embed_image) if not data: # if data is None, means this is not an embeding, just a preview image - return None + return elif ext in ['.BIN', '.PT']: data = torch.load(path, map_location="cpu") elif ext in ['.SAFETENSORS']: data = safetensors.torch.load_file(path, device="cpu") else: - return None + return # textual inversion embeddings if 'string_to_param' in data: @@ -345,7 +345,7 @@ class EmbeddingDatabase: elif type(data) == dict and type(next(iter(data.values()))) == torch.Tensor: if len(data.keys()) != 1: self.skipped_embeddings[name] = Embedding(None, name=name, filename=path) - return None + return emb = next(iter(data.values())) if len(emb.shape) == 1: emb = emb.unsqueeze(0) @@ -353,7 +353,7 @@ class EmbeddingDatabase: raise RuntimeError(f"Couldn't identify {filename} as textual inversion embedding") if shared.native: - return emb + return vec = emb.detach().to(devices.device, dtype=torch.float32) # name = data.get('name', name) diff --git a/modules/ui.py b/modules/ui.py index 70128e0f9..44fcab97c 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -243,9 +243,11 @@ def create_ui(startup_timer = None): if cmd_opts.use_directml: directml_override_opts() if cmd_opts.use_openvino: - if not shared.opts.cuda_compile: - shared.log.warning("OpenVINO: Enabling Torch Compile") - shared.opts.cuda_compile = True + shared.log.warning("OpenVINO: Enabling Torch Compile") + if "Model" not in shared.opts.cuda_compile: + shared.opts.cuda_compile.append("Model") + if "VAE" not in shared.opts.cuda_compile: + shared.opts.cuda_compile.append("VAE") if shared.opts.cuda_compile_backend != "openvino_fx": shared.log.warning("OpenVINO: Setting Torch Compiler backend to OpenVINO FX") shared.opts.cuda_compile_backend = "openvino_fx" diff --git a/modules/ui_control.py b/modules/ui_control.py index 336653396..b2cf157a7 100644 --- a/modules/ui_control.py +++ b/modules/ui_control.py @@ -136,7 +136,7 @@ def create_ui(_blocks: gr.Blocks=None): with gr.Row(variant='compact', elem_id="control_extra_networks", visible=False) as extra_networks_ui: from modules import timer, ui_extra_networks extra_networks_ui = ui_extra_networks.create_ui(extra_networks_ui, btn_extra, 'control', skip_indexing=shared.opts.extra_network_skip_indexing) - timer.startup.record('ui-en') + timer.startup.record('ui-networks') with gr.Row(elem_id='control-inputs'): with gr.Column(scale=9, elem_id='control-input-column', visible=True) as _column_input: diff --git a/modules/ui_img2img.py b/modules/ui_img2img.py index 1da835be6..8d18eefea 100644 --- a/modules/ui_img2img.py +++ b/modules/ui_img2img.py @@ -44,7 +44,7 @@ def create_ui(): with gr.Row(variant='compact', elem_id="img2img_extra_networks", visible=False) as extra_networks_ui: from modules import ui_extra_networks extra_networks_ui_img2img = ui_extra_networks.create_ui(extra_networks_ui, img2img_extra_networks_button, 'img2img', skip_indexing=shared.opts.extra_network_skip_indexing) - timer.startup.record('ui-en') + timer.startup.record('ui-networks') with gr.Row(elem_id="img2img_interface", equal_height=False): with gr.Column(variant='compact', elem_id="img2img_settings"): diff --git a/modules/ui_txt2img.py b/modules/ui_txt2img.py index 705444ccf..fca679a70 100644 --- a/modules/ui_txt2img.py +++ b/modules/ui_txt2img.py @@ -29,7 +29,7 @@ def create_ui(): with gr.Row(variant='compact', elem_id="txt2img_extra_networks", visible=False) as extra_networks_ui: from modules import ui_extra_networks extra_networks_ui = ui_extra_networks.create_ui(extra_networks_ui, txt2img_extra_networks_button, 'txt2img', skip_indexing=shared.opts.extra_network_skip_indexing) - timer.startup.record('ui-en') + timer.startup.record('ui-networks') with gr.Row(elem_id="txt2img_interface", equal_height=False): with gr.Column(variant='compact', elem_id="txt2img_settings"):