β οΈ 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- 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
| 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 |
β Mandatory: Install Microsoft Visual C++ Redistributable if encountering DLL errors
β Mandatory: Install Node.js (version 14 or higher) for the Node-Based Frontend UI
After installing Node.js, verify the installation:
node --version
npm --versionRecommended 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:
- Create a Python virtual environment
- Install Python dependencies
- Install Node.js dependencies for the frontend
- Build the frontend UI
- Download required models
Clone Repository π
git clone https://github.com/lrzjason/T2ITrainer.git
cd T2ITrainerVirtual Environment π οΈ
python -m venv venv
call venv\Scripts\activate
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121Frontend Setup π₯οΈ
cd frontend
npm install
npm run build
cd ..Backend Dependencies π¦
pip install -r requirements.txtModel 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/| 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 |
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 devAccess at: http://localhost:3000
Production Mode (Optimized for performance):
# Build and serve the frontend with backend
python main.pyAccess 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 previewAccess at: http://localhost:7860
Performance Note:
npm run devprovides the fastest experience with hot reloading, whilenpm run previewoffers optimized performance similar to production. Thepython main.pyapproach usesnpm run previewinternally for better performance but still requires the backend to be running separately.
| 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
Inpainting Model Setup
hf download"lrzjason/qwen_image_nf4" --local-dir qwen_models/qwen_image_nf4/For more details (example dataset):
| Category | Settings |
|---|---|
| Base Configuration | Rank 32, AdamW, Learn Rate 1e-4 |
| 24GB GPU | 512 resolution, Batch Size 1 |
| Precision | bf16 |
| Category | Settings |
|---|---|
| Base Configuration | Rank 32~64, AdamW, Learn Rate 1e-4 |
| 48GB GPU | 1024 resolution, Batch Size 1 |
| Precision | bf16 |
| Category | Settings |
|---|---|
| Base Configuration | Rank 32~64, AdamW, Learn Rate 1e-4 |
| 48GB GPU | 512 resolution, Batch Size 1 |
| Precision | bf16 |
|
VRAM Peak Around 43GB |
| 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
Inpainting Model Setup
hf download"lrzjason/flux-kontext-nf4" --local-dir flux_models/kontext/For more details (example dataset):
- https://github.com/lrzjason/T2ITrainer/blob/main/doc/image/flux_kontext.md
- https://huggingface.co/datasets/lrzjason/object_removal_alpha_kontext
Inpainting Model Setup
hf download"lrzjason/flux-fill-nf4" --local-dir flux_models/fill/ For more details (example dataset):
- https://github.com/lrzjason/T2ITrainer/blob/main/doc/image/flux_fill.md
- https://huggingface.co/datasets/lrzjason/ObjectRemovalAlpha
Dev Model Installation
hf download"black-forest-labs/FLUX.1-dev" --local-dir flux_models/dev/| 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 |
| 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 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/| Category | Settings |
|---|---|
| Base Configuration | Rank 32~64, AdamW, Learn Rate 1e-4 |
| 24GB GPU | 1024 resolution, Batch Size 1 |
| Precision | bf16 |
Register WandB before using it Setup WandB env
pip install wandb
wandb loginInstall Tensorboard first if you choice to use Tensorboard To visualize training data, run the following command in your terminal:
tensorboard --logdir=.\logs- Configuration Guide: π CivitAI Article
- Kolors Black Image Issue: Ensure you're using FP16 Fixed VAE
- VRAM Limitations: Adjust
blocks_to_swapparameter (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 devfor development ornpm run previewfor optimized local serving instead ofpython main.py
- 2025-07-30:
- Fix: Remove text attention mask in lora training.
- Thanks to all the contributors and sponsors for improving the project!
- Sponsor List:
- https://github.com/lrzjason/T2ITrainer/blob/main/sponsor/sponsor_list.txt
- π Twitter: @Lrzjason
- π§ Email: [email protected]
- π¬ QQ Group: 866612947
- π¬ WeChat ID: fkdeai
- π¨ CivitAI: xiaozhijason
- 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