-
Notifications
You must be signed in to change notification settings - Fork 17
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
[Inference Issue] ValueError when trying to load LoRA weights with diffusers #2
Comments
The weights were not converted. I will upload the converted weights soon. Try this from safetensors.torch import load_file, save_file
def get_module_kohya_state_dict(module, prefix: str, dtype: torch.dtype, adapter_name: str = "default"):
kohya_ss_state_dict = {}
for peft_key, weight in module.items():
kohya_key = peft_key.replace("base_model.model", prefix)
kohya_key = kohya_key.replace("lora_A", "lora_down")
kohya_key = kohya_key.replace("lora_B", "lora_up")
kohya_key = kohya_key.replace(".", "_", kohya_key.count(".") - 2)
kohya_ss_state_dict[kohya_key] = weight.to(dtype)
# Set alpha parameter
if "lora_down" in kohya_key:
alpha_key = f'{kohya_key.split(".")[0]}.alpha'
kohya_ss_state_dict[alpha_key] = torch.tensor(8).to(dtype)
return kohya_ss_state_dict
pcm_lora_weight = load_file(pcm_lora_path)
pcm_lora_weight_convert = get_module_kohya_state_dict(pcm_lora_weight, "lora_unet", weight_dtype)
pipe.load_lora_weights(pcm_lora_weight_convert)
save_file(pcm_lora_weight_convert, "converted_pcm_lora.safetensors") |
Also set scheduler=DDIMScheduler(
num_train_timesteps=1000,
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear",
timestep_spacing="trailing",
) # DDIM should just work well. See our discussion on parameterization in the paper. |
thanks @G-U-N , do we have to use the modified DDIMScheduler from here? https://github.com/G-U-N/Phased-Consistency-Model/blob/master/code/text_to_image_sd15/scheduling_ddpm_modified.py |
@radames. Don't need that for inference. I just add the `noise_travel' function in the original DDPM implementation of diffusers for training convenience. |
We can just use this scheduler for inference. I have thought about a more reasonable scheduler design: You can image that as a series small LCM scheduler. Within each small LCM scheduler, we can do inference through stochastic inference. Cross different schedulers, we can apply the deterministic algorithm. But I think that will make the whole thing a bit too complex. |
Great! I works! Got some weird results for the normal cfg loras, but for smallcfg it was consistent. Same params
|
@radames. Yes, many thanks for testing! For the results of normal CFG, I just realize some of my implementation is flawed. And I just find a better way to do that! |
perfect! Please let us know if you want to setup a demo o HF Spaces, I'll be happy to kickstarted this for you and transfer to your profile! |
hi @G-U-N , for SDXL do I use the same params for the |
@radames Yes, DDIM. TCDScheduler should also work. |
Hi @radames. It does not look right with DDPM. Both setting DDIM with DDIMScheduler(
num_train_timesteps=1000,
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear",
timestep_spacing="trailing",
) and using TCD should get good results. |
DDPM is a stochastic scheduler in nature, which is not aligned with the training of PCM LoRA. |
Reasons for DDPM not getting good results:
|
yes that makes sense! thanks for the insight and amazing working! |
Many thanks @radames. I sincerely appreciate your attention and help! |
Thanks @radames ! The demo looks awesome! For the LCM like LoRA, it should use LCM scheduler and can flexible choose the step of sampling. |
pipe.load_lora_weights(pcm_lora_weight_convert) |
Problem solved |
Hey!
Congrats on you work, and thanks a lot of sharing it 🤗
When trying to use the sd1.5 and sdxl checkpoints on the hub for inference with
diffusers
, I got this following error when callingload_lora_weights:
The text was updated successfully, but these errors were encountered: