Skip to main content

Naifu

naifu-diffusion (or naifu) is designed for training generative models with various configurations and features. The code in the main branch of this repository is under development and subject to change as new features are added.

Other branches in the repository include:

  • sgm - Uses the sgm to train SDXL models.
  • main-archived - Contains the original naifu-diffusion code for training Stable Diffusion 1.x models.

Installation

To install the necessary dependencies, simply run:

git clone https://github.com/mikubill/naifu-diffusion
pip install -r requirements.txt

Usage

You can train the image model using different configurations by running the trainer.py script with the appropriate configuration file.

python trainer.py --config config/<config_file>
python trainer.py config/<config_file>

Replace <config_file> with one of the available configuration files listed below.

Available Configurations

Choose the appropriate configuration file based on training objectives and environment.

Train SDXL (Stable Diffusion XL) model

# stabilityai/stable-diffusion-xl-base-1.0
python trainer.py config/train.yaml

Train SDXL refiner (Stable Diffusion XL refiner) model

# stabilityai/stable-diffusion-xl-refiner-1.0
python trainer.py config/train_refiner.yaml

Train original Stable Diffusion 1.4 or 1.5 model

# runwayml/stable-diffusion-v1-5
# Note: will save in diffusers format
python trainer.py config/train_sd15.yaml

Train SDXL model with diffusers backbone

# stabilityai/stable-diffusion-xl-base-1.0
# Note: will save in diffusers format
python trainer.py config/train_diffusers.yaml

Train SDXL model with LyCORIS.

# Based on the work available at KohakuBlueleaf/LyCORIS
pip install lycoris_lora toml
python trainer.py config/train_lycoris.yaml

Use fairscale strategy for distributed data parallel sharded training

pip install fairscale
python trainer.py config/train_fairscale.yaml

Train SDXL model with Diffusion DPO
Paper: Diffusion Model Alignment Using Direct Preference Optimization (arxiv:2311.12908)

# dataset: yuvalkirstain/pickapic_v2
# Be careful tuning the resolution and dpo_betas!
# will save in diffusers format
python trainer.py config/train_dpo_hfdataset.yaml

Train Pixart-Alpha model
Paper: Fast Training of Diffusion Transformer for Photorealistic Text-to-Image Synthesis (arxiv:2310.00426)

# PixArt-alpha/PixArt-XL-2-1024-MS
python trainer.py config/train_pixart.yaml

Train SDXL-LCM model
Paper: Latent Consistency Models: Synthesizing High-Resolution Images with Few-Step Inference (arxiv:2310.04378)

# PixArt-alpha/PixArt-XL-2-1024-MS
python trainer.py config/train_lcm.yaml

Preparing Datasets

Each configuration file may have different dataset requirements. Make sure to check the specific configuration file for any dataset specifications or requirements.

You can use your dataset directly for training. Simply point the configuration file to the location of your dataset. If you want to reduce the VRAM usage during training, you can encode your dataset to latents using the encode_latents.py script.

# prepare images in input_path
python encode_latents.py -i <input_path> -o <encoded_path>

Metadata

Release files for naifu 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for naifu 0.1.3
File Size Uploaded Provenance Actions
naifu-0.1.3.tar.gz 74.2 kB Without provenance Details for naifu-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for naifu 0.1.3
File Interpreter ABI Platform Actions
naifu-0.1.3-py3-none-any.whl Python 3 none any Details for naifu-0.1.3-py3-none-any.whl

Total release size: 165.6 kB

Release files / naifu-0.1.3.tar.gz

Download URL naifu-0.1.3.tar.gz
Size 74.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3240a31aa1aef44f7da48e9568316d21101c870eb0a8f0c4456c8b29e2f2cf2c
BLAKE2b-256 checksum
How to use checksums
69c0d598ff6ff7abde769e52863f4db48c05316b68dde57da59493dd690c6547
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release files / naifu-0.1.3-py3-none-any.whl

Download URL naifu-0.1.3-py3-none-any.whl
Size 91.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe8cf12d7076faa7ae10fc73a053c41b617f923e29d54171b38d9171c8231eb1
BLAKE2b-256 checksum
How to use checksums
f1d7848386dc00def2745cd45295c33e1d55320394a448627dcbd656dea883a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Security for naifu 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page