lora  by cloneofsimo

LoRA tool for fast diffusion fine-tuning

created 2 years ago
7,403 stars

Top 7.1% on sourcepulse

GitHubView on GitHub
Project Summary

This repository provides a method for efficiently fine-tuning diffusion models, specifically Stable Diffusion, for text-to-image generation. It targets users who want to customize models with their own datasets, offering significantly faster training and much smaller output files compared to full fine-tuning, enabling easier sharing and experimentation.

How It Works

The core innovation is Low-Rank Adaptation (LoRA), which injects trainable low-rank matrices into the pre-trained model's weights. Instead of updating the entire weight matrix $W$, LoRA trains smaller matrices $A$ and $B$ such that $\Delta W = AB^T$. This drastically reduces the number of trainable parameters, leading to faster training and compact model outputs (1MB-6MB). The method can be applied to the UNet, Text Encoder, or both, and integrates with techniques like Dreambooth and Pivotal Tuning Inversion for enhanced results.

Quick Start & Requirements

  • Install: pip install git+https://github.com/cloneofsimo/lora.git
  • Prerequisites: Python, PyTorch, Hugging Face diffusers, transformers, accelerate, xformers (recommended for performance). CUDA-enabled GPU is highly recommended for practical training.
  • Example CLI: lora_pti --pretrained_model_name_or_path=... --instance_data_dir=... --output_dir=... (see README for full parameters).
  • Demo: Integrated into Huggingface Spaces via Gradio.
  • Colab: Example notebooks are available.

Highlighted Details

  • Fine-tunes Stable Diffusion models up to twice as fast as Dreambooth.
  • Generates very small LoRA files (1MB-6MB), ideal for sharing.
  • Supports fine-tuning UNet, Text Encoder, and CLIP.
  • Offers merging capabilities for combining multiple LoRAs or merging LoRAs with base models.
  • Integrates Pivotal Tuning Inversion for improved results.
  • Supports safetensor format and xformers for performance.

Maintenance & Community

The project is actively developed, with frequent updates noted in the README. It's integrated into the Hugging Face diffusers library. Community discussions and tips are encouraged via PRs.

Licensing & Compatibility

The repository's license is not explicitly stated in the README. However, its integration with Hugging Face diffusers suggests compatibility with common open-source workflows. Users should verify licensing for commercial use.

Limitations & Caveats

The README mentions that extensive comparisons for performance against full fine-tuning are future work. Some features like Kronecker product adaptation and time-aware fine-tuning are listed as TODOs. User-friendliness for non-programmers and documentation improvements are also noted as areas for development.

Health Check
Last commit

1 year ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
97 stars in the last 90 days

Explore Similar Projects

Starred by Tobi Lutke Tobi Lutke(Cofounder of Shopify), Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), and
2 more.

xTuring by stochasticai

0.0%
3k
SDK for fine-tuning and customizing open-source LLMs
created 2 years ago
updated 10 months ago
Feedback? Help us improve.