# HunyuanImage 2.1

> Open 17B diffusion model for 2K text-to-image generation

- Category: Multimodal Generation / Image Generation
- Language: Python
- Repository: https://github.com/Tencent-Hunyuan/HunyuanImage-2.1
- Website: https://hunyuan.tencent.com
- Canonical page: https://ai-tldr.dev/tools/hunyuanimage-2-1/

## In short

HunyuanImage 2.1 is an open text-to-image diffusion model from Tencent. It is a 17B-parameter model that generates images at 2K resolution (for example, 2048x2048 for 1:1 or 2560x1536 for 16:9). It sits in the Image Generation category of the Multimodal Generation tools and is open-source, written in Python. To get started: clone the repository.

## Overview

HunyuanImage 2.1 is an open text-to-image diffusion model from Tencent. It is a 17B-parameter model that generates images at 2K resolution (for example, 2048x2048 for 1:1 or 2560x1536 for 16:9). The repo ships PyTorch model definitions, pretrained weights, and inference code so you can run generation locally.

It is built for developers and researchers who want to run a high-resolution image generator on their own NVIDIA GPU rather than calling a hosted API. The pipeline uses two stages: a base text-to-image model with two text encoders, and a refiner model that cleans up image quality and reduces artifacts. Prompt enhancement can rewrite short prompts into longer, more detailed ones.

Within the image-generation category, it stands out for native Chinese and English support, glyph-aware text rendering, and FP8 quantization that brings 2K generation down to about 24GB of GPU memory with CPU offloading enabled.

## What it does

- Generates 2K (2048x2048) images; note the model only supports 2K output, and 1K resolution produces artifacts
- Native support for both Chinese and English prompts
- Two-stage pipeline: a base DiT text-to-image model plus a refiner model for higher clarity
- FP8 quantized weights let you generate 2K images on a 24GB GPU with CPU offloading
- Flexible aspect ratios including 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, and 2:3
- Glyph-aware text rendering using ByT5 for more accurate text in images, plus optional automatic prompt enhancement

## Getting started

HunyuanImage 2.1 runs on Linux with an NVIDIA CUDA GPU (24GB minimum for 2K with FP8 and offloading). Clone the repo, install dependencies, download the weights, then run the inference pipeline.

1. Clone the repository

   Get the source code from GitHub and move into the project directory.

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

2. Install dependencies

   Install the Python requirements plus a matching flash-attn build.

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

3. Download pretrained models

   Follow the checkpoint download guide in the repo (ckpts/checkpoints-download.md) to fetch the base, distilled, and refiner weights before running inference.

4. Generate a 2K image

   Load the pipeline with FP8 enabled, pick a supported 2K aspect ratio, and run a prompt. The model only supports 2K output.

```python
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")

prompt = "A cute, cartoon-style anthropomorphic penguin plush toy painting the Mona Lisa, photorealistic."

# 2K aspect ratios: 16:9=(2560,1536), 4:3=(2304,1792), 1:1=(2048,2048), 3:4=(1792,2304), 9:16=(1536,2560)
width, height = 2048, 2048

image = pipe(prompt=prompt, width=width, height=height)
```

## When to use it

- Self-hosting a high-resolution text-to-image generator on your own NVIDIA GPU instead of using a paid API
- Producing 2K marketing, concept-art, or illustration images in a range of aspect ratios
- Generating images that need accurate Chinese or English text rendered inside them
- Research and experimentation on diffusion-transformer pipelines, refiner models, and prompt enhancement
