"""Load the step-1600 Wan-Fun generator adapter through the evaluated loader.""" from perflow_lora import apply_adapter_strength, attach_wan_lora def load_wan_fun_lora(transformer, checkpoint_path, strength=1.0): """Attach once to a freshly loaded native VideoX-Fun 5B Control transformer. ``checkpoint_path`` is the downloaded ``generator_lora.pt``. The returned receipt proves exact target coverage. Call before CPU/group offloading. Safetensors is a separate PEFT-format export, not this function's input. """ name = "wan_fun_dmd_step1600" if any(name in getattr(m, "lora_A", {}) for m in transformer.modules()): raise ValueError("Adapter already installed; load a fresh transformer") conv = transformer.patch_embedding if conv.in_channels != 148: raise ValueError("Expected the complete 148-channel Wan2.2-Fun-5B-Control transformer") report = attach_wan_lora( transformer, checkpoint_path, style="native", expected_rank=64, lora_alpha=64, adapter_name=name, checkpoint_kind="wan_fun_control_dmd", report_prefix="WAN_FUN_LORA", expected_step=1600, enabled=True, ) report.update(apply_adapter_strength(transformer, adapter_name=name, strength=strength)) return report