Lora-for-Diffusers  by haofanwang

Tutorial for using LoRA within the Diffusers framework

created 2 years ago
813 stars

Top 44.4% on sourcepulse

GitHubView on GitHub
Project Summary

This repository provides a simplified tutorial and conversion scripts for integrating LoRA (Low-Rank Adaptation) models into the Hugging Face diffusers framework, targeting AI generation researchers and developers. It aims to make using LoRA weights, commonly found in .safetensors format from communities like Civitai, straightforward within diffusers for custom model fine-tuning and inference.

How It Works

The project addresses the incompatibility of .safetensors LoRA weights with the diffusers library by providing custom Python scripts. These scripts extract LoRA weights from .safetensors files and directly merge them into the diffusers compatible base model's UNet attention layers. This approach avoids full model conversion, offering a lightweight method to apply LoRA adaptations. The training section leverages diffusers' train_text_to_image_lora.py script, demonstrating efficient fine-tuning with minimal parameters.

Quick Start & Requirements

  • Install safetensors: pip install safetensors
  • Requires Python and PyTorch.
  • GPU with CUDA is recommended for training and inference.
  • Official diffusers library is a core dependency.
  • Links: Hugging Face Diffusers, Civitai

Highlighted Details

  • Simplifies loading .safetensors LoRA weights into diffusers.
  • Provides scripts for converting full .ckpt or .safetensors models to diffusers format.
  • Includes example code for training LoRA models using accelerate and diffusers.
  • Demonstrates using LoRA weights with StableDiffusionPipeline for inference.

Maintenance & Community

  • The project has submitted Pull Requests to the main diffusers library for improved LoRA integration.
  • Active development is indicated by ongoing PRs and support for related techniques like ControlNet.

Licensing & Compatibility

  • The repository itself appears to be under a permissive license, but it relies heavily on the diffusers library and models from Hugging Face and Civitai, which have their own licensing terms. Users must ensure compatibility with the specific models and licenses they use.

Limitations & Caveats

  • The script's compatibility with all .safetensors files is not guaranteed due to potential variations in naming conventions or inclusion of LoRA weights for modules beyond UNet's attention layers (e.g., text encoders).
  • Support for LoRA weights targeting the text encoder is noted as pending.
  • Mixing multiple LoRA models is possible but requires careful management of weights to avoid model degradation.
Health Check
Last commit

1 year ago

Responsiveness

1 day

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

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems) and Ying Sheng Ying Sheng(Author of SGLang).

DoRA by NVlabs

0%
818
PyTorch code for weight-decomposed low-rank adaptation (DoRA)
created 1 year ago
updated 10 months ago
Feedback? Help us improve.