# Qwen Image Training

The Complete Detailed Tutorial Guide

## Part 1: Initial Setup & Installation

- Introduction & Finding Resources
  - Locating the main post with all necessary information.
  - Finding the specific resources: the zip file, instructions, and the attachments section.
  - Speaker's Note: A direct instruction to not start installation immediately and to read the entire post first.
- Mandatory Prerequisites: The Requirements Tutorial
  - The critical first step: Following the separate "requirements tutorial" linked in the main post.
  - This sub-tutorial is presented as a separate video.
  - Contents of the requirements tutorial: Installing Python, CUDA, FFmpeg, and other essential software.
  - Confirmation that all links in the requirements tutorial are fully updated (example date given: 3 September 2025).
  - The explicit instruction to return to the main post after completing the requirements tutorial.
- Core Application Installation
  - Moving the downloaded `.zip` file to the desired installation drive (e.g., Q drive).
  - Extracting the zip file (using the standard Windows extractor is fine).
  - Critical Step: Entering the newly extracted folder before running anything.
  - Running the installer by double-clicking `Windows install and update.bat` (or selecting and hitting Enter).
  - Crucial Warning: Do NOT run anything as an administrator, as it will break the installation.
  - Explanation of the isolated virtual environment and how it protects your system.
  - How to handle installation errors: Select all text in the CMD window (Ctrl+A, Ctrl+C), save to a text file, and send it for support via email, Patreon, or Discord.

## Part 2: Acquiring the AI Models

- Downloading Training Models
  - Running the downloader script: `Windows download training models.bat`.
  - Choosing which base model to download:
    - Option 1: Qwen base model.
    - Option 2: Qwen image edit plus model.
  - Features of the custom downloader: High speed (16 simultaneous connections), fully resumable, automatic file merging, and hash verification to prevent corruption.
  - Location of downloaded models: `training/models/Qwen/` folder.
  - Important Model Requirement: BF16 version models are mandatory for training. FP8 or GGUF versions are explicitly stated to not work.

## Part 3: The Training Interface & Configuration

- Starting and Navigating the UI
  - How to update the application: Rerun `Windows install and update.bat`.
  - How to start the application: Run `Windows start up.bat`.
  - The importance of monitoring the CMD window for status and errors.
  - Ensuring you are in the "Qwen image training" tab.
  - User Interface Tip: Refresh the page before loading a new config to avoid issues.
- Loading a Training Configuration (Preset)
  - First step in the UI: Loading a configuration file (`.toml`).
  - Navigating to the `Qwen training configs` folder.
  - Choosing a training type: LoRA vs. Fine-tuning (Dreambooth).
  - Choosing training duration/quality: 200 epochs (best quality, lower learning rate), 100 epochs, 50 epochs.
  - Understanding tiered configs (Tier 1, 2, 3...) based on VRAM requirements.
  - How to understand tier differences: Opening the `Lora configs explanation.gpx` file located inside the configs folder.
- System & VRAM Preparation
  - How to check total GPU VRAM: `nvidia-smi` command.
  - How to check free VRAM: `pip install nvitop` and then running `nvitop`.
  - The necessity of minimizing background VRAM usage (e.g., getting it under 2GB) by restarting the PC and disabling unnecessary startup apps in Task Manager.
- Detailed Training Parameter Setup
  - Accelerate Launch Settings: For multi-GPU training.
  - Important Caveat: It's noted that multi-GPU on Windows is not working very well.
  - Checkpoints & Output Settings:
    - Setting the Output folder for saved models.
    - Setting the Save every N epochs frequency.
  - Definition of Epoch: One epoch is defined as the point where all training images have been trained one time.
  - Saving Your Custom Configuration: How to save your modified settings into a new `.toml` file to use later, and the importance of saving to a new folder to avoid overwriting base configs.

## Part 4: Dataset Preparation (The Most Critical Section)

- Using the Ultimate Batch Image Processing Tool
  - Downloading, installing, and running the separate image processing application.
  - Stage 1: Smart Cropping: Using the tool to automatically zoom in on the subject (e.g., "person") via class selection (YOLO) or prompt (SAM 2) without cropping important parts.
  - Stage 2: Exact Resizing: Taking the output from Stage 1 and resizing/cropping to the exact target resolution (e.g., `1328x1328`).
- Dataset Quality Guidelines (For Characters)
  - Variety is Key: Include a mix of full body, half body, close-ups, clothing, backgrounds, emotions, poses, and angles.
  - Quality is Paramount: Use images with good lighting and sharp focus. Avoid blurry or fuzzy backgrounds.
  - Core Principle: The model will learn and repeat whatever is consistently present in the dataset. Only the subject should be consistent.
- NEW - Using the Internal Image Pre-processing Tool
  - A tab within the main trainer UI named "Image Preprocessing."
  - Purpose: To visualize the exact final version of your images as the trainer will see them, especially useful for bucketing (multi-aspect ratio training).
  - How to Use: Provide an input folder, enable bucketing, select the architecture (Qwen Image), and process.
  - What it reveals: Inaccurate image orientation, padding added by bucketing, and the final resolution distribution.
  - Debug Mode: A feature to have images pop up one-by-one during training to see exactly how they are being processed.
- Dataset Structuring for the Trainer
  - Creating a subfolder in your dataset directory named in the format: `[repeats]_[triggerword]` (e.g., `1_OHWX`).
  - Explanation of Repeats: Used to balance datasets with different numbers of images per concept. For a single subject, 1 is sufficient.
- Captioning Your Dataset
  - Recommended Method: Using only a single trigger word (e.g., `OHWX`) as the caption. The tutorial states this works best.
  - Alternative (Detailed Captions): Using the "Image Captioning" tab (powered by Qwen VL) or the external Joy Caption tool.
  - Generating the `dataset_config.toml` file within the UI is the final step of dataset setup.
- Finalizing Model Paths and Settings
  - Qwen Image Model Settings: Selecting the Base model, VAE, and Text encoder files.
  - Block Swap: Adjusting this value if you get out-of-VRAM errors or slow speeds, as it controls swapping memory with system RAM.
  - Training Settings: Setting the Maximum number of epochs (e.g., 200 is good for <50 images).

## Part 5: The Training Process & Post-Training Workflow

- Monitoring Training & Performance Optimization
  - Advanced Speed Improvement Tricks:
    - Connect monitors to a secondary, weaker GPU to free up the primary GPU's idle VRAM.
    - Enable "Use pinned memory for block swapping" in the UI.
    - Disable "Hardware-accelerated GPU scheduling" in Windows Graphics Settings.
    - Overclocking the GPU with MSI Afterburner.
- Testing and Finding the Best Checkpoint
  - Prerequisite: Setting up Swarm UI with a Comfy UI backend via the linked tutorial.
  - Using the Grid Generator tool in Swarm UI to compare multiple checkpoints against a set of test prompts.
  - For LoRA: Vary the Lora parameter.
  - For Fine-tune: Vary the Model parameter.
  - Analyzing the generated grid to visually determine the best-performing checkpoint.
- Resuming an Incomplete Training
  - For LoRA: Set `network_weights` to the path of your last checkpoint. Adjust `max_train_epochs` to the additional number of epochs needed.
  - For Fine-tuning: Set the `base_model_path` to your last fine-tune checkpoint. Adjust `max_train_epochs` similarly.

## Part 6: Generating High-Quality Images

- Image Generation Workflow in Swarm UI
  - Using presets (e.g., `Qwen image realism tier 2`).
  - Crucial Note for Fine-Tuned Models: After applying a preset, you might need to manually re-select your fine-tuned model, as the preset can override it.
  - Pro-Tip: Generate smaller images first without upscaling to quickly find a good seed, then enable upscaling for the one you like.
- Fixing Imperfections: Inpainting
  - Automatic Face Fixing: Adding `segment face` to the prompt.
  - Manual Inpainting: Using the "Edit Image" feature to manually mask and regenerate a specific area.

## Part 7: Specialized Training Scenarios

- Fine-Tuning (Dreambooth) Specifics
  - Process is nearly identical to LoRA but uses fine tuning configs.
  - Key Difference: Checkpoints are massive (~40 GB).
  - Post-Training Step: Converting the BF16 models to FP8 scaled (tensor_wise), reducing size by 50%.
- Training on the Qwen Image Edit Model
  - Without Control Images: A simple process allowing your subject to work with command-based prompts (e.g., "replace his face with OHWX man").
  - With Control Images (Teaching New Commands): A complex setup requiring a final image, a caption with the command, and one or more input images. This method uses significantly more VRAM and is much slower.
- Style Training
  - The key is the dataset: extremely consistent style with high variety in subjects (nothing should repeat except the style).
  - Using presets like `Qwen images stylized UHD tier 1` (better quality, more steps) or `tier 2` (faster) for generation.
- Product Training
  - The key is the dataset: a mix of close-up shots (for details like text) and wider shots (for scale).
  - Use detailed prompts during inference that describe logos and text on the product for higher accuracy.

## Part 8: Conclusion & Community

- Final Housekeeping & Recap
  - LoRAs go in the `SwarmUI/models/lora` folder.
  - Fine-tuned models go in the `SwarmUI/models/diffusion` folder after FP8 conversion.
- Community and Support Channels
  - Joining the Discord server.
  - Following on GitHub (fork, star, watch, sponsor).
  - Joining the Reddit community.
  - Following on LinkedIn and subscribing on YouTube (and enabling notifications).
  - Information about professional services: private lectures and company consultations.