Skip to content

Commit

Permalink
refactor: split legacy loaders
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Jan 13, 2025
1 parent 1c10e69 commit 0c80440
Show file tree
Hide file tree
Showing 17 changed files with 543 additions and 522 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
- refactored progress monitoring, job updates and live preview
- improved metadata save and restore
- startup tracing and optimizations
- threading load locks on model loads
- threading load locks on model loads
- refactor native vs legacy model loader
- **Schedulers**:
- [TDD](https://github.com/RedAIGC/Target-Driven-Distillation) new super-fast scheduler that can generate images in 4-8 steps
recommended to use with [TDD LoRA](https://huggingface.co/RED-AIGC/TDD/tree/main)
Expand All @@ -40,7 +41,7 @@
- **XYZ Grid**: add prompt search&replace options: *primary, refine, detailer, all*
- **SysInfo**: update to collected data and benchmarks
- [Wiki/Docs](https://vladmandic.github.io/sdnext-docs/):
- updated: Detailer, Install, Debug, Control-HowTo, ZLUDA
- updated: Detailer, Install, Update, Debug, Control-HowTo, ZLUDA
- **Fixes**:
- explict clear caches on model load
- lock adetailer commit: `#a89c01d`
Expand All @@ -61,6 +62,8 @@
- restore args after batch run
- flux controlnet
- zluda installer
- control inherit parent pipe settings
- control logging

## Update for 2024-12-31

Expand Down
2 changes: 1 addition & 1 deletion extensions-builtin/sd-webui-agent-scheduler
5 changes: 5 additions & 0 deletions installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def get(self):
log.addHandler(rb)
log.buffer = rb.buffer

def quiet_log(quiet: bool=False, *args, **kwargs): # pylint: disable=redefined-outer-name,keyword-arg-before-vararg
if not quiet:
log.debug(*args, **kwargs)
log.quiet = quiet_log

# overrides
logging.getLogger("urllib3").setLevel(logging.ERROR)
logging.getLogger("httpx").setLevel(logging.ERROR)
Expand Down
1 change: 0 additions & 1 deletion modules/cmd_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def compatibility_args():
group_compat.add_argument("--disable-queue", default=os.environ.get("SD_DISABLEQUEUE", False), action='store_true', help=argparse.SUPPRESS)



def settings_args(opts, args):
# removed args are added here as hidden in fixed format for compatbility reasons
group_compat = parser.add_argument_group('Compatibility options')
Expand Down
75 changes: 39 additions & 36 deletions modules/control/run.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion modules/control/units/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,14 @@ def __init__(self,
if dtype is not None:
self.pipeline = self.pipeline.to(dtype)

sd_models.copy_diffuser_options(self.pipeline, pipeline)
if opts.diffusers_offload_mode == 'none':
sd_models.move_model(self.pipeline, devices.device)
from modules.sd_models import set_diffuser_offload
set_diffuser_offload(self.pipeline, 'model')

t1 = time.time()
log.debug(f'Control {what} pipeline: class={self.pipeline.__class__.__name__} time={t1-t0:.2f}')
debug_log(f'Control {what} pipeline: class={self.pipeline.__class__.__name__} time={t1-t0:.2f}')

def restore(self):
self.pipeline.unload_lora_weights()
Expand Down
13 changes: 13 additions & 0 deletions modules/processing_original.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def get_conds_with_caching(function, required_prompts, steps, cache):
cache[0] = (required_prompts, steps)
return cache[1]

def check_rollback_vae():
if shared.cmd_opts.rollback_vae:
if not torch.cuda.is_available():
shared.log.error("Rollback VAE functionality requires compatible GPU")
shared.cmd_opts.rollback_vae = False
elif torch.__version__.startswith('1.') or torch.__version__.startswith('2.0'):
shared.log.error("Rollback VAE functionality requires Torch 2.1 or higher")
shared.cmd_opts.rollback_vae = False
elif 0 < torch.cuda.get_device_capability()[0] < 8:
shared.log.error('Rollback VAE functionality device capabilities not met')
shared.cmd_opts.rollback_vae = False


def process_original(p: processing.StableDiffusionProcessing):
cached_uc = [None, None]
Expand All @@ -42,6 +54,7 @@ def process_original(p: processing.StableDiffusionProcessing):
for x in x_samples_ddim:
devices.test_for_nans(x, "vae")
except devices.NansException as e:
check_rollback_vae()
if not shared.opts.no_half and not shared.opts.no_half_vae and shared.cmd_opts.rollback_vae:
shared.log.warning('Tensor with all NaNs was produced in VAE')
devices.dtype_vae = torch.bfloat16
Expand Down
6 changes: 0 additions & 6 deletions modules/sd_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ def detect_pipeline(f: str, op: str = 'model', warning=True, quiet=False):
elif (size > 20000 and size < 40000):
guess = 'FLUX'
# guess by name
"""
if 'LCM_' in f.upper() or 'LCM-' in f.upper() or '_LCM' in f.upper() or '-LCM' in f.upper():
if shared.backend == shared.Backend.ORIGINAL:
warn(f'Model detected as LCM model, but attempting to load using backend=original: {op}={f} size={size} MB')
guess = 'Latent Consistency Model'
"""
if 'instaflow' in f.lower():
guess = 'InstaFlow'
if 'segmoe' in f.lower():
Expand Down
Loading

0 comments on commit 0c80440

Please sign in to comment.