mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
re-update lcm-convert.py
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import argparse
|
||||
import torch
|
||||
from diffusers import StableDiffusionPipeline, StableDiffusionXLPipeline, AutoPipelineForText2Image, LCMScheduler
|
||||
@@ -5,11 +6,13 @@ from diffusers import StableDiffusionPipeline, StableDiffusionXLPipeline, AutoPi
|
||||
parser = argparse.ArgumentParser("lcm_convert")
|
||||
parser.add_argument("--name", help="Name of the new LCM model", type=str)
|
||||
parser.add_argument("--model", help="A model to convert", type=str)
|
||||
parser.add_argument("--lora-scale", default=1.0, help="Strenght of the LCM", type=float)
|
||||
parser.add_argument("--huggingface", action="store_true", help="Use Hugging Face models instead of safetensors models")
|
||||
parser.add_argument("--upload", action="store_true", help="Upload the new LCM model to Hugging Face")
|
||||
parser.add_argument("--no_save", action="store_true", help="Don't save the new LCM model to local disk")
|
||||
parser.add_argument("--no-half", action="store_true", help="Convert the new LCM model to FP32")
|
||||
parser.add_argument("--no-save", action="store_true", help="Don't save the new LCM model to local disk")
|
||||
parser.add_argument("--sdxl", action="store_true", help="Use SDXL models")
|
||||
parser.add_argument("--ssd_1b", action="store_true", help="Use SSD-1B models")
|
||||
parser.add_argument("--ssd-1b", action="store_true", help="Use SSD-1B models")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -28,15 +31,25 @@ elif args.ssd_1b:
|
||||
pipeline.load_lora_weights("latent-consistency/lcm-lora-ssd-1b")
|
||||
else:
|
||||
pipeline.load_lora_weights("latent-consistency/lcm-lora-sdv1-5")
|
||||
pipeline.fuse_lora()
|
||||
pipeline.fuse_lora(lora_scale=args.lora_scale)
|
||||
|
||||
#components = pipeline.components
|
||||
#pipeline = LatentConsistencyModelPipeline(**components)
|
||||
|
||||
pipeline = pipeline.to(dtype=torch.float16)
|
||||
if args.no_half:
|
||||
pipeline = pipeline.to(dtype=torch.float32)
|
||||
else:
|
||||
pipeline = pipeline.to(dtype=torch.float16)
|
||||
print(pipeline)
|
||||
|
||||
if not args.no_save:
|
||||
pipeline.save_pretrained(args.name, variant="fp16")
|
||||
os.makedirs(f"models--local--{args.name}/snapshots")
|
||||
if args.no_half:
|
||||
pipeline.save_pretrained(f"models--local--{args.name}/snapshots/{args.name}")
|
||||
else:
|
||||
pipeline.save_pretrained(f"models--local--{args.name}/snapshots/{args.name}", variant="fp16")
|
||||
if args.upload:
|
||||
pipeline.push_to_hub(args.name, variant="fp16")
|
||||
if args.no_half:
|
||||
pipeline.push_to_hub(args.name)
|
||||
else:
|
||||
pipeline.push_to_hub(args.name, variant="fp16")
|
||||
Reference in New Issue
Block a user