Skip to content

CaptainGrock/Krea2Trainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Krea2Trainer

🎨 Krea 2 LoRA Trainer

A self-contained, GUI-driven LoRA trainer for Krea 2 (built on Wan 2.1 architecture). Train custom LoRA adapters on your own images using a simple web interface β€” no command line required after installation.


What This Does

Krea 2 LoRA Trainer lets you train a LoRA (Low-Rank Adaptation) on top of the Krea 2 image generation model. A LoRA is a small adapter file (~50-200 MB) that teaches the base model a new style, person, object, or concept from your own images.

What you can train:

  • A person's likeness (face, style)
  • An artistic style
  • A specific object or product
  • A consistent character

What this tool provides:

  • One-click installer (handles Python, dependencies, ai-toolkit automatically)
  • Visual dataset browser with tag editing
  • AI auto-tagging via Microsoft Florence-2
  • Training configuration UI with sensible defaults for 24GB GPUs
  • Real-time training progress monitoring
  • Powered by ostris/ai-toolkit

System Requirements

Minimum

Component Requirement
OS Windows 10/11 (64-bit)
GPU NVIDIA GPU with 24 GB VRAM (RTX 3090, 4090, etc.)
CUDA CUDA 12.1 or higher
RAM 32 GB system RAM
Disk 100 GB free space (models + training data + outputs)
Internet Required for first-time setup and model downloads

Recommended

Component Recommendation
GPU NVIDIA RTX 4090 (24 GB VRAM)
RAM 64 GB
Disk 500 GB+ SSD
Internet 50 Mbps+ for faster model downloads

Software Prerequisites

⚠️ Important: This tool currently supports Windows only. Linux/Mac support is planned.


Installation

Step 1 β€” Download the Trainer

Option A β€” Clone with Git (recommended): bash git clone https://github.com/yourusername/krea2-lora-trainer.git cd krea2-lora-trainer

Option B β€” Download ZIP: Click the green Code button at the top of this page Click Download ZIP Extract to a folder of your choice (e.g., C:\krea2-lora-trainer) Step 2 β€” Run the Launcher Open the krea2-lora-trainer folder Double-click launch.bat A console window will open Step 3 β€” Choose Install Location The installer will ask where to install all files:

Where would you like to install Krea 2 LoRA Trainer?

Files stored here:

  • Python virtual environment (~4 GB)
  • AI-Toolkit training engine (~1 GB)
  • Trained LoRA output files
  • Model cache

Recommended: short path, no spaces, 20+ GB free

Default: C:\krea2-lora-trainer

Press ENTER for default, or type a path: C:\trainer

Tips for choosing a path:

Avoid paths with spaces (e.g., C:\My Trainer can cause issues) Choose a drive with plenty of free space A short path like C:\trainer or D:\ai\krea2 works well Step 4 β€” Choose Python The installer will detect any Python installation on your system:

Found Python on your system: C:\Python311\python.exe

Options:

  1. Download fresh portable Python (RECOMMENDED)
  2. Use the system Python found above

Enter 1 or 2 [default=1]:

Recommendation: Choose option 1 (fresh portable Python) to avoid conflicts with other tools like ComfyUI or Automatic1111.

Step 5 β€” Wait for Installation The installer runs automatically through these steps: STEP 1 β€” Creating Directory Structure STEP 2 β€” Creating Virtual Environment STEP 3 β€” Detecting GPU and CUDA Version STEP 4 β€” Installing PyTorch (~2-3 GB download) STEP 5 β€” Installing GUI Dependencies STEP 6 β€” Installing ostris/ai-toolkit STEP 7 β€” Resolving Dependency Conflicts STEP 8 β€” Writing Environment Files STEP 9 β€” Validating Installation STEP 10 β€” Finalising

⏱️ Estimated time: 10-25 minutes depending on internet speed.

Do not close the console window during installation.

Step 6 β€” Installation Complete When installation finishes you will see: ══════════════════════════════════════════════════ βœ” INSTALLATION COMPLETE βœ” Install dir: C:\trainer ══════════════════════════════════════════════════

[Launch] Starting Krea 2 LoRA Trainer... [Launch] URL: http://localhost:7860

First-Time Setup After installation, complete these one-time setup steps before training:

  1. Set a HuggingFace Token (Recommended) Go to the βš™οΈ Settings tab and set a HuggingFace token for faster downloads.

See Settings Tab Guide for instructions.

  1. Download the Krea 2 Model The Krea 2 model must be downloaded in Diffusers pipeline format β€” this is a folder containing multiple subfolders (transformer/, text_encoder/, vae/, etc.), NOT a single .safetensors file.

Go to the 🧠 Model tab β†’ expand "Download Krea 2 Pipeline" β†’ click Download.

⚠️ This is a large download (~50 GB). With a HuggingFace token it takes 30-60 minutes. Without a token it may take 2-3 hours.

  1. (Optional) Download Florence-2 for Auto-Tagging If you want AI-powered automatic caption generation for your images, download Microsoft Florence-2 (~1 GB) on the Model tab.

Model Tab Guide The Model tab manages the two AI models used by this tool.

Base Model (Krea 2) β”Œβ”€ Base Model Selection ────────────────────────────────────┐ β”‚ β”‚ β”‚ Pipeline Folder Path: [C:\models\Krea-2-Raw__________] β”‚ β”‚ [Validate] β”‚ β”‚ β”‚ β”‚ βœ… Valid Diffusers pipeline: Krea-2-Raw (48.2 GB) β”‚ β”‚ β”‚ β”‚ πŸ” Search Your Hard Drive β”‚ β”‚ Directory to Scan: [C:\models________________] [Scan] β”‚ β”‚ Found Pipelines: [Krea-2-Raw (48.2 GB) β–Ό] β”‚ β”‚ β”‚ β”‚ β–Ό Download Krea 2 Pipeline from HuggingFace (~50 GB) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

What is a Diffusers pipeline folder?

Unlike a single .safetensors file (which is what ComfyUI uses), ai-toolkit needs the full HuggingFace Diffusers format β€” a folder with this structure: Krea-2-Raw/ β”œβ”€β”€ transformer/ ← Main diffusion model weights (sharded files) β”œβ”€β”€ text_encoder/ ← Text understanding model β”œβ”€β”€ vae/ ← Image encoding/decoding β”œβ”€β”€ tokenizer/ ← Text tokenization └── scheduler/ ← Noise scheduling

To set your model:

If you already have the folder downloaded: type the path or use Scan to find it If not: expand the download section and click ⬇️ Download Florence-2 Auto-Tagger Florence-2 is an optional Microsoft AI model that automatically generates captions for your training images. This saves significant time when preparing datasets.

To set up Florence-2:

Click πŸ” Scan to find it if already downloaded Or expand the download section and click ⬇️ Download (~1 GB) Select the found model from the dropdown Click ⚑ Load Model to load it into VRAM Florence-2 uses ~2 GB of VRAM. Remember to click Unload (Free VRAM) before starting training to free that memory.

Dataset Tab Guide The Dataset tab is where you prepare your training images and captions.

What Makes a Good Dataset Factor Recommendation Image count 10-50 images (quality over quantity) Image quality High resolution, well-lit, in focus Variety Different angles, lighting, backgrounds Consistency All images clearly show the concept you're training Captions Descriptive text files matching each image Step 1 β€” Scan Your Dataset Folder Type the path to your images folder in the Directory Path field Check Recursive if your images are in subfolders Click πŸ” Scan The gallery will populate with your images. Each image shows:

[1] β€” The image ID number [⚠️] β€” Missing tags warning [EXCL] β€” Excluded from training πŸ“Œ β€” Currently selected for bulk operations Step 2 β€” Review and Edit Tags Caption format: Each image needs a .txt file with the same name. For example:

photo_001.jpg β†’ photo_001.txt photo_001.txt contains: a woman with brown hair, wearing a red dress, smiling Individual editing:

Click any image in the gallery to load it into the Tag Editor Edit the caption text in the text area Click πŸ’Ύ Save Tags to save Navigation: Use β—€ Prev and Next β–Ά to move through images

Step 3 β€” Auto-Tag with Florence-2 (Optional) If Florence-2 is loaded on the Model tab:

Select the images you want to tag (use Selection Tools) Choose a caption style from the dropdown: Detailed Caption β€” Recommended for training Simple Caption β€” Brief description More Detailed Caption β€” Very verbose Click πŸ€– Auto-Tag Selected Watch the status bar for progress.

Auto-tags overwrite existing captions. Use Apply to Selected Subset to preserve existing tags.

Step 4 β€” Add Your Trigger Word A trigger word is a unique phrase that activates your LoRA during inference.

Best practices:

Use something unlikely to appear in normal prompts For a person: p3rs0n, jsmith_v1, xyz_person For a style: mypaintstyle, xyz_style Type your trigger word in the Trigger Word field Click Prepend to All to add it to the beginning of all captions Before: a woman with brown hair, smiling After: p3rs0n, a woman with brown hair, smiling

Step 5 β€” Review the Verification Table Scroll to the bottom of the Dataset tab to see the πŸ“‹ Dataset Verification table. Click πŸ”„ Refresh to update it.

This shows all images with their full captions and status β€” do a final check before training.

Selection Tools Reference Tool What it does Select All Selects all included images Deselect All Clears selection Invert Flips the selection Select Untagged Selects only images without captions Select by ID Type 1-10, 15, 20-25 to select specific ranges Batch Operations Reference Operation What it does Auto-Tag Selected AI-generates captions for selected images Save All Tags Writes all in-memory tag edits to disk ❌ Exclude Selected Removes selected images from training βœ… Include Selected Re-includes previously excluded images Prepend to All Adds trigger word to all included image captions Create Empty .txt Creates empty tag files for untagged images Apply to Selected Subset Applies specific tags to only selected images Training Tab Guide Step 1 β€” Configure Essential Settings Setting What it does Recommended Output Name Name for your LoRA file my_lora_v1 Trigger Word Word that activates LoRA p3rs0n Training Steps How long to train 1000-3000 Learning Rate How fast the model learns 1e-4 LoRA Rank Model complexity 32 LoRA Alpha Scaling factor 32 Resolution Training image size 632 Batch Size Images per step 1 Step 2 β€” Preview Your Config Click πŸ‘ Preview Config to see the YAML that will be passed to ai-toolkit. Expand the Generated YAML Config accordion to review it.

Step 3 β€” Start Training Click β–Ά Start Training. The status will change to "Training started."

Step 4 β€” Monitor Progress The Training Monitor section updates every 2 seconds showing:

Progress: Current step / total steps Loss: Should decrease over time (good: below 0.05) LR: Current learning rate Speed: Steps per second Elapsed: Time since training started The Training Log shows raw output from ai-toolkit.

Step 5 β€” Find Your Output Completed LoRA files are saved to:

text

[your install dir]\output[output name]
The final LoRA file will be named [output name].safetensors.

Settings Tab Guide HuggingFace Token A HuggingFace token enables:

Faster downloads (3-5x speed improvement) Access to gated/private models Higher rate limits How to get a token:

Go to https://huggingface.co/join and create a free account Go to https://huggingface.co/settings/tokens Click New Token Select Read access (sufficient for downloads) Give it a name like krea2-trainer Copy the token (starts with hf_) Paste it in the Settings tab and click πŸ’Ύ Save Token Click πŸ” Test Token to verify it works The token is saved persistently β€” you only need to do this once.

Training Parameter Reference Essential Parameters Parameter Description Range Default Training Steps Total training iterations. More steps = more learning but risk of overfitting. 500-5000 2000 Learning Rate How aggressively the model updates. Too high = unstable. Too low = slow. 1e-5 to 5e-4 1e-4 LoRA Rank Complexity of the LoRA adapter. Higher = more expressive but more VRAM. 4-128 32 LoRA Alpha Scaling factor. Usually set equal to rank. 4-128 32 Resolution Training image resolution. Higher = better quality but more VRAM. 512-1024 632 Batch Size Images processed per step. Higher = faster but more VRAM. 1-4 1 Advanced Parameters Parameter Description Default Gradient Checkpointing Reduces VRAM at cost of speed. Leave ON for 24GB GPUs. βœ… On Use EMA Smooths learning. Slightly slower but better results. βœ… On EMA Decay How much EMA smoothing. Higher = smoother. 0.99 Save Every N Steps How often to save checkpoint files. 250 Max Checkpoints How many checkpoint files to keep on disk. 4 Caption Dropout Randomly drops captions during training, helps generalisation. 0.05 Shuffle Tokens Randomises caption word order each step. ❌ Off Memory Settings (Pre-configured for 24GB GPU) Parameter Description Default Quantize Model Loads model in 8-bit, halves VRAM usage. βœ… On Quantize Text Encoder Quantises text encoder too. βœ… On Low VRAM Mode Aggressive memory management. βœ… On Unload Text Encoder Encodes all captions first, then unloads TE from VRAM. Required for 24GB. βœ… On Sample Generation Settings Parameter Description Default Disable Sampling Skip sample generation (faster training). ❌ Off Sample Every N Steps How often to generate preview images. 250 Sample Prompt Prompt for preview images. Uses trigger word if blank. β€” Sample Width/Height Size of preview images. 832Γ—480 Optimizer Options Optimizer Description Best For adamw8bit 8-bit AdamW. Best VRAM/performance balance. Default, recommended adamw Standard AdamW. More VRAM but reliable. High VRAM systems prodigy Self-adapting LR. Set LR to 1.0 when using. Experimental adafactor Very low memory. Slower convergence. Low VRAM Using Your Trained LoRA Once training is complete, your LoRA file is in:

[install dir]\output[output name][output name].safetensors Using with ComfyUI Copy the .safetensors file to your ComfyUI models/loras/ folder In a workflow, add a Load LoRA node Connect it between your model loader and sampler Set the LoRA weight (0.5-1.0 is typical) Include your trigger word in the prompt Using with other tools Most tools that support LoRA (Automatic1111, InvokeAI, etc.) work the same way β€” copy the file to the loras folder and reference it in your prompt.

Trigger Word Usage Always include your trigger word in prompts to activate the LoRA: p3rs0n sitting in a coffee shop, photorealistic, high quality

Troubleshooting Installation Issues "git is not installed or not on PATH"

Install Git for Windows from: https://git-scm.com/download/win Then close and re-run launch.bat

"Failed to download Python"

Check your internet connection. If behind a corporate proxy, install Python 3.11 manually: https://www.python.org/downloads/release/python-3119/ Then set PYTHON_PATH in launch_config.ini

Installation fails at Step 4 (PyTorch)

Run as Administrator (right-click launch.bat β†’ Run as administrator) Or temporarily disable antivirus during installation

"No module named venv"

The installer downloaded the wrong Python type. Delete [install dir]\python_portable\ and run launch.bat again. The installer will download the full Python installer instead.

Force reinstall everything

Open launch_config.ini (in the same folder as launch.bat) Change: FORCE_REINSTALL=false To: FORCE_REINSTALL=true Run launch.bat again

Model Issues "Not a Diffusers pipeline directory"

You pointed to a single .safetensors file instead of a pipeline folder. The pipeline folder must contain subfolders: transformer/, text_encoder/, tokenizer/, vae/, scheduler/ Use the download button on the Model tab to get the correct format.

Florence-2 fails to load: "forced_bos_token_id"

Run this command: [install dir]\venv\Scripts\python.exe -m pip install "transformers>=4.48.0" Then restart the app.

Dataset Issues Images not showing in gallery

Check that your images are .jpg, .jpeg, .png, .webp, or .bmp format. Other formats (HEIC, TIFF, etc.) are not supported.

"Cannot move file to gradio cache"

This should be fixed in the current version. If it appears, restart the app - it's a first-load issue.

Training Issues "CUDA Out of Memory"

Enable all memory-saving options: βœ… Quantize Model βœ… Quantize Text Encoder
βœ… Low VRAM Mode βœ… Unload Text Encoder βœ… Gradient Checkpointing

Reduce resolution to 512 and batch size to 1.

Training exits immediately with code 1

Check the Training Log for the specific error. Common causes:

  • Dataset path has no images
  • Image captions are missing
  • transformers/diffusers version conflict (run pip upgrades)

"cannot import name 'Dinov2WithRegistersConfig'" Run: [install dir]\venv\Scripts\python.exe -m pip install "transformers>=4.48.0" "diffusers>=0.32.0" Then restart the app.

Loss is not decreasing

  • Try a higher learning rate (2e-4)
  • Ensure captions are descriptive and consistent
  • Make sure trigger word is in all captions
  • More training steps may be needed

Loss is increasing or very unstable

  • Lower the learning rate (5e-5)
  • Enable EMA if not already on
  • Check for corrupt or mislabeled images

App Issues Browser shows blank page

Run: [install dir]\venv\Scripts\python.exe -m pip install jinja2==3.1.4 Then restart launch.bat

App crashes on startup

Check the console window for the error message. Common fix: [install dir]\venv\Scripts\python.exe -m pip install gradio==5.31.0

Progress bar stuck at 0%

This is normal during model loading (can take 5-10 minutes on first run). Watch the Training Log for activity.

File Structure Reference krea2-lora-trainer/ ← Launcher directory (source code) β”‚ β”œβ”€β”€ launch.bat ← DOUBLE-CLICK THIS to start β”œβ”€β”€ launch_config.ini ← Auto-generated configuration β”œβ”€β”€ .install_dir ← Pointer to install directory β”œβ”€β”€ .env ← Environment variables β”‚ β”œβ”€β”€ installer/ β”‚ β”œβ”€β”€ bootstrap.py ← Master installer (runs once) β”‚ β”œβ”€β”€ gpu_detector.py ← NVIDIA GPU detection β”‚ β”œβ”€β”€ torch_installer.py ← PyTorch CUDA installer β”‚ β”œβ”€β”€ toolkit_installer.py ← ai-toolkit installer β”‚ └── requirements.txt ← GUI dependencies β”‚ └── app/ β”œβ”€β”€ main.py ← Application entry point β”œβ”€β”€ state.py ← Shared state + settings β”‚ β”œβ”€β”€ ui/ β”‚ β”œβ”€β”€ layout.py ← Tab composition β”‚ β”œβ”€β”€ model_selector.py β”‚ β”œβ”€β”€ dataset_browser.py β”‚ β”œβ”€β”€ training_tab.py β”‚ └── settings_tab.py β”‚ β”œβ”€β”€ backend/ β”‚ β”œβ”€β”€ config_generator.py ← Builds YAML for ai-toolkit β”‚ β”œβ”€β”€ subprocess_runner.py ← Manages training process β”‚ β”œβ”€β”€ dataset_manager.py ← Image/tag scanning β”‚ └── florence_tagger.py ← Auto-tagging β”‚ └── utils/ β”œβ”€β”€ file_utils.py └── image_utils.py

[install directory]/ ← Your chosen install location β”‚ β”œβ”€β”€ venv/ ← Python virtual environment β”‚ └── .install_complete ← Marker: installation is done β”œβ”€β”€ ai-toolkit/ ← ostris/ai-toolkit (training engine) β”œβ”€β”€ output/ ← YOUR TRAINED LoRA FILES GO HERE β”‚ └── [lora name]/ β”‚ β”œβ”€β”€ [lora name].safetensors ← Final LoRA β”‚ └── [lora name]_000250.safetensors ← Checkpoints β”œβ”€β”€ workspace/ ← Prepared training datasets β”œβ”€β”€ configs/ ← Generated YAML training configs β”œβ”€β”€ logs/ ← Training and install logs β”œβ”€β”€ hf_cache/ ← HuggingFace model cache β”œβ”€β”€ python_portable/ ← Portable Python (if downloaded) └── user_settings.json ← Your saved settings

FAQ Q: Do I need a HuggingFace account? A: No, but an account gives you a token which makes downloads 3-5x faster. Highly recommended for the large model download.

Q: Can I use a single .safetensors file as the base model? A: Not directly with ai-toolkit. It requires the Diffusers pipeline format. A future update will include a conversion tool. For now, use the download button to get the correct format.

Q: How many images do I need? A: 10-50 high-quality, consistent images is the sweet spot. More is not always better β€” 200 mediocre images often trains worse than 20 great ones.

Q: How long does training take? A: On an RTX 4090 at 2000 steps with rank 32: approximately 30-60 minutes after the model loads into VRAM. Model loading itself takes 5-10 minutes.

Q: What's the difference between rank 16, 32, and 64? A: Higher rank = more parameters = more expressive LoRA but larger file and more VRAM. Rank 32 is a good balance for most use cases. Use rank 16 for simple styles and rank 64 for complex subjects.

Q: My trigger word isn't working in ComfyUI A: Make sure to use the exact same trigger word you trained with, and ensure the LoRA is loaded with a non-zero weight (try 0.8-1.0).

Q: Can I continue training from a checkpoint? A: Not yet β€” resume-from-checkpoint is on the roadmap for a future update.

Q: Can I use this on Linux or Mac? A: Not yet. Windows only for now. Linux support is planned.

Q: The app says "Already loaded" for Florence-2 but auto-tag is still greyed out A: Go back to the Model tab and click the Load Model button again. The button should change to "Loaded βœ…".

Q: Where are my trained LoRA files? A: [your install directory]\output[output name]\

Credits ostris/ai-toolkit β€” Training engine Krea AI β€” Krea 2 model Wan-AI β€” Base Wan 2.1 architecture Microsoft Florence-2 β€” Auto-tagging model Gradio β€” Web UI framework HuggingFace β€” Model hosting License MIT License β€” see LICENSE for details.

Contributing Issues and pull requests welcome. Please test on a clean Windows machine before submitting.

text


Also here is the LICENSE file: MIT License

Copyright (c) 2025 Krea 2 LoRA Trainer Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Automated wrapper to make training Krea 2 easy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors