Thanks to visit codestin.com
Credit goes to github.com

Skip to content

lrzjason/T2ITrainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ T2ITrainer

⚠️ Development Notice: Currently in active development - stability not guaranteed. Frequent updates - check changelogs regularly.

T2ITrainer is a diffusers based training script. It aims to provide simple yet implementation for lora training.

  • ❗ Mandatory: Update diffusers to latest github version
pip install git+https://github.com/huggingface/diffusers.git -U

πŸ“… Major Updates

  • 2025-12-20: Node Based Frontend UI for configuration with visualization capabilities. Flexible dataset configuration. (Still under development)
  • 2025-12-20: Support LongCat Image and LongCat Edit, 6B MMDIT flux vae models, Lora Training

πŸ›‘οΈ Prerequisites

  • PyTorch: torch>=2.3.0+cu121 (CUDA 12.1 supported) PyPI
  • Node.js: node>=14.0.0 (Required for frontend UI) Node.js

πŸ’» Supported Training Configurations

Model Type VRAM Requirements Status
LongCat Image/Edit 24GB GPU βœ… Supported
Qwen Edit 48GB GPU (bf16) βœ… Supported
Qwen Image 24GB GPU (nf4) 48GB GPU (bf16) βœ… Supported
Flux Fill, Kontext 24GB GPU βœ… Supported

βš™οΈ Installation Guide

0. System Requirements

❗ Mandatory: Install Microsoft Visual C++ Redistributable if encountering DLL errors

0.1 Frontend Requirements

❗ Mandatory: Install Node.js (version 14 or higher) for the Node-Based Frontend UI

After installing Node.js, verify the installation:

node --version
npm --version

1. Automated Setup

Recommended Method

  git clone https://github.com/lrzjason/T2ITrainer.git
  cd T2ITrainer
  setup.bat
  • Handles: Virtual Environment β€’ Dependency Installation β€’ Model Downloads β€’ Frontend Dependencies

The automated setup will:

  1. Create a Python virtual environment
  2. Install Python dependencies
  3. Install Node.js dependencies for the frontend
  4. Build the frontend UI
  5. Download required models

2. Manual Installation

Clone Repository 🌐

    git clone https://github.com/lrzjason/T2ITrainer.git
    cd T2ITrainer

Virtual Environment πŸ› οΈ

    python -m venv venv
    call venv\Scripts\activate
    pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

Frontend Setup πŸ–₯️

    cd frontend
    npm install
    npm run build
    cd ..

Backend Dependencies πŸ“¦

    pip install -r requirements.txt

Model Downloads πŸ“₯ ❗ Notice: Only download the models you want to train. Install huggingface-cli if you haven't (or update the huggingface-cli if you have an old version). You could find the download scripts in download_xxx.txt

    # NF4 Qwen Image
    hf download "lrzjason/qwen_image_nf4" --local-dir qwen_models/qwen_image_nf4/

    # NF4 Flux kontext
    hf download "lrzjason/flux-kontext-nf4" --local-dir flux_models/kontext/

    # NF4 Flux Fill for low gpu
    hf download "lrzjason/flux-fill-nf4" --local-dir flux_models/fill/

    # Kolors
    hf download Kwai-Kolors/Kolors --local-dir kolors_models/

    # SD3.5 Models
    hf download "stabilityai/stable-diffusion-3.5-large" --local-dir "sd3.5L/"

    # download original repo for lokr training
    hf download "Qwen/Qwen-Image" --local-dir qwen_models/qwen_image/
    hf download "Qwen/Qwen-Image-Edit" --local-dir qwen_models/qwen_image_edit/

πŸš€ Launch Options

Command Line Interface

Model Command Special Notes
Qwen Edit python train_qwen_image_edit.py 48GB VRAM Recommended for original model
Qwen Image python train_qwen_image.py 24GB VRAM Recommended for nf4, 48GB VRAM Recommended for original model
Flux kontext python ui_flux_fill.py 24GB VRAM Recommended
Flux Fill python ui_flux_fill.py 24GB VRAM Recommended
LongCat Image python train_longcat.py 24GB VRAM Recommended
LongCat Image Edit python train_longcat_edit.py 24GB VRAM Recommended

Node-Based Frontend UI (Recommended)

For the new Node-Based Frontend UI with visualization capabilities:

Development Mode (Fastest for development):

# Terminal 1: Start backend
python backend_api.py

# Terminal 2: Start frontend (auto-reloads on changes)
cd frontend
npm run dev

Access at: http://localhost:3000

Production Mode (Optimized for performance):

# Build and serve the frontend with backend
python main.py

Access at: http://localhost:7860

Preview Mode (Pre-built optimized version):

# Terminal 1: Start backend
python backend_api.py

# Terminal 2: Serve pre-built frontend (faster than main.py)
cd frontend
npm run preview

Access at: http://localhost:7860

Performance Note: npm run dev provides the fastest experience with hot reloading, while npm run preview offers optimized performance similar to production. The python main.py approach uses npm run preview internally for better performance but still requires the backend to be running separately.

πŸ”§ Parameter Configuration Guide

CivitAI Article


🌌 Qwen Model Management

Config Usage
config_qwen_single.json Train qwen image with a single image; leave the suffix empty to use all images without a suffix.
  • Usage: python train_qwen_image.py --config_path config_qwen_single.json
Config Usage
config_qwen_single.json Train Qwen Image/Edit with a single image; leave the suffix empty to use all images without a suffix.
config_qwen_edit_pairs.json Traditional Qwen Edit training using _T and _R suffixed images.
config_qwen_edit_pairs_multiple.json Train with multiple reference images by setting suffixes like _T, _R, and _G.
  • Usage: python train_qwen_image_edit.py --config_path config_qwen_single.json

Qwen Model Installation

Inpainting Model Setup

  hf download"lrzjason/qwen_image_nf4" --local-dir qwen_models/qwen_image_nf4/

For more details (example dataset):

βš™οΈ Qwen Recommended Parameters

Qwen Image NF4

Category Settings
Base Configuration Rank 32, AdamW, Learn Rate 1e-4
24GB GPU 512 resolution, Batch Size 1
Precision bf16

Qwen Image Model

Category Settings
Base Configuration Rank 32~64, AdamW, Learn Rate 1e-4
48GB GPU 1024 resolution, Batch Size 1
Precision bf16

Qwen Edit Model

Category Settings
Base Configuration Rank 32~64, AdamW, Learn Rate 1e-4
48GB GPU 512 resolution, Batch Size 1
Precision bf16

πŸ’» VRAM Usage (nf4, bs1, blocks_to_swap=20)

VRAM Peak

πŸ’» VRAM Usage (nf4, bs1, blocks_to_swap=0)

VRAM Peak

πŸ’» VRAM Usage (Original, bf16, bs1, blocks_to_swap=0)

VRAM Peak
Around 43GB

🌌 Flux Model Management

Config Usage
config_new_single.json Train Kontext with a single image; leave the suffix empty to use all images without a suffix.
config_new_pairs.json Traditional Kontext training using _T and _R suffixed images.
config_new_pairs_multiple.json Train with multiple reference images by setting suffixes like _T, _R, and _G.
config_new_mixed.json Train Kontext using a mixed layoutβ€”e.g., combine traditional pair training with single-image training.
  • Usage: python train_flux_lora_ui_kontext_new.py --config_path config_new_single.json

Kontext Model Installation

Inpainting Model Setup

  hf download"lrzjason/flux-kontext-nf4" --local-dir flux_models/kontext/

For more details (example dataset):

Fill Model Installation (Skip if train kontext)

Inpainting Model Setup

  hf download"lrzjason/flux-fill-nf4" --local-dir flux_models/fill/ 

For more details (example dataset):

Dev Model Download (Skip if train fill and kontext)

Dev Model Installation

  hf download"black-forest-labs/FLUX.1-dev" --local-dir flux_models/dev/

βš™οΈ Flux Training Recommended Parameters

Category Settings
Base Configuration Rank 16, AdamW, Lr 1e-4
24GB GPU 512 resolution, Batch Size 1
VRAM Optimization Use nf4 based training
Precision bf16

🌌 LongCat Model Management

Config Usage
config_longcat_dev.json Train LongCat Image with a single image; leave the suffix empty to use all images without a suffix.
config_longcat_edit.json Train LongCat Image Edit with paired images using various suffixes like _T, _R, etc.
  • Usage (LongCat Image): python train_longcat.py --config_path config_longcat_dev.json
  • Usage (LongCat Image Edit): python train_longcat_edit.py --config_path config_longcat_edit.json

LongCat Model Installation

LongCat Model Setup

  hf download "Meituan/LongCat-Image" --local-dir longcat_models/LongCat-Image/
  hf download "Meituan/LongCat-Image-Edit" --local-dir longcat_models/LongCat-Image-Edit/

βš™οΈ LongCat Training Recommended Parameters

Category Settings
Base Configuration Rank 32~64, AdamW, Learn Rate 1e-4
24GB GPU 1024 resolution, Batch Size 1
Precision bf16

πŸ’» VRAM Usage nf4

VRAM Peak

πŸ’» VRAM Usage (bf16, blocks_to_swap=10)

VRAM Peak
VRAM Low

πŸ”§ Visualize Training Data

Register WandB before using it Setup WandB env

pip install wandb
wandb login

Install Tensorboard first if you choice to use Tensorboard To visualize training data, run the following command in your terminal:

tensorboard --logdir=.\logs

πŸ†˜ Troubleshooting

  • Kolors Black Image Issue: Ensure you're using FP16 Fixed VAE
  • VRAM Limitations: Adjust blocks_to_swap parameter (higher values reduce memory usage)
  • Windows DLL Errors: Verify VC++ Redistributable installation
  • Frontend Not Loading: Ensure Node.js is installed and frontend is built (cd frontend && npm install && npm run build)
  • Templates Not Found: In production builds, ensure the backend is running (python backend_api.py) before accessing the frontend
  • Slow Frontend Performance: Use npm run dev for development or npm run preview for optimized local serving instead of python main.py

Star History

Star History Chart

Old Change logs:

Recent Change Logs:

  • 2025-07-30:
  • Fix: Remove text attention mask in lora training.

Sponsor:

πŸ“¬ Contact

Sponsors me for more open source projects:

Buy me a coffee:

Buy Me a Coffee QR

WeChat:

WeChat QR
- Thanks to ηŒ«δΈηˆ±εƒι¦™θœ sponsor for adding lokr support. - Thanks to AIGate(https://waas.aigate.cc/) providing compute power for the development.

Acknowledgements:

  • Thanks to chenpipi0807 for Chinese translation and language switch support
  • Thanks for diffusers and Terminus Research Group
  • Thanks to minienglish1 and Freon in EveryDream Discord for the assistance.
  • Special thanks to kohya ss for references from the training codebase.
  • Thanks to Kblueleaf for coding reference on hunyuandit gradient checkpoint implementation.
  • Thanks to Kolors for the open-source checkpoint.
  • Thanks to comfyui for the wonderful codebase.
  • Thanks to emojiiii for the setup.bat script and other updates.
  • Thanks to Rohit Gandikota and related authors of Concept Sliders https://github.com/rohitgandikota/sliders

About

Practice Code for text to image trainer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6