Lora-for-Diffusers  by haofanwang

Tutorial for using LoRA within the Diffusers framework

Created 2 years ago
820 stars

Top 43.3% 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

Inactive

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

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Yaowei Zheng Yaowei Zheng(Author of LLaMA-Factory), and
1 more.

DoRA by NVlabs

0.3%
854
PyTorch code for weight-decomposed low-rank adaptation (DoRA)
Created 1 year ago
Updated 11 months ago
Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera), and
5 more.

ai-toolkit by ostris

0.9%
6k
Training toolkit for finetuning diffusion models
Created 2 years ago
Updated 14 hours ago
Feedback? Help us improve.