LCM-LoRA: A Universal Stable-Diffusion Acceleration Module
Simian Luo, Yiqin Tan, Suraj Patil, Daniel Gu, Patrick von Platen, Apolinário Passos, Longbo Huang, Jian Li, Hang Zhao
Introduction
Latent Diffusion Models (LDMs) (Rombach et al., 2022) have been pivotal in generating highly detailed and creative imagery from various inputs such as text and sketches. Despite their success, the slow reverse sampling process inherent to LDMs hampers real-time application, compromising the user experience. Current open-source models and acceleration techniques have yet to bridge the gap to real-time generation on standard consumer GPUs. Efforts to accelerate LDMs generally fall into two categories: the first involves advanced ODE-Solvers, like DDIM (Song et al., 2020), DPM-Solver (Lu et al., 2022a) and DPM-Solver++ (Lu et al., 2022b), to expedite the generation process. The second strategy involves distillation of LDMs to streamline their functioning. The ODE-Solver methods, despite reducing the number of inference steps needed, still demand a significant computational overhead, especially when incorporating classifier-free guidance (Ho & Salimans, 2022). Meanwhile, distillation methods such as Guided-Distill (Meng et al., 2023), although promising, face practical limitations due to their intensive computational requirements. The quest for a balance between speed and quality in LDM-generated imagery continues to be a challenge in the field.
Recently, Latent Consistency Models (LCMs) (Luo et al., 2023) have emerged, inspired by Consistency Models (CMs) (Song et al., 2023), as a solution to the slow sampling issue in image generation. LCMs approach the reverse diffusion process by treating it as an augmented probability flow ODE (PF-ODE) problem. They innovatively predict the solution in the latent space, bypassing the need for iterative solutions through numerical ODE-Solvers. This results in a remarkably efficient synthesis of high-resolution images, taking only 1 to 4 inference steps. Additionally, LCMs stand out in terms of distillation efficiency, requiring merely 32 A100 training hours for a minimal-step inference.
Building on this, Latent Consistency Finetuning (LCF) (Luo et al., 2023) has been developed as a method to fine-tune pre-trained LCMs without starting from the teacher diffusion model. For specialized datasets—like those for anime, photo-realistic, or fantasy images—additional steps are necessary, such as employing Latent Consistency Distillation (LCD) (Luo et al., 2023) to distill a pre-trained LDM into an LCM or directly fine-tuning an LCM using LCF. However, this extra training can be a barrier to the quick deployment of LCMs across diverse datasets, posing the critical question of whether fast, training-free inference on custom datasets is attainable.
To answer the above question, we introduce LCM-LoRA, a universal training-free acceleration module that can be directly plugged into various Stable-Diffusion (SD) (Rombach et al., 2022) fine-tuned models or SD LoRAs (Hu et al., 2021) to support fast inference with minimal steps. Compared to earlier numerical probability flow ODE (PF-ODE) solvers such as DDIM (Song et al., 2020), DPM-Solver (Lu et al., 2022a), and DPM-Solver++ (Lu et al., 2022b), LCM-LoRA represents a novel class of neural network-based PF-ODE solvers module. It demonstrates robust generalization capabilities across various fine-tuned SD models and LoRAs.
Related Work
Song et al. (2023) have showcased the remarkable potential of consistency models (CMs), a novel class of generative models that enhance sampling efficiency without sacrificing the quality of the output. These models employ a consistency mapping technique that deftly maps points along the Ordinary Differential Equation (ODE) trajectory to their origins, thus enabling expeditious one-step generation. Their research specifically targets image generation tasks on ImageNet 64x64 (Deng et al., 2009) and LSUN 256x256 (Yu et al., 2015), demonstrating CMs' effectiveness in these domains. Further advancing the field, Luo et al. (2023) has pioneered latent consistency models (LCMs) within the text-to-image synthesis landscape. By viewing the guided reverse diffusion process as the resolution of an augmented Probability Flow ODE (PF-ODE), LCMs adeptly predict the solution of such ODEs in latent space. This innovative approach significantly reduces the need for iterative steps, thereby enabling the rapid generation of high-fidelity images from text inputs and setting a new standard for state-of-the-art performance on LAION-5B-Aesthetics dataset (Schuhmann et al., 2022).
Parameter-Efficient Fine-Tuning
Parameter-Efficient Fine-Tuning (PEFT) (Houlsby et al., 2019) enables the customization of pre-existing models for particular tasks while limiting the number of parameters that need retraining. This reduces both computational load and storage demands. Among the assorted techniques under the PEFT umbrella, Low-Rank Adaptation (LoRA) (Hu et al., 2021) stands out. LoRA's strategy involves training a minimal set of parameters through the integration of low-rank matrices, which succinctly represent the required adjustments in the model's weights for fine-tuning. In practice, this means that during task-specific optimization, only these matrices are learned and the bulk of pre-trained weights are left unchanged. Consequently, LoRA significantly trims the volume of parameters to be modified, thereby enhancing computational efficiency and permitting model refinement with considerably less data.
Task Arithmetic in Pretrained Models
Task arithmetic (Ilharco et al., 2022; Ortiz-Jimenez et al., 2023; Zhang et al., 2023) has become a notable method for enhancing the abilities of pre-trained models, offering a cost-effective and scalable strategy for direct edits in weight space. By applying fine-tuned weights of different tasks to a model, researchers can improve its performance on these tasks or induce forgetting by negating them. Despite its promise, the understanding of task arithmetic's full potential and the principles that underlie it remain areas of active exploration.
LCM-LoRA
The Latent Consistency Model (LCM) (Luo et al., 2023) is trained using a one-stage guided distillation method, leveraging a pre-trained auto-encoder's latent space to distill a guided diffusion model into an LCM. This process involves solving an augmented Probability Flow ODE (PF-ODE), a mathematical formulation that ensures the generated samples follow a trajectory that results in high-quality images. The distillation focuses on maintaining the fidelity of these trajectories while significantly reducing the number of required sampling steps. The method includes innovations like the Skipping-Steps technique to quicken convergence. The pseudo-code of LCD is provided in Algorithm 1.
In this equation, represents the output vector, and the outputs of and are added together after being multiplied by the input . By decomposing the full parameter matrix into the product of two low-rank matrices, LoRA significantly reduces the number of trainable parameters, thereby lowering memory usage. Table 1 compares the total number of parameters in the full model with the trainable parameters when using the LoRA technique. It is evident that by incorporating the LoRA technique during the LCM distillation process, the quantity of trainable parameters is significantly reduced, effectively decreasing the memory requirements for training.
Luo et al. (2023) primarily distilled the base stable diffusion model, such as SD-V1.5 and SD-V2.1. We extended this distillation process to more powerful models with enhanced text-to-image capabilities and larger parameter counts, including SDXL (Podell et al., 2023) and SSD-1B (Segmind., 2023). Our experiments demonstrate that the LCD paradigm adapts well to larger models. The generated results of different models are displayed in Figure 2.
2 LCM-LoRA as Universal Acceleratiion Module
Based on parameter-efficient fine-tuning techniques, such as LoRA, one can fine-tune pretrained models with substantially reduced memory requirements. Within the framework of LoRA, the resultant LoRA parameters can be seamlessly integrated into the original model parameters. In Section 3.1, we demonstrate the feasibility of employing LoRA for the distillation process of Latent Consistency Models (LCMs). On the other hand, one can fine-tune on customized datasets for specific task-oriented applications. There is now a broad array of fine-tuning parameters available for selection and utilization. We discover that the LCM-LoRA parameters can be directly combined with other LoRA parameters fine-tuned on datasets of particular styles. Such an amalgamation yields a model capable of generating images in specific styles with minimal sampling steps, without the need for any further training. As shown in Figure 1, denote the LCM-LoRA fine-tuned parameters as , which is identified as the ``acceleration vector", and the LoRA parameters fine-tuned on customized dataset as , which is the ``style vector", we find that an LCM which generates customized images can be obtained as
is the linear combination of acceleration vector and style vector . Here and are hyperparameters. The generation results of the specific style LoRA parameters and their combination with LCM-LoRA parameters are shown in Figure 3. Note that we do not make further training on the combined parameters.
Conclusion
We present LCM-LoRA, a universal training-free acceleration module for Stable-Diffusion (SD). LCM-LoRA can serve as an independent and efficient neural network-based solver module to predict the solution of PF-ODE, enabling fast inference with minimal steps on various finetuned SD models and SD LoRAs. Extensive experiments on text-to-image generation have demonstrated LCM-LoRA's strong generalization capabilities and superiority.
Contribution & Acknowledgement
This work builds upon Simian Luo and Yiqin Tan's Latent Consistency Models (LCMs) (Luo et al., 2023). Based on LCMs, Simian Luo wrote the original LCM-SDXL distillation code, and together with Yiqin Tan, primarily completed this technical report. Yiqin Tan discovered the arithmetic property of LCM parameters. Suraj Patil first completed the training of LCM-LoRA, discovering its strong generalization abilities, and conducted most of the training. Suraj Patil and Daniel Gu conducted excellent refactoring of the original LCM-SDXL codebase and improved training efficiency, seamlessly integrating it into the Diffusers library. Patrick von Platen revised and polished this technical report, as well as integrating LCM into the Diffusers library. Longbo Huang, Jian Li, Hang Zhao co-advised the original LCMs paper, and polished this technical report. We further thanks Apolinário Passos and Patrick von Platen for making excellent LCMs demo and deployment. We also want to thank Sayak Paul and Pedro Cuenca for helping with writing documentation as well as Radamés Ajna for creating demos. We appreciate the computing resources provided by the Hugging Face Diffusers teams to support our experiments. Finally, we value the insightful discussions from LCM community members.