Oneflow-Inc / libai

LiBai(李白): A Toolbox for Large-Scale Distributed Parallel Training
https://libai.readthedocs.io
Apache License 2.0
391 stars 55 forks source link

Dev stable diffusion #437

Closed CPFLAME closed 1 year ago

CPFLAME commented 1 year ago

这个pr要做的, stable diffusion的finetune代码:

说明:

Stable diffusion

This is an reimplement of training stable diffusion in LiBai

Environment

Before running the scripts, make sure to install the library's training dependencies:

To make sure you can successfully run the latest versions of the example scripts, we highly recommend installing from source and keeping the install up to date as we update the example scripts frequently and install some example-specific requirements.

Install libai

libai installation, refer to Installation instructions

# create conda env
conda create -n libai python=3.8 -y
conda activate libai

# install oneflow nightly, [PLATFORM] could be cu117 or cu102
python3 -m pip install --pre oneflow -f https://staging.oneflow.info/branch/master/[PLATFORM]

# install libai
git clone https://github.com/Oneflow-Inc/libai.git
cd libai
pip install pybind11
pip install -e .

Install onediff

Important

To make sure you can train stable diffusion in LiBai, please install onediff

Option 1: Fresh clone and dev install

git clone https://github.com/Oneflow-Inc/diffusers.git onediff
cd onediff
python3 -m pip install "transformers>=4.26" "diffusers[torch]==0.12.1"
python3 -m pip uninstall accelerate -y
python3 -m pip install -e .

Option 2: Setup if you were using the the oneflow-fork branch before

  1. uninstall transformers and diffusers
python3 -m pip uninstall transformers -y
python3 -m pip uninstall diffusers -y
  1. install transformers and diffusers
python3 -m pip install "transformers>=4.26" "diffusers[torch]==0.12.1"
python3 -m pip uninstall accelerate -y
  1. delete the main first:
git branch -D main
git fetch
git checkout main
python3 -m pip install -e .

Notes

python3 -m pip install huggingface_hub
 ~/.local/bin/huggingface-cli login

Start training

Training

DreamBooth

DreamBooth is a method to personalize text2image models like stable diffusion given just a few(3~5) images of a subject.

Inference with trained model

model will be saved in train.output_dir in config.py,

CPFLAME commented 1 year ago

这个pr可以先review了, 可以先合进去。

xiezipeng-ML commented 1 year ago

可以加一下license

CPFLAME commented 1 year ago

可以加一下license

已加