Skip to main content
HunyuanImage-2.1 is a Diffusion Transformer (DiT) image generation model from Tencent. It uses two text encoders — a large vision-language model (Qwen2.5-VL) and a byte-level encoder (byT5) — alongside a dedicated VAE. sd-scripts supports LoRA training only; full model fine-tuning is not supported for this architecture.

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.
Full model fine-tuning is not supported for HunyuanImage-2.1. Only LoRA training is available. Additionally, LoRA modules for the text encoders are not supported — you must always pass --network_train_unet_only.

Required model files

Download the following files before training:

Available training methods

LoRA training

Use hunyuan_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> — offloads n DiT 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_disk to avoid re-encoding on every run. Also increase --num_cpu_threads_per_process in the accelerate launch command (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.
The Adafactor optimizer reduces VRAM consumption more than 8-bit AdamW:

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:
To convert back from ComfyUI format to sd-scripts format, add --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

Use hunyuan_image_minimal_inference.py to generate images with your trained LoRA:
The most stable inference resolutions are: 2560×1536, 2304×1792, 2048×2048, 1792×2304, and 1536×2560.