fix makelora
parent
82009e6c9e
commit
5c7d67bc33
|
|
@ -287,16 +287,22 @@ def makelora(model_a,model_b,dim,saveto,settings,alpha,beta,save_precision,calc_
|
|||
return "ERROR: No model Selected"
|
||||
gc.collect()
|
||||
|
||||
currentinfo = shared.sd_model.sd_checkpoint_info
|
||||
try:
|
||||
currentinfo = shared.sd_model.sd_checkpoint_info
|
||||
except:
|
||||
currentinfo = None
|
||||
|
||||
checkpoint_info = sd_models.get_closet_checkpoint_match(model_a)
|
||||
load_model(checkpoint_info)
|
||||
|
||||
model = shared.sd_model
|
||||
print(type(model).__name__)
|
||||
print("XL" in type(model).__name__)
|
||||
|
||||
is_sdxl = hasattr(model, 'conditioner')
|
||||
is_sd2 = not model.is_sdxl and hasattr(model.cond_stage_model, 'model')
|
||||
is_sd1 = not model.is_sdxl and not model.is_sd2
|
||||
is_sdxl = type(model).__name__ == "StableDiffusionXL" or getattr(model,'is_sdxl', False)
|
||||
is_sd2 = type(model).__name__ == "StableDiffusion2" or getattr(model,'is_sd2', False)
|
||||
is_sd1 = type(model).__name__ == "StableDiffusion" or getattr(model,'is_sd1', False)
|
||||
is_flux = type(model).__name__ == "Flux" or getattr(model,'is_flux', False)
|
||||
|
||||
print(f"Detected model type: SDXL: {is_sdxl}, SD2.X: {is_sd2}, SD1.X: {is_sd1}")
|
||||
|
||||
|
|
@ -333,7 +339,8 @@ def makelora(model_a,model_b,dim,saveto,settings,alpha,beta,save_precision,calc_
|
|||
|
||||
result = ext.svd(args)
|
||||
|
||||
load_model(currentinfo)
|
||||
if currentinfo:
|
||||
load_model(currentinfo)
|
||||
return result
|
||||
|
||||
##############################################################
|
||||
|
|
@ -482,6 +489,8 @@ def merge_lora_models(models, ratios, sets, locon, calc_precision):
|
|||
alpha = alphas[lora_module_name]
|
||||
|
||||
ratio = ratios[blockfromkey(key, keylist, isv2)]
|
||||
#print(key,blockfromkey(key, keylist, isv2))
|
||||
|
||||
if "same to Strength" in sets:
|
||||
ratio, fugou = (ratio ** 0.5, 1) if ratio > 0 else (abs(ratio) ** 0.5, -1)
|
||||
|
||||
|
|
@ -851,7 +860,7 @@ def pluslora(lnames,loraratios,settings,output,model,save_precision,calc_precisi
|
|||
return result + add
|
||||
|
||||
def newpluslora(theta_0,filenames,lweis,names, isxl,isv2, keychanger):
|
||||
nets.load_networks(names, [1]* len(names),[1]* len(names), isxl, isv2)
|
||||
nets.load_networks(names, [1]* len(names),[1]* len(names), [1]* len(names), isxl, isv2)
|
||||
|
||||
for l, loaded in enumerate(nets.loaded_networks):
|
||||
for n, name in enumerate(names):
|
||||
|
|
@ -1135,10 +1144,12 @@ def blockfromkey(key,keylist,isv2 = False):
|
|||
fullkey = fullkey.replace("lora_unet", "diffusion_model")
|
||||
elif "lora_te1_text_model" in fullkey:
|
||||
fullkey = fullkey.replace("lora_te1_text_model", "0_transformer_text_model")
|
||||
|
||||
for i,n in enumerate(keylist):
|
||||
if n in fullkey: return i
|
||||
|
||||
if "1_model_transformer_resblocks_" in fullkey:return 0
|
||||
|
||||
for i,n in enumerate(keylist):
|
||||
if n in fullkey: return i
|
||||
|
||||
print(f"ERROR:Block is not deteced:{fullkey}")
|
||||
return 0
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue