• Stars
    star
    894
  • Rank 50,711 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 21 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A universal Stable-Diffusion toolbox

HCP-Diffusion

PyPI GitHub stars GitHub license codecov open issues

📘中文说明

Introduction

HCP-Diffusion is a toolbox for Stable Diffusion models based on 🤗 Diffusers. It facilitates flexiable configurations and component support for training, in comparison with webui and sd-scripts.

This toolbox supports Colossal-AI, which can significantly reduce GPU memory usage.

HCP-Diffusion can unify existing training methods for text-to-image generation (e.g., Prompt-tuning, Textual Inversion, DreamArtist, Fine-tuning, DreamBooth, LoRA, ControlNet, etc) and model structures through a single .yaml configuration file.

The toolbox has also implemented an upgraded version of DreamArtist with LoRA, named DreamArtist++, for one-shot text-to-image generation. Compared to DreamArtist, DreamArtist++ is more stable with higher image quality and generation controllability, and faster training speed.

Features

  • Layer-wise LoRA (with Conv2d)
  • Layer-wise fine-tuning
  • Layer-wise model ensemble
  • Prompt-tuning with multiple words
  • DreamArtist and DreamArtist++
  • Aspect Ratio Bucket (ARB) with automatic clustering
  • Multiple datasets with multiple data sources
  • Image attention mask
  • Word attention multiplier
  • Custom words that occupy multiple words
  • Maximum sentence length expansion
  • 🤗 Accelerate
  • Colossal-AI
  • xFormers for UNet and text-encoder
  • CLIP skip
  • Tag shuffle and dropout
  • Safetensors support
  • Controlnet (support training)
  • Min-SNR loss
  • Custom optimizer (Lion, DAdaptation, pytorch-optimizer, ...)
  • Custom lr scheduler

Install

Install with pip:

pip install hcpdiff
# Start a new project and make initialization
hcpinit

Install from source:

git clone https://github.com/7eu7d7/HCP-Diffusion.git
cd HCP-Diffusion
pip install -e .
# Modified based on this project or start a new project and make initialization
## hcpinit

To use xFormers to reduce VRAM usage and accelerate training:

# use conda
conda install xformers -c xformers

# use pip
pip install xformers>=0.0.17

User guidance

Training

Training scripts based on 🤗 Accelerate or Colossal-AI are provided.

# with Accelerate
accelerate launch -m hcpdiff.train_ac --cfg cfgs/train/cfg_file.yaml
# with Accelerate and only one GPU
accelerate launch -m hcpdiff.train_ac_single --cfg cfgs/train/cfg_file.yaml
# with Colossal-AI
torchrun --nproc_per_node 1 -m hcpdiff.train_colo --cfg cfgs/train/cfg_file.yaml

Inference

python -m hcpdiff.visualizer --cfg cfgs/infer/cfg.yaml pretrained_model=pretrained_model_path \
        prompt='positive_prompt' \
        neg_prompt='negative_prompt' \
        seed=42

Conversion of Stable Diffusion models

The framework is based on 🤗 Diffusers. So it needs to convert the original Stable Diffusion model into a supported format using the scripts provided by 🤗 Diffusers.

  • Download the config file
  • Convert models based on config file
python -m hcpdiff.tools.sd2diffusers \
    --checkpoint_path "path_to_stable_diffusion_model" \
    --original_config_file "path_to_config_file" \
    --dump_path "save_directory" \
    [--extract_ema] # Extract EMA model
    [--from_safetensors] # Whether the original model is in safetensors format
    [--to_safetensors] # Whether to save to safetensors format

Convert VAE:

python -m hcpdiff.tools.sd2diffusers \
    --vae_pt_path "path_to_VAE_model" \
    --original_config_file "path_to_config_file" \
    --dump_path "save_directory"
    [--from_safetensors]

Tutorials

Contributing

You are welcome to contribute more models and features to this toolbox!

Team

This toolbox is maintained by HCP-Lab, SYSU.

Citation

@article{DBLP:journals/corr/abs-2211-11337,
  author    = {Ziyi Dong and
               Pengxu Wei and
               Liang Lin},
  title     = {DreamArtist: Towards Controllable One-Shot Text-to-Image Generation
               via Positive-Negative Prompt-Tuning},
  journal   = {CoRR},
  volume    = {abs/2211.11337},
  year      = {2022},
  doi       = {10.48550/arXiv.2211.11337},
  eprinttype = {arXiv},
  eprint    = {2211.11337},
}

More Repositories

1

genshin_auto_fish

基于深度强化学习的原神自动钓鱼AI
Python
4,762
star
2

DreamArtist-stable-diffusion

stable diffusion webui with contrastive prompt tuning
Python
876
star
3

DreamArtist-sd-webui-extension

DreamArtist for Stable-Diffusion-webui extension
Python
694
star
4

pixiv_AI_crawler

基于深度学习的p站高质量涩图AI爬虫,可以学会你的XP
Python
622
star
5

genshin_autoplay_domain

原神全自动刷秘境AI
Python
479
star
6

genshin_voice_play

语音控制玩原神
Python
141
star
7

HCP-Diffusion-webui

webui for HCP-Diffusion
Vue
139
star
8

ML-Danbooru

Anime image tags detector
Python
73
star
9

RobustDet

The official PyTorch implementation of "Adversarially-Aware Robust Object Detector"
Python
56
star
10

ML-Danbooru-webui

webui extension of ML-Danbooru
Python
53
star
11

GenshinMidi

根据midi自动生成原神音游谱
Python
48
star
12

yuanshen_auto_music

原神自动演奏脚本
Python
40
star
13

TeyvatOCR

识别并翻译原神中的提瓦特通用文
Python
27
star
14

anime-ai-detect-fucker

针对AI画图识别AI的对抗攻击
Python
25
star
15

synthesis_watermelon

基于box2d物理引擎的安卓版合成大西瓜
Java
15
star
16

yuanshen_draw

在原神中使用围栏绘图
Python
13
star
17

genshin_maze

AI自动生成并摆放原神迷宫
Python
7
star
18

torch-analyzer

A torch model analyzer
Python
7
star
19

open_cumputer

利用esp8266+舵机实现远程开机,包含服务器端代码实现内网穿透以及安卓端开机APP代码
Java
6
star
20

rl3

强化学习作业,多智能体
Python
6
star
21

anime_resource_title_analyzer

分析动漫资源网站的标题信息(字幕组 + 番剧标题 + 分辨率 + 第几集)
Python
6
star
22

WeiChatJump

Java
5
star
23

FunctionWave

一个能用数学函数来作曲的小程序
Java
5
star
24

edge_charimg

把图像的边缘特征转化成字符图
Python
5
star
25

rl2

Python
3
star
26

ProgramCalculator

多功能可编程科学计算器,电子技术课程设计
Python
2
star
27

BlindWaterMarkKiller

消除知乎盲水印
Python
2
star
28

ys_solve

原神机关自动解谜
Java
2
star
29

Arduion_3Dcube

Arduion显示一个3D立方体
C++
2
star
30

BluetoothMosue

蓝牙鼠标安卓端源码
Java
2
star
31

4D-Draw

一个4D绘图引擎
Java
1
star
32

auto_helthy_report

中南大学自动每日打卡
Java
1
star
33

card_QR_door

刷卡、扫码宿舍门
C++
1
star
34

huaji_video

一个将视频滑稽化的软件
Java
1
star
35

Auto_Hand_Font

自动生成手写体文章
Java
1
star
36

my-gitpage

SCSS
1
star
37

MatrixCalculator

一个轻便的矩阵计算器,低配matlab
Java
1
star
38

arduino-badapple

用Arduino+oled屏播放badapple
C++
1
star
39

sysu_report

中山大学自动每日健康打卡
Python
1
star
40

RainbowNekoEngine

Neural network training and inference framework
Python
1
star
41

NekoFormer

All in one basic anime CV model. tagger+siglip+natural language
Python
1
star