add filename (not prefix) option and update readme
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
Auto-MBW for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) loosely based on [sdweb-auto-MBW](https://github.com/Xerxemi/sdweb-auto-MBW)
|
Auto-MBW for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) loosely based on [sdweb-auto-MBW](https://github.com/Xerxemi/sdweb-auto-MBW)
|
||||||
|
|
||||||
### Purpose
|
### Purpose
|
||||||
This node "advanced > auto merge block weighted" takes two models, merges individual blocks together at various ratios, and automatically rates each merge, keeping the ratio with the highest score. Whether this is a good idea or not is anyone's guess. In practice this makes models that make images the classifier says are good.
|
This node "advanced > auto merge block weighted" takes two models, merges individual blocks together at various ratios, and automatically rates each merge, keeping the ratio with the highest score. Whether this is a good idea or not is anyone's guess. In practice this makes models that make images the classifier says are good. You would probably disagree with the classifiers' decisions often.
|
||||||
|
|
||||||
### Settings
|
### Settings
|
||||||
- Prompt: to generate sample images to be rated
|
- Prompt: to generate sample images to be rated
|
||||||
@@ -26,10 +26,13 @@ The classifier models have been taken from the sdweb-auto-MBW repo.
|
|||||||
- [Cafe Waifu](https://huggingface.co/cafeai/cafe_waifu) and [Cafe Aesthetic](https://huggingface.co/cafeai/cafe_aesthetic)
|
- [Cafe Waifu](https://huggingface.co/cafeai/cafe_waifu) and [Cafe Aesthetic](https://huggingface.co/cafeai/cafe_aesthetic)
|
||||||
|
|
||||||
### Notes
|
### Notes
|
||||||
- --highvram flag recommended - both models will be kept in VRAM and the process is much faster
|
- many hardcoded settings are arbitrary such as the seed, sampler and block processing order
|
||||||
- many hardcoded settings are arbitrary - such as the sampler and block processing order
|
|
||||||
- generated images are not saved
|
- generated images are not saved
|
||||||
- the final model is saved in the models/checkpoints directory with a timestamped name
|
|
||||||
- the resulting model will contain the text encoder and VAE sent to the node
|
- the resulting model will contain the text encoder and VAE sent to the node
|
||||||
|
|
||||||
|
### Bugs
|
||||||
|
- filename box doesn't use the standard comfy "prefix" method
|
||||||
|
- merging process doesn't use the comfy ModelPatcher method and takes hundreds of milliseconds
|
||||||
|
- - as a result, --highvram flag recommended. both models will be kept in VRAM and the process is much faster
|
||||||
- the unet will (probably) be fp16 and the rest fp32. that's how they're sent to the node
|
- the unet will (probably) be fp16 and the rest fp32. that's how they're sent to the node
|
||||||
- - see: `model_management.should_use_fp16()`
|
- - see: `model_management.should_use_fp16()`
|
||||||
|
|||||||
+13
-3
@@ -2,7 +2,6 @@ import importlib
|
|||||||
import math
|
import math
|
||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -43,6 +42,7 @@ class AutoMBW:
|
|||||||
"search_depth": ("INT", {"default": 4, "min": 2}),
|
"search_depth": ("INT", {"default": 4, "min": 2}),
|
||||||
"sample_count": ("INT", {"default": 1, "min": 1}),
|
"sample_count": ("INT", {"default": 1, "min": 1}),
|
||||||
"classifier": (classifiers.__all__,),
|
"classifier": (classifiers.__all__,),
|
||||||
|
"filename": ("STRING", { "multiline": False, "default": "ambw" }),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
RETURN_TYPES = ()
|
RETURN_TYPES = ()
|
||||||
@@ -103,7 +103,7 @@ class AutoMBW:
|
|||||||
return maximum
|
return maximum
|
||||||
|
|
||||||
def ambw(self, model1, model2, clip, vae, prompt, negative, search_depth,
|
def ambw(self, model1, model2, clip, vae, prompt, negative, search_depth,
|
||||||
sample_count, classifier):
|
sample_count, classifier, filename):
|
||||||
# python setup
|
# python setup
|
||||||
self.model1 = model1
|
self.model1 = model1
|
||||||
self.model2 = model2
|
self.model2 = model2
|
||||||
@@ -150,14 +150,24 @@ class AutoMBW:
|
|||||||
for key in clip:
|
for key in clip:
|
||||||
sd1[f"cond_stage_model.{key}"] = clip[key]
|
sd1[f"cond_stage_model.{key}"] = clip[key]
|
||||||
|
|
||||||
|
create_ckpt = False
|
||||||
|
if filename.endswith(".safetensors"):
|
||||||
|
filename = filename[0:-12]
|
||||||
|
elif filename.endswith(".ckpt"):
|
||||||
|
filename = filename[0:-5]
|
||||||
|
create_ckpt = True
|
||||||
|
|
||||||
filename = pathlib.Path(folder_paths.folder_names_and_paths[
|
filename = pathlib.Path(folder_paths.folder_names_and_paths[
|
||||||
"checkpoints"][0][0]).joinpath(f"ambw{int(time.time())}")
|
"checkpoints"][0][0]).joinpath(f"{filename}")
|
||||||
print(f"saving as {filename}", end="")
|
print(f"saving as {filename}", end="")
|
||||||
|
if not create_ckpt:
|
||||||
try:
|
try:
|
||||||
import safetensors.torch
|
import safetensors.torch
|
||||||
print(".safetensors")
|
print(".safetensors")
|
||||||
safetensors.torch.save_file(sd1, f"{filename}.safetensors")
|
safetensors.torch.save_file(sd1, f"{filename}.safetensors")
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
|
create_ckpt = True
|
||||||
|
if create_ckpt:
|
||||||
print(".ckpt")
|
print(".ckpt")
|
||||||
torch.save(sd1, f"{filename}.ckpt")
|
torch.save(sd1, f"{filename}.ckpt")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user