RepoTencent HunyuanTencent Hunyuanpublished Sep 4, 2025seen 5d

Tencent-Hunyuan/HunyuanImage-2.1

Python

Open original ↗

Captured source

source ↗

Tencent-Hunyuan/HunyuanImage-2.1

Description: HunyuanImage-2.1: An Efficient Diffusion Model for High-Resolution (2K) Text-to-Image Generation​

Language: Python

License: NOASSERTION

Stars: 673

Forks: 55

Open issues: 15

Created: 2025-09-04T06:46:19Z

Pushed: 2025-10-14T06:38:42Z

Default branch: main

Fork: no

Archived: no

README: [中文阅读](./README_CN.md)

&nbsp&nbsp🤗 HuggingFace&nbsp&nbsp | 💻 Official website(官网) Try our model!&nbsp&nbsp

👏 Join our WeChat and Discord

-----

This repo contains PyTorch model definitions, pretrained weights and inference/sampling code for our HunyuanImage-2.1. You can directly try our model on Official website(官网) and find more visualizations on our project page.

🔥🔥🔥 Latest Updates

  • September 18, 2025: ✨ Try the PromptEnhancer-32B model for higher-quality prompt enhancement!​.
  • September 18, 2025: ✨ ComfyUI workflow of HunyuanImage-2.1 is available now!
  • September 16, 2025: 👑 We achieved the Top1 on Arena's leaderboard for text-to-image open-source models. Leaderboard
  • September 12, 2025: 🚀 Released FP8 quantized models! Making it possible to generate 2K images with only 24GB GPU memory!
  • September 8, 2025: 🚀 Released inference code and model weights for HunyuanImage-2.1.

Introduction

We are excited to introduce HunyuanImage-2.1, a 17B text-to-image model that is capable of generating 2K (2048 × 2048) resolution images.

Our architecture consists of two stages: 1. ​Base text-to-image Model:​​ The first stage is a text-to-image model that utilizes two text encoders: a multimodal large language model (MLLM) to improve image-text alignment, and a multi-language, character-aware encoder to enhance text rendering across various languages. 2. Refiner Model: The second stage introduces a refiner model that further enhances image quality and clarity, while minimizing artifacts.

👑 We achieved the Top1 on Arena's leaderboard for text-to-image open-source models.

🎉 HunyuanImage-2.1 Key Features

  • High-Quality Generation: Efficiently produces ultra-high-definition (2K) images with cinematic composition.
  • Multilingual Support: Provides native support for both Chinese and English prompts.
  • Advanced Architecture: Built on a multi-modal, single- and dual-stream combined DiT (Diffusion Transformer) backbone.
  • Glyph-Aware Processing: Utilizes ByT5's text rendering capabilities for improved text generation accuracy.
  • Flexible Aspect Ratios: Supports a variety of image aspect ratios (1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3).
  • Prompt Enhancement: Automatically rewrites prompts to improve descriptive accuracy and visual quality.

📜 System Requirements

Hardware and OS Requirements:

  • NVIDIA GPU with CUDA support.

Minimum requrement for now: 24 GB GPU memory for 2048x2048 image generation.

> Note: The memory requirements above are measured with model CPU offloading and FP8 quantization enabled. If your GPU has sufficient memory, you may disable offloading for improved inference speed.

  • Supported operating system: Linux.

🛠️ Dependencies and Installation

1. Clone the repository:

git clone https://github.com/Tencent-Hunyuan/HunyuanImage-2.1.git
cd HunyuanImage-2.1

2. Install dependencies:

pip install -r requirements.txt
pip install flash-attn==2.7.3 --no-build-isolation

🧱 Download Pretrained Models

The details of download pretrained models are shown [here](ckpts/checkpoints-download.md).

🔑 Usage

Prompt Enhancement

Prompt enhancement plays a crucial role in enabling our model to generate high-quality images. By writing longer and more detailed prompts, the generated image will be significantly improved. We encourage you to craft comprehensive and descriptive prompts to achieve the best possible image quality.

We highly recommend you to try the PromptEnhancer-32B model for higher-quality prompt enhancement.

Text to Image

HunyuanImage-2.1 only supports 2K image generation (e.g. 2048x2048 for 1:1 images, 2560x1536 for 16:9 images, etc.). Generating images with 1K resolution will result in artifacts.

Additionally, we highly recommend using the full generation pipeline for better quality (i.e. enabling prompt enhancement and refinment).

| model type | model name | description | num_inference_steps | guidance_scale | shift | |--------------------------|---------------------------|-----------------------------------------|---------------------|----------------|-------| | Base text-to-image Model | hunyuanimage2.1 | Undistilled model for the best quality. | 50 | 3.5 | 5 | | Distilled text-to-image Model | hunyuanimage2.1-distilled | Distilled model for faster inference | 8 | 3.25 | 4 | | Refiner | hunyuanimage-refiner | The refiner model | N/A | N/A | N/A |

import os
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
import torch
from hyimage.diffusion.pipelines.hunyuanimage_pipeline import HunyuanImagePipeline

# Supported model_name: hunyuanimage-v2.1, hunyuanimage-v2.1-distilled
model_name = "hunyuanimage-v2.1"
pipe = HunyuanImagePipeline.from_pretrained(model_name=model_name, use_fp8=True)
pipe = pipe.to("cuda")

# The input prompt
prompt = "A cute, cartoon-style anthropomorphic penguin plush toy with fluffy fur, standing in a painting studio, wearing a red knitted scarf and a red beret with the word \"Tencent\" on it, holding a paintbrush with a focused expression as it paints an oil painting of the Mona Lisa, rendered in a photorealistic photographic style."

# Generate with different aspect ratios
aspect_ratios = {
"16:9": (2560, 1536),
"4:3": (2304, 1792),
"1:1": (2048, 2048),
"3:4": (1792, 2304),
"9:16": (1536, 2560),
}

width, height = aspect_ratios["1:1"]

image = pipe(
prompt=prompt,
width=width,
height=height,
# disable the reprompt if you already use the prompt enhancement to enhance the prompt
use_reprompt=False, # Enable prompt enhancement (which may result in higher GPU memory usage)
use_refiner=True, # Enable refiner model
# For the distilled model, use 8 steps for faster inference.
# For…

Excerpt shown — open the source for the full document.

Notability

notability 6.0/10

Notable image model release, moderate traction