PromptEnhancer: A Simple Approach to Enhance Text-to-Image Models via Chain-of-Thought Prompt Rewriting
Linqing Wang · Ximing Xing · Yiji Cheng · Zhiyuan Zhao · Jiale Tao · QiXun Wang · Ruihuang Li · Comi Chen · Xin Li · Mingrui Wu · Xinchi Deng · Chunyu Wang† · Qinglin Lu*
Tencent Hunyuan
†Project Lead · *Corresponding Author
Hunyuan-PromptEnhancer is a prompt rewriting utility built on top of Tencent's Hunyuan models. It restructures an input prompt while preserving the original intent, producing clearer, layered, and logically consistent prompts suitable for downstream image generation or similar tasks.
- Preserves intent across key elements (subject/action/quantity/style/layout/relations/attributes/text, etc.).
- Encourages a "global–details–summary" narrative, describing primary elements first, then secondary/background elements, ending with a concise style/type summary.
- Robust output parsing with graceful fallback: prioritizes
<answer>...</answer>
; if missing, removes<think>...</think>
and extracts clean text; otherwise falls back to the original input. - Configurable inference parameters (temperature, top_p, max_new_tokens) for balancing determinism and diversity.
pip install -r requirements.txt
huggingface-cli download tencent/HunyuanImage-2.1/reprompt --local-dir ./models/
from inference.prompt_enhancer import HunyuanPromptEnhancer
# 1) Provide a local path or a repo id, e.g., "tencent/Hunyuan-7B-Instruct"
models_root_path = "./models/"
# 2) Initialize (device_map respects your configuration)
enhancer = HunyuanPromptEnhancer(models_root_path=models_root_path, device_map="auto")
# 3) Enhance a prompt (Chinese or English)
user_prompt = "Third-person view, a race car speeding on a city track..."
new_prompt = enhancer.predict(
prompt_cot=user_prompt,
# Default system prompt is tailored for image prompt rewriting; override if needed
temperature=0.7, # >0 enables sampling; 0 uses deterministic generation
top_p=0.9,
max_new_tokens=256,
)
print("Enhanced:", new_prompt)
models_root_path
: Local path or repo id; supportstrust_remote_code
models.device_map
: Device mapping (defaultauto
).predict(...)
:prompt_cot
(str): Input prompt to rewrite.sys_prompt
(str): Optional system prompt; a default is provided for image prompt rewriting.temperature
(float):>0
enables sampling;0
for deterministic generation.top_p
(float): Nucleus sampling threshold (effective when sampling).max_new_tokens
(int): Maximum number of new tokens to generate.
- open source PromptEnhancerV2-32B model
This project is distributed under the terms specified in LICENSE
.
If you find this project useful, please consider citing:
@article{promptenhancer,
title={PromptEnhancer: A Simple Approach to Enhance Text-to-Image Models via Chain-of-Thought Prompt Rewriting},
author={Wang, Linqing and Xing, Ximing and Cheng, Yiji and Zhao, Zhiyuan and Tao, Jiale and Wang, QiXun and Li, Ruihuang and Chen, Comi and Li, Xin and Wu, Mingrui and Deng, Xinchi and Wang, Chunyu and Lu, Qinglin},
journal={arXiv preprint arXiv:2509.04545},
year={2025}
}
We would like to thank the following open-source projects and communities for their contributions to open research and exploration: Transformers and HuggingFace.
If you would like to leave a message for our R&D and product teams, Welcome to contact our open-source team . You can also contact us via email (hunyuan_opensource@tencent.com).