From 84cb2d63bb640570e8c60a507c342cae1ff42ed6 Mon Sep 17 00:00:00 2001 From: loulanyue <260355617@qq.com> Date: Sat, 22 Aug 2026 08:13:12 +0800 Subject: [PATCH] Fix LCM LoRA SDXL distillation PEFT state dict loading and saving Keep native PEFT state dict without routing through convert_state_dict_to_diffusers, ensuring both intermediate validation and saved checkpoints preserve all attention and convolutional adapters when loaded into StableDiffusionXLPipeline. Fixes #14548 --- .../train_lcm_distill_lora_sdxl.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/consistency_distillation/train_lcm_distill_lora_sdxl.py b/examples/consistency_distillation/train_lcm_distill_lora_sdxl.py index cd9f6c1b7aa1..d6b868d02e20 100644 --- a/examples/consistency_distillation/train_lcm_distill_lora_sdxl.py +++ b/examples/consistency_distillation/train_lcm_distill_lora_sdxl.py @@ -56,7 +56,6 @@ from diffusers.training_utils import cast_training_params, resolve_interpolation_mode from diffusers.utils import ( check_min_version, - convert_state_dict_to_diffusers, convert_unet_state_dict_to_peft, is_wandb_available, ) @@ -121,7 +120,7 @@ def log_validation(vae, args, accelerator, weight_dtype, step, unet=None, is_fin if unet is None: raise ValueError("Must provide a `unet` when doing intermediate validation.") unet = accelerator.unwrap_model(unet) - state_dict = convert_state_dict_to_diffusers(get_peft_model_state_dict(unet)) + state_dict = get_peft_model_state_dict(unet) to_load = state_dict else: to_load = args.output_dir @@ -888,9 +887,7 @@ def main(args): def save_model_hook(models, weights, output_dir): if accelerator.is_main_process: unet_ = accelerator.unwrap_model(unet) - # also save the checkpoints in native `diffusers` format so that it can be easily - # be independently loaded via `load_lora_weights()`. - state_dict = convert_state_dict_to_diffusers(get_peft_model_state_dict(unet_)) + state_dict = get_peft_model_state_dict(unet_) StableDiffusionXLPipeline.save_lora_weights(output_dir, unet_lora_layers=state_dict) for _, model in enumerate(models): @@ -1442,7 +1439,7 @@ def compute_time_ids(original_size, crops_coords_top_left): accelerator.wait_for_everyone() if accelerator.is_main_process: unet = accelerator.unwrap_model(unet) - unet_lora_state_dict = convert_state_dict_to_diffusers(get_peft_model_state_dict(unet)) + unet_lora_state_dict = get_peft_model_state_dict(unet) StableDiffusionXLPipeline.save_lora_weights(args.output_dir, unet_lora_layers=unet_lora_state_dict) if args.push_to_hub: