Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebUI 1.6.0 fix with my own guide and recommendations. #4

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 205 additions & 0 deletions README.md

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions docs/15b-AstolfoMix-08b09b-0-2023-11-21-12-16AM-36.csv

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions docs/15b-AstolfoMix-08b09b.recipe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
modelA=08b-AstolfoMix-_13a_14a.safetensors
modelB=09b-AstolfoMix-_15a_16a.safetensors
modelO=15b-AstolfoMix-08b09b
position_id_fix=Keep Original
output_mode=Max Precision
0.4,0.9,0.5,0.6,0.5,0.0,0.9,0.9,1.0,0.4,0.3,0.8,0.3,0.9,0.6,0.8,0.9,0.7,0.6,1.0,0.9,0.6,0.7,0.3,0.6,1.0,0.0

[0] hyper_score (Bayesian Optimization): 35%| | 95/270 [48:30:32<89:21:31, 1838.24s/it, best_iter=0, best


Results: 'hyper_score'
Best score: 0.6132534303822829
Best parameter set:
'0' : 0.4
'1' : 0.9
'2' : 0.5
'3' : 0.6
'4' : 0.5
'5' : 0.0
'6' : 0.9
'7' : 0.9
'8' : 1.0
'9' : 0.4
'10' : 0.3
'11' : 0.8
'12' : 0.3
'13' : 1.0
'14' : 0.9
'15' : 0.6
'16' : 0.8
'17' : 0.9
'18' : 0.7
'19' : 0.6
'20' : 1.0
'21' : 0.9
'22' : 0.6
'23' : 0.7
'24' : 0.3
'25' : 0.6
'26' : 0.0
Best iteration: 0

Random seed: 367813992

Evaluation time : 174590.83615255356 sec [99.98 %]
Optimization time : 34.05722665786743 sec [0.02 %]
Iteration time : 174624.89337921143 sec [646.76 sec/iter]

2023-11-21 00:16:36,848 - AutoMBWrt - INFO - Writing merge history to E:\NOVELAI\stable-diffusion-webui\stable-diffusion-webui\extensions\auto-MBW-rt\csv\history.tsv
2023-11-21 00:16:36,873 - AutoMBWrt - INFO - Saving checkpoint to 15b-AstolfoMix-08b09b
2023-11-21 00:16:36,873 - MBWrt - DEBUG - Gathering MBW info
2023-11-21 00:16:36,873 - MBWrt - DEBUG - Reading model A
2023-11-21 00:16:40,076 - MBWrt - DEBUG - Saving recipe file as E:\NOVELAI\stable-diffusion-webui\stable-diffusion-webui\models\Stable-diffusion\15b-AstolfoMix-08b09b.recipe.txt
2023-11-21 00:16:42,189 - MBWrt - INFO - Checkpoint saved to E:\NOVELAI\stable-diffusion-webui\stable-diffusion-webui\models\Stable-diffusion\15b-AstolfoMix-08b09b.safetensors.
2023-11-21 00:16:42,321 - AutoMBWrt - INFO - merge completed.
2023-11-21 00:16:42,321 - AutoMBWrt - INFO - Disable injection.

[0] hyper_score (Bayesian Optimization): 0%| | 0/270 [00:00<?, ?it/s]2023-11-21 01:27:27,668 - AutoMBWrt - INFO - testweights: 0.4,0.9,0.5,0.6,0.5,0.0,0.9,0.9,1.0,0.4,0.3,0.8,0.3,1.0,0.9,0.6,0.8,0.9,0.7,0.6,1.0,0.9,0.6,0.7,0.3,0.6,0.0
2023-11-21 02:02:24,217 - AutoMBWrt - DEBUG - <Response [200]>████████████| 96/96 [02:39<00:00, 3.00s/it]
load checkpoint from C:\Users\User/.cache/ImageReward\ImageReward.pt
checkpoint loaded
2023-11-21 02:02:40,953 - AutoMBWrt - INFO - test score: 0.6132534303822829
[0] hyper_score (Bayesian Optimization): 0%| | 1/270 [35:13<157:54:39, 2113.31s/it, best_iter=0, best_po]
Binary file added docs/continue_as_warmstart.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/recover_from_log.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions docs/recover_from_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import numpy as np

raw_log = """
[0] hyper_score (Bayesian Optimization): 12%| | 31/250 [7:10:18<50:39:56, 832.86s/it, best_iter=0, bes


Results: 'hyper_score'
Best score: 0.44875530845332806
Best parameter set:
'0' : 0.35
'1' : 0.05
'2' : 1.0
'3' : 0.7
'4' : 0.35
'5' : 0.75
'6' : 0.7
'7' : 1.0
'8' : 0.95
'9' : 0.65
'10' : 0.9
'11' : 0.05
'12' : 0.45
'13' : 1.0
'14' : 0.4
'15' : 0.4
'16' : 0.3
'17' : 1.0
'18' : 0.5
'19' : 0.7
'20' : 0.8
'21' : 0.6
'22' : 0.95
'23' : 0.55
'24' : 0.45
'25' : 0.2
'26' : 0.2
Best iteration: 0

Random seed: 60156508

Evaluation time : 25650.57901096344 sec [99.74 %]
Optimization time : 66.75476264953613 sec [0.26 %]
Iteration time : 25717.333773612976 sec [102.87 sec/iter]

2023-11-05 15:40:31,671 - AutoMBWrt - INFO - merge completed.
2023-11-05 15:40:32,474 - AutoMBWrt - INFO - injection disabled (hopefully).
"""

print("Recover Weights from console log: ")
print(raw_log)
print("log = weights = slider")

# sliders = sliders_in + [sl_M_00] + [sl_OUT] + sliders_out + [sl_TIME_EMBED] = sl_ALL_nat

# sl_ALL_nat = [*sl_INPUT, *sl_MID, sl_OUT, *sl_OUTPUT, sl_TIME_EMBED]
# sl_ALL = [*sl_INPUT, *sl_MID, *sl_OUTPUT, sl_TIME_EMBED, sl_OUT]

print("Repo1: https://github.com/Xerxemi/auto-MBW-rt")
print("Repo2: https://github.com/Xynonners/sd-webui-runtime-block-merge/blob/master/scripts/runtime_block_merge.py")

def on_save_checkpoint(*weights, ):
current_weights_nat = weights[:27]
weights_output_recipe = weights[27:]
print("current_weights_nat:")
print(current_weights_nat)
print("weights_output_recipe:")
print(f"{','.join([str(w) for w in weights_output_recipe])}\n")
print("Which is [*sl_INPUT, *sl_MID, *sl_OUTPUT, sl_OUT, sl_TIME_EMBED]")
print("However in code sl_ALL (Repo2): ")
print("sl_ALL = [*sl_INPUT, *sl_MID, *sl_OUTPUT, sl_TIME_EMBED, sl_OUT]")

def main(weights):
weights_s = weights.copy()
out = weights_s.pop(13)
time_embed = weights_s.pop(-1)
weights_s.append(out)
weights_s.append(time_embed)
print("weights:")
print(weights)
print("weights_s:")
print(weights_s) # sliders_in + [sl_M_00] + sliders_out + [sl_OUT] + [sl_TIME_EMBED] = !sl_ALL
on_save_checkpoint(*weights,*weights_s) # Merge is fine, recipe is bad.

sliders = list(range(0,27))

print("(Repo1): sliders = sliders_in + [sl_M_00] + [sl_OUT] + sliders_out + [sl_TIME_EMBED] = sl_ALL_nat")
print(sliders)

main(sliders)

print("Due to the recipe bug, you should swap OUT and TIME_EMBED on UI if you are reading the recipe.")

actual_recipe = "0.35,0.05,1.0,0.7,0.35,0.75,0.7,1.0,0.95,0.65,0.9,0.05,0.45,0.4,0.4,0.3,1.0,0.5,0.7,0.8,0.6,0.95,0.55,0.45,0.2,1.0,0.2"
print("Verify with Actual recipe: ")
print(actual_recipe)
4 changes: 2 additions & 2 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
if "SettingsInjector" in open(script_path, "r").read():
pass
else:
raise Exception("autoMBW [error]: runtime-block-merge extension missing injector. MERGING WILL NOT WORK - https://github.com/Xynonners/sd-webui-runtime-block-merge")
raise Exception("autoMBW [error]: runtime-block-merge extension missing injector. MERGING WILL NOT WORK - https://github.com/6DammK9/sd-webui-runtime-block-merge")
else:
raise Exception("autoMBW [error]: runtime-block-merge extension not found. MERGING WILL NOT WORK - https://github.com/Xynonners/sd-webui-runtime-block-merge")
raise Exception("autoMBW [error]: runtime-block-merge extension not found. MERGING WILL NOT WORK - https://github.com/6DammK9/sd-webui-runtime-block-merge")

if not os.path.isdir(os.path.join(__extensions__, msgspec.toml.decode(open(config_path, "rb").read())["extension_counterpart_lora"])):
raise Exception("autoMBW [error]: lora-block-weight extension not found. LoRA merging will not work - https://github.com/hako-mikan/sd-webui-lora-block-weight")
3 changes: 3 additions & 0 deletions metadata.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Extension]
Name=auto-MBW-rt
Requires=sd-webui-runtime-block-merge
8 changes: 8 additions & 0 deletions scripts/classifiers/THUDM/score_image_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
import math
import ImageReward as reward

from scripts.util.auto_mbw_rt_logger import logger_autombwrt as logger

def sigmoid(x):
return 1 / (1 + math.exp(-x))

model = None

def score(image, prompt="", reverse=False):
#I think it is the culprit or "locked score".
global model
if model == None:
logger.info("Loading ImageReward...")
model = reward.load("ImageReward-v1.0")
score_origin = model.score(prompt, image)
#Why it can be identical?
logger.debug(f"Image address: {image}")
logger.debug(f"Raw model score: {score_origin}")
if reverse:
score_origin = score_origin*-1
score = sigmoid(score_origin)
Expand Down
4 changes: 3 additions & 1 deletion scripts/classifiers/aesthetic/score_aes_B32_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def forward(self, x):
import safetensors
from transformers import CLIPModel, CLIPProcessor

from scripts.util.auto_mbw_rt_logger import logger_autombwrt as logger

dirname = os.path.dirname(__file__)
aesthetic_path = os.path.join(dirname, "aes-B32-v0.safetensors")
clip_name = 'openai/clip-vit-base-patch32'
Expand All @@ -46,6 +48,6 @@ def score(image, prompt="", reverse=False):
image_embeds = image_embeddings_direct(image, clipmodel, clipprocessor)
prediction = aes_model(torch.from_numpy(image_embeds).float().to('cuda'))
if reverse:
print("Reverse scoring not supported with this classifier. Are you sure you want to continue?")
logger.warning("Reverse scoring not supported with this classifier. Are you sure you want to continue?")
return prediction.item()

2 changes: 1 addition & 1 deletion scripts/classifiers/cafe_aesthetic/aesthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

ImageFile.LOAD_TRUNCATED_IMAGES = True

from webui import wrap_gradio_gpu_call
from modules.call_queue import wrap_gradio_gpu_call
from modules import shared, scripts, script_callbacks, ui
from modules import generation_parameters_copypaste as parameters_copypaste
import launch
Expand Down
4 changes: 3 additions & 1 deletion scripts/classifiers/cafe_aesthetic/score_cafe_aesthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from transformers import CLIPModel, CLIPProcessor
from scripts.classifiers.cafe_aesthetic.aesthetic import judge

from scripts.util.auto_mbw_rt_logger import logger_autombwrt as logger

def score(image, prompt="", reverse=False):
aesthetic, _, _ = judge(image)
if reverse:
print("Reverse scoring not supported with this classifier. Are you sure you want to continue?")
logger.warning("Reverse scoring not supported with this classifier. Are you sure you want to continue?")
return aesthetic["aesthetic"]

4 changes: 3 additions & 1 deletion scripts/classifiers/cafe_aesthetic/score_cafe_waifu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from transformers import CLIPModel, CLIPProcessor
from scripts.classifiers.cafe_aesthetic.aesthetic import judge

from scripts.util.auto_mbw_rt_logger import logger_autombwrt as logger

def score(image, prompt="", reverse=False):
_, _, waifu = judge(image)
if reverse:
print("Reverse scoring not supported with this classifier. Are you sure you want to continue?")
logger.warning("Reverse scoring not supported with this classifier. Are you sure you want to continue?")
return waifu["waifu"]

2 changes: 1 addition & 1 deletion scripts/classifiers/hybridIQA/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def resnet152_backbone(lda_out_channels, in_chn, pretrained=False, **kwargs):

def weights_init_xavier(m):
classname = m.__class__.__name__
# print(classname)
# logger.debug(classname)
# if isinstance(m, nn.Conv2d):
if classname.find('Conv') != -1:
init.kaiming_normal_(m.weight.data)
Expand Down
4 changes: 3 additions & 1 deletion scripts/classifiers/hybridIQA/score_hybridIQA_V1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import scripts.classifiers.hybridIQA.models as models
import numpy as np

from scripts.util.auto_mbw_rt_logger import logger_autombwrt as logger

# state_name = "hyperIQA_hybrid_latest.pth"
# dirname = os.path.dirname(__file__)
# pth_path = os.path.join(dirname, state_name)
Expand All @@ -27,7 +29,7 @@
# random crop 25 patches and calculate mean quality score
def score(image, prompt="", reverse=False):
if reverse:
print("Reverse scoring not supported with this classifier. Are you sure you want to continue?")
logger.warning("Reverse scoring not supported with this classifier. Are you sure you want to continue?")
image = image.convert("RGB")
pred_scores = []
for i in range(25):
Expand Down
4 changes: 3 additions & 1 deletion scripts/classifiers/laion_v1/score_laion_avs1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import clip
import os

from scripts.util.auto_mbw_rt_logger import logger_autombwrt as logger

state_name = "sa_0_4_vit_l_14_linear.pth"
dirname = os.path.dirname(__file__)
aesthetic_path = os.path.join(dirname, state_name)
Expand Down Expand Up @@ -44,6 +46,6 @@ def score(image, prompt="", reverse=False):
image_features = get_image_features(image)
score = predictor(torch.from_numpy(image_features).to(device).float())
if reverse:
print("Reverse scoring currently not supported with this classifier. Are you sure you want to continue?")
logger.warning("Reverse scoring currently not supported with this classifier. Are you sure you want to continue?")
return score.item()

Loading