It is a distilled consistency adapter for
stable-diffusion-xl-base-1.0
that allows
to reduce the number of inference steps to only between
2 - 8 steps
.
LCM-LoRA is supported in 🤗 Hugging Face Diffusers library from version v0.23.0 onwards. To run the model, first
install the latest version of the Diffusers library as well as
peft
,
accelerate
and
transformers
.
audio dataset from the Hugging Face Hub:
Note: For detailed usage examples we recommend you to check out our official
LCM-LoRA docs
Text-to-Image
The adapter can be loaded with it's base model
stabilityai/stable-diffusion-xl-base-1.0
. Next, the scheduler needs to be changed to
LCMScheduler
and we can reduce the number of inference steps to just 2 to 8 steps.
Please make sure to either disable
guidance_scale
or use values between 1.0 and 2.0.
import torch
from diffusers import LCMScheduler, AutoPipelineForText2Image
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
adapter_id = "latent-consistency/lcm-lora-sdxl"
pipe = AutoPipelineForText2Image.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16")
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.to("cuda")
# load and fuse lcm lora
pipe.load_lora_weights(adapter_id)
pipe.fuse_lora()
prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"# disable guidance_scale by passing 0
image = pipe(prompt=prompt, num_inference_steps=4, guidance_scale=0).images[0]
Inpainting
LCM-LoRA can be used for inpainting as well.
import torch
from diffusers import AutoPipelineForInpainting, LCMScheduler
from diffusers.utils import load_image, make_image_grid
pipe = AutoPipelineForInpainting.from_pretrained(
"diffusers/stable-diffusion-xl-1.0-inpainting-0.1",
torch_dtype=torch.float16,
variant="fp16",
).to("cuda")
# set scheduler
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
# load LCM-LoRA
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
pipe.fuse_lora()
# load base and mask image
init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint.png").resize((1024, 1024))
mask_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint_mask.png").resize((1024, 1024))
prompt = "a castle on top of a mountain, highly detailed, 8k"
generator = torch.manual_seed(42)
image = pipe(
prompt=prompt,
image=init_image,
mask_image=mask_image,
generator=generator,
num_inference_steps=5,
guidance_scale=4,
).images[0]
make_image_grid([init_image, mask_image, image], rows=1, cols=3)
Combine with styled LoRAs
LCM-LoRA can be combined with other LoRAs to generate styled-images in very few steps (4-8). In the following example, we'll use the LCM-LoRA with the
papercut LoRA
.
To learn more about how to combine LoRAs, refer to
this guide
.
The inference parameters in this example might not work for all examples, so we recommend you to try different values for `num_inference_steps`, `guidance_scale`, `controlnet_conditioning_scale` and `cross_attention_kwargs` parameters and choose the best one.
T2I Adapter
This example shows how to use the LCM-LoRA with the
Canny T2I-Adapter
and SDXL.
lcm-lora-sdxl huggingface.co is an AI model on huggingface.co that provides lcm-lora-sdxl's model effect (), which can be used instantly with this latent-consistency lcm-lora-sdxl model. huggingface.co supports a free trial of the lcm-lora-sdxl model, and also provides paid use of the lcm-lora-sdxl. Support call lcm-lora-sdxl model through api, including Node.js, Python, http.
lcm-lora-sdxl huggingface.co is an online trial and call api platform, which integrates lcm-lora-sdxl's modeling effects, including api services, and provides a free online trial of lcm-lora-sdxl, you can try lcm-lora-sdxl online for free by clicking the link below.
latent-consistency lcm-lora-sdxl online free url in huggingface.co:
lcm-lora-sdxl is an open source model from GitHub that offers a free installation service, and any user can find lcm-lora-sdxl on GitHub to install. At the same time, huggingface.co provides the effect of lcm-lora-sdxl install, users can directly use lcm-lora-sdxl installed effect in huggingface.co for debugging and trial. It also supports api for free installation.