backup vae on load and restore when set to none

This commit is contained in:
Vladimir Mandic
2024-06-22 19:50:17 -04:00
parent 1aab44cb49
commit 0a9cfc8621
2 changed files with 18 additions and 8 deletions
+7 -5
View File
@@ -11,6 +11,7 @@ But there's more than SD3:
- support for quantized **T5** text encoder in all models that use T5: FP4/FP8/FP16/INT8 (SD3, PixArt-Σ, etc)
- support for **PixArt-Sigma** in small/medium/large variants
- support for **HunyuanDiT 1.1**
- additional **NNCF weights compression** support: SD3, PixArt, ControlNet, Lora
- (finally) new release of **Torch-DirectML**
- additional efficiencies for users with low vram gpus
- over 20 overall fixes
@@ -47,6 +48,7 @@ But there's more than SD3:
- support for `torch-directml` **0.2.2**, thanks @lshqqytiger!
*note*: new directml is finally based on modern `torch` 2.3.1!
- xyz grid: add support for LoRA selector
- vae load: store original vae so it can be restored when set to none
- extra networks: info display now contains link to source url if model if its known
works for civitai and huggingface models
- force gc for lowvram users and improve gc logging
@@ -56,11 +58,11 @@ But there's more than SD3:
- additional torch gc checks, thanks @Disty0!
**Improvements: NNCF**, thanks @Disty0!
- SD3 and PixArt support
- moved the first compression step to CPU
- sequential cpu offload (lowvram) support
- Lora support without reloading the model
- ControlNet compression support
- SD3 and PixArt support
- moved the first compression step to CPU
- sequential cpu offload (lowvram) support
- Lora support without reloading the model
- ControlNet compression support
### Fixes
+11 -3
View File
@@ -259,6 +259,11 @@ def reload_vae_weights(sd_model=None, vae_file=unspecified):
vae_file, vae_source = resolve_vae(checkpoint_file)
else:
vae_source = "function-argument"
if vae_file is None or vae_file == 'None':
if hasattr(sd_model, 'original_vae'):
sd_models.set_diffuser_options(sd_model, vae=sd_model.original_vae, op='vae')
shared.log.info("VAE restored")
return None
if loaded_vae_file == vae_file:
return None
if not shared.native and (shared.cmd_opts.lowvram or shared.cmd_opts.medvram):
@@ -276,11 +281,14 @@ def reload_vae_weights(sd_model=None, vae_file=unspecified):
if vae_file is not None:
shared.log.info(f"VAE weights loaded: {vae_file}")
else:
if hasattr(shared.sd_model, "vae") and hasattr(shared.sd_model, "sd_checkpoint_info"):
vae = load_vae_diffusers(shared.sd_model.sd_checkpoint_info.filename, vae_file, vae_source)
if hasattr(sd_model, "vae") and hasattr(sd_model, "sd_checkpoint_info"):
vae = load_vae_diffusers(sd_model.sd_checkpoint_info.filename, vae_file, vae_source)
if vae is not None:
if not hasattr(sd_model, 'original_vae'):
sd_model.original_vae = sd_model.vae
sd_models.move_model(sd_model.original_vae, devices.cpu)
sd_models.set_diffuser_options(sd_model, vae=vae, op='vae')
apply_vae_config(shared.sd_model.sd_checkpoint_info.filename, vae_file, sd_model)
apply_vae_config(sd_model.sd_checkpoint_info.filename, vae_file, sd_model)
if not shared.cmd_opts.lowvram and not shared.cmd_opts.medvram:
sd_models.move_model(sd_model, devices.device)