diff --git a/scripts/kohyas/sdxl_model_util.py b/scripts/kohyas/sdxl_model_util.py index d5254b9..33c179a 100644 --- a/scripts/kohyas/sdxl_model_util.py +++ b/scripts/kohyas/sdxl_model_util.py @@ -134,6 +134,9 @@ def convert_key(key): return new_sd, logit_scale +delkeys =[ +'text_model.embeddings.position_ids' +] # load state_dict without allocating new tensors def _load_state_dict_on_device(model, state_dict, device, dtype=None): @@ -141,12 +144,14 @@ def _load_state_dict_on_device(model, state_dict, device, dtype=None): missing_keys = list(model.state_dict().keys() - state_dict.keys()) unexpected_keys = list(state_dict.keys() - model.state_dict().keys()) + unexpected_keys = list(set(unexpected_keys) - set(delkeys)) + # similar to model.load_state_dict() if not missing_keys and not unexpected_keys: for k in list(state_dict.keys()): set_module_tensor_to_device(model, k, device, value=state_dict.pop(k), dtype=dtype) return "" - + # error_msgs error_msgs: List[str] = [] if missing_keys: diff --git a/scripts/mergers/pluslora.py b/scripts/mergers/pluslora.py index 0bc42b5..db580da 100644 --- a/scripts/mergers/pluslora.py +++ b/scripts/mergers/pluslora.py @@ -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 ##############################################################