Architecture
- DiT (Diffusion Transformer) — replaces the UNet. Operates on patchified latents using transformer blocks with flow matching.
- Qwen2.5-VL (7B) — a vision-language model used as the primary text encoder (
bfloat16). Provides rich semantic understanding. - byT5 (small) — a byte-level T5 encoder used as an auxiliary text encoder (
float16). Improves character-level and OCR fidelity. - VAE — HunyuanImage-2.1-specific VAE. Not compatible with SDXL, SD3, or FLUX.1 VAEs.
Required model files
Download the following files before training:Available training methods
LoRA training
Usehunyuan_image_train_network.py with --network_module=networks.lora_hunyuan_image. The --network_train_unet_only flag is required because text encoder LoRA is not supported:
VRAM optimization
HunyuanImage-2.1 is a large model. Use the following combinations based on your GPU:Key VRAM reduction options
--fp8_scaled— trains the DiT in scaled FP8 format. This is the recommended FP8 option for HunyuanImage-2.1 (replaces the unsupported--fp8_base). Essential for GPUs below 40 GB.--fp8_vl— uses FP8 for the Qwen2.5-VL text encoder.--blocks_to_swap <n>— offloadsnDiT blocks to CPU. Up to 37 blocks can be swapped.--text_encoder_cpu— runs both text encoders on CPU. Useful when VRAM is below 12 GB. Combine with--cache_text_encoder_outputs_to_diskto avoid re-encoding on every run. Also increase--num_cpu_threads_per_processin theaccelerate launchcommand (e.g., 8 or 16) to speed up encoding.--vae_chunk_size <n>— enables chunked VAE processing. A chunk size of 16 is recommended for low-VRAM environments.--cpu_offload_checkpointing— offloads gradient checkpoints to CPU. Cannot be combined with--blocks_to_swap.
Key training parameters
Attention modes
The--attn_mode option selects the attention implementation:
ComfyUI format conversion
LoRAs trained with sd-scripts use a format that differs slightly from ComfyUI’s expected format. Convert before use in ComfyUI:--reverse:
Reverse conversion only works for LoRAs that were originally converted by this script. LoRAs created with other training tools cannot be converted back.
Inference
Usehunyuan_image_minimal_inference.py to generate images with your trained LoRA:
