Open linoytsaban opened 4 months ago
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.
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.
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. Can I a PR on huggingface with the converted loras?
Same params
prompt = "cinematic picture of an astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
negative_prompt = "3d render, carton, drawing, art, low light, blur, pixelated, low resolution, black and white"
num_inference_steps = 2
height = 512
width = height
guidance_scale = 0
seed = 2341412232
4step-normal guidance 7.5
8step-normal guidance 7.5
2step guidance 0
4step guidance 0
@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! I have seen some promising results, and I might upload them in the coming days!
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 DDPMScheduler
?
@radames Yes, DDIM. TCDScheduler should also work.
I noticed you've converted the weights! yeah! thanks BTW the TCDScheduler works better with SDXL!!
DDPMScheduler TCDScheduler
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! I'll setup a Space demo for you later today and transfer to your name! thanks
Many thanks @radames. I sincerely appreciate your attention and help!
Final question, for the new LCM LIke Lora
would it make sense to use the same params?
num_train_timesteps=1000,
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear",
timestep_spacing="trailing",
)
Making a Space demo with all Lora Options
Thanks @radames ! The demo looks awesome!
For the LCM like LoRA, it should use LCM scheduler and can flexible choose the step of sampling.
@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! I have seen some promising results, and I might upload them in the coming days!
@G-U-N any update on this? Great work btw <3
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")
pipe.load_lora_weights(pcm_lora_weight_convert) 用自己è®ç»ƒçš„sdxlçš„pcm loraåŠ è½½æŠ¥é”™ï¼Œ*** IndexError: list index out of range
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")
pipe.load_lora_weights(pcm_lora_weight_convert) 用自己è®ç»ƒçš„sdxlçš„pcm loraåŠ è½½æŠ¥é”™ï¼Œ*** IndexError: list index out of range
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: