From be0bfbcd27f867a31c7ba94d39d8adada0083fd2 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 5 Jul 2023 11:00:29 -0400 Subject: [PATCH] fix samplers config --- DIFFUSERS.md | 28 +++++++++++++++++++++++----- javascript/style.css | 2 +- modules/sd_models.py | 14 +++++++------- modules/shared.py | 2 +- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/DIFFUSERS.md b/DIFFUSERS.md index ac9dc998e..3a57dec92 100644 --- a/DIFFUSERS.md +++ b/DIFFUSERS.md @@ -68,12 +68,14 @@ whats implemented so far? even if extensions are not supported, runtime errors are never nice will need to handle in the code before we get out of alpha -- controlnet - `sd_model.model?.diffusion_model?` -- multi-diffusion - `sd_model.first_stage_model?.encoder?` -- lycoris +- lycoris `lyco_patch_lora` +- controlnet + > sd_model.model?.diffusion_model? +- multi-diffusion + > sd_model.first_stage_model?.encoder? +- dynamic-thresholding + > AttributeError: 'DiffusionSampler' object has no attribute 'model_wrap_cfg' ## Issues @@ -120,6 +122,8 @@ will need to handle in the code before we get out of alpha > In this conversion only the EMA weights are extracted. If you want to instead extract the non-EMA weights (useful to continue fine-tuning), please make sure to remove the `--extract_ema` flag. - do you have plans to implement [Restart](https://github.com/vladmandic/automatic/issues/1537) sampler in diffusers? - `torch.nonzero()` performance issue +- `enable_sequential_cpu_offload()` results in error + > NotImplementedError: Cannot copy out of meta tensor; no data! ## Update @@ -132,3 +136,17 @@ will need to handle in the code before we get out of alpha - redid samplers - fixed "it looks like the config file at 'xxx.safetensors' is not a valid JSON file" - ui settings -> samplers is now dynamic depending if backend is original or diffusers + +## Performance + +| pipeline | performance it/s | memory cpu/gpu | +| --- | --- | --- | +| original | | | +| diffusers | 8.98 / 7.44 / 8.16 / 8.41 / 7.04 | 4.3 / 9.0 | +| diffusers with safetensors | 8.91 / 7.35 / 8.11 / 8.4 / 7.09 | 5.9 / 9.0 | +| diffusers medvram | 7.52 / 6.72 / 7.53 / 7.84 / 7.21 | 6.6 / 8.2 | +| diffusers lowvram | | | + +Notes: + +- Performance is measured for batch sizes 1, 2, 4, 8 16 diff --git a/javascript/style.css b/javascript/style.css index 6340485f2..b71b2ec8d 100644 --- a/javascript/style.css +++ b/javascript/style.css @@ -541,7 +541,7 @@ table.settings-value-table td{ .extra-networks-tab { padding: 0 !important; } .extra-network-subdirs { background: var(--input-background-fill); overflow-x: hidden; overflow-y: auto; max-height: 50vh; min-width: 80px; max-width: 120px; } .extra-networks-page { display: flex } -.extra-networks .custom-button { min-width: 80px; max-width: 120px; width: 100%; background: none; justify-content: left; text-align: left; padding: 2px 8px 2px 8px; box-shadow: none; line-break: anywhere; } +.extra-networks .custom-button { min-width: 80px; max-width: 120px; width: 100%; background: none; justify-content: left; text-align: left; padding: 2px 8px 2px 8px; box-shadow: none; line-break: auto; } .extra-networks .custom-button:hover { background: var(--button-primary-background-fill) } .extra-network-cards { display: flex; flex-wrap: wrap; height: 50vh; max-height: 50vh; overflow-y: scroll; overflow-x: hidden; width: -webkit-fill-available; } .extra-network-cards .card { height: fit-content; margin: 0.5em; position: relative; scroll-snap-align: start; scroll-margin-top: 0; } diff --git a/modules/sd_models.py b/modules/sd_models.py index 66df8a0ac..6ba07c52e 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -582,28 +582,28 @@ def load_diffuser(checkpoint_info=None, already_loaded_state_dict=None, timer=No prior = diffusers.DiffusionPipeline.from_pretrained(prior_id, **diffusers_load_config) sd_model = PriorPipeline(prior=prior, main=sd_model) # wrap sd_model - if hasattr(sd_model, "enable_sequential_cpu_offload"): - if shared.cmd_opts.lowvram or shared.opts.diffusers_seq_cpu_offload: - sd_model.enable_sequential_cpu_offload() - shared.log.debug('Diffusers: enable sequenctial CPU offload') if hasattr(sd_model, "enable_model_cpu_offload"): if shared.cmd_opts.medvram or shared.opts.diffusers_model_cpu_offload: shared.log.debug('Diffusers: enable model CPU offload') sd_model.enable_model_cpu_offload() + if hasattr(sd_model, "enable_sequential_cpu_offload"): + if shared.opts.diffusers_seq_cpu_offload: + sd_model.enable_sequential_cpu_offload() + shared.log.debug('Diffusers: enable sequential CPU offload') if hasattr(sd_model, "enable_vae_slicing"): - if shared.opts.diffusers_vae_slicing: + if shared.cmd_opts.lowvram or shared.opts.diffusers_vae_slicing: shared.log.debug('Diffusers: enable VAE slicing') sd_model.enable_vae_slicing() else: sd_model.disable_vae_slicing() if hasattr(sd_model, "enable_vae_tiling"): - if shared.opts.diffusers_vae_tiling: + if shared.cmd_opts.lowvram or shared.opts.diffusers_vae_tiling: shared.log.debug('Diffusers: enable VAE tiling') sd_model.enable_vae_tiling() else: sd_model.disable_vae_tiling() if hasattr(sd_model, "enable_attention_slicing"): - if shared.opts.diffusers_attention_slicing: + if shared.cmd_opts.lowvram or shared.opts.diffusers_attention_slicing: shared.log.debug('Diffusers: enable attention slicing') sd_model.enable_attention_slicing() else: diff --git a/modules/shared.py b/modules/shared.py index c9aae6b90..68945b2c7 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -472,11 +472,11 @@ options_templates.update(options_section(('sampler-params', "Sampler Settings"), "show_samplers": OptionInfo(["Euler a", "UniPC", "DEIS", "DDIM", "DPM 1S", "DPM 2M", "DPM++ 2M SDE", "DPM++ 2M SDE Karras", "DPM2 Karras", "DPM++ 2M Karras"], "Show samplers in user interface", gr.CheckboxGroup, lambda: {"choices": [x.name for x in list_samplers() if x.name != "PLMS"]}), "fallback_sampler": OptionInfo("Euler a", "Secondary sampler", gr.Dropdown, lambda: {"choices": ["None"] + [x.name for x in list_samplers()]}), "force_latent_sampler": OptionInfo("None", "Force latent upscaler sampler", gr.Dropdown, lambda: {"choices": ["None"] + [x.name for x in list_samplers()]}), + "always_batch_cond_uncond": OptionInfo(False, "Disable conditional batching enabled on low memory systems"), })) if backend == Backend.ORIGINAL: options_templates.update(options_section(('sampler-params', "Sampler Settings"), { - "always_batch_cond_uncond": OptionInfo(False, "Disable conditional batching enabled on low memory systems"), "enable_quantization": OptionInfo(True, "Enable samplers quantization for sharper and cleaner results"), "eta_ancestral": OptionInfo(1.0, "Noise multiplier for ancestral samplers (eta)", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.01}), "eta_ddim": OptionInfo(0.0, "Noise multiplier for DDIM (eta)", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.01}),