PromptEnhancer

Hunyuan-PromptEnhancer活跃维护

把随手写的提示词改写成更清晰、结构化的版本,让文生图和图像编辑模型生成效果更稳定。

[CVPR 2026] PromptEnhancer is a prompt-rewriting tool, refining prompts into clearer, structured versions for better image generation.

暂无版本3,803star +2 / 7 天328fork同步于 2026-11-10 05:39 UTC

怎么上手

由 README 提炼,执行前请确认
pip install -r requirements.txt
huggingface-cli download tencent/HunyuanImage-2.1/reprompt --local-dir ./models/promptenhancer-7b
硬件要求按 README 说明

7B 模型需 8GB+ 显存,32B 全精度需 32GB+;GGUF 量化版按档位需 20GB(RTX 3090/4080)、27GB(RTX 4090/5090)、35GB(H100/A100)显存。README 未说明纯 CPU 运行方案。

需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

腾讯混元开源的提示词改写工具,把口语化 prompt 重写成结构化版本以提升出图质量

把随手写的提示词改写成更清晰、结构化的版本,让文生图和图像编辑模型生成效果更稳定。

核心能力

  • 用思维链方式重写提示词并保留主体、动作、风格等原始意图
  • 同时支持文生图提示词增强和图生图编辑指令改写
  • 提供多级回退解析机制保证输出稳定可用
  • 支持 7B/32B 全精度、GGUF 量化及视觉语言模型多种后端
  • 附带 T2I-Keypoints-Eval 评测脚本与数据集

容易踩的坑

模型需单独从 HuggingFace 下载,仓库不含权重;GGUF 量化推理需改用 script/install_gguf.sh 安装 llama.cpp 后端,与标准安装不通用;图生图编辑模型基于 Qwen2.5-VL,与纯文本模型是不同权重。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    PromptEnhancer: A Simple Approach to Enhance Text-to-Image Models via Chain-of-Thought Prompt Rewriting

    Linqing Wang †· Ximing Xing · Zhiyong Xu · Yiji Cheng · Zhiyuan Zhao · Donghao Li · Tiankai Hang · Zhenxi Li · Jiale Tao · QiXun Wang · Ruihuang Li · Comi Chen · Xin Li · Mingrui Wu · Xinchi Deng · Shuyang Gu · Chunyu Wang* · Qinglin Lu

    Tencent Hunyuan

    †Project Lead · *Corresponding Author


    Overview

    Hunyuan-PromptEnhancer is a prompt rewriting utility that supports both Text-to-Image generation and Image-to-Image editing. It restructures input prompts while preserving original intent, producing clearer, structured prompts for downstream image generation tasks.

    Key Features:

    • Dual-mode support: Text-to-Image prompt enhancement and Image-to-Image editing instruction refinement with visual context
    • Intent preservation: Maintains all key elements (subject, action, style, layout, attributes, etc.) across rewriting
    • Robust parsing: Multi-level fallback mechanism ensures reliable output
    • Flexible deployment: Supports full-precision (7B/32B), quantized (GGUF), and vision-language models

    🔥🔥🔥Updates

    Installation

    Option 1: Standard Installation (Recommended)

    pip install -r requirements.txt
    

    Option 2: GGUF Installation (For quantized models with CUDA support)

    chmod +x script/install_gguf.sh && ./script/install_gguf.sh
    

    💡 Tip: Choose GGUF installation if you want faster inference with lower memory usage, especially for the 32B model.

    Model Download

    🎯 Quick Start

    For most users, we recommend starting with the PromptEnhancer-7B model:

    # Download PromptEnhancer-7B (13GB) - Best balance of quality and efficiency
    huggingface-cli download tencent/HunyuanImage-2.1/reprompt --local-dir ./models/promptenhancer-7b
    

    📊 Model Comparison & Selection Guide

    ModelSizeQualityMemoryBest For
    PromptEnhancer-7B13GBHigh8GB+Most users, balanced performance
    PromptEnhancer-32B64GBHighest32GB+Research, highest quality needs
    32B-Q8_0 (GGUF)35GBHighest35GB+High-end GPUs (H100, A100)
    32B-Q6_K (GGUF)27GBExcellent27GB+RTX 4090, RTX 5090
    32B-Q4_K_M (GGUF)20GBGood20GB+RTX 3090, RTX 4080

    Standard Models (Full Precision)

    # PromptEnhancer-7B (recommended for most users)
    huggingface-cli download tencent/HunyuanImage-2.1/reprompt --local-dir ./models/promptenhancer-7b
    
    # PromptEnhancer-32B (for highest quality)
    huggingface-cli download PromptEnhancer/PromptEnhancer-32B --local-dir ./models/promptenhancer-32b
    
    # PromptEnhancer-Img2Img-Edit (for image editing tasks)
    huggingface-cli download PromptEnhancer/PromptEnhancer-Img2img-Edit --local-dir ./models/promptenhancer-img2img-edit
    

    GGUF Models (Quantized - Memory Efficient)

    Choose one based on your GPU memory:

    # Q8_0: Highest quality (35GB)
    huggingface-cli download mradermacher/PromptEnhancer-32B-GGUF PromptEnhancer-32B.Q8_0.gguf --local-dir ./models
    
    # Q6_K: Excellent quality (27GB) - Recommended for RTX 4090
    huggingface-cli download mradermacher/PromptEnhancer-32B-GGUF PromptEnhancer-32B.Q6_K.gguf --local-dir ./models
    
    # Q4_K_M: Good quality (20GB) - Recommended for RTX 3090/4080
    huggingface-cli download mradermacher/PromptEnhancer-32B-GGUF PromptEnhancer-32B.Q4_K_M.gguf --local-dir ./models
    

    🚀 Performance Tip: GGUF models offer 50-75% memory reduction with minimal quality loss. Use Q6_K for the best quality/memory trade-off.

    Quickstart

    Using HunyuanPromptEnhancer (Text-to-Image)

    from inference.prompt_enhancer import HunyuanPromptEnhancer
    
    models_root_path = "./models/promptenhancer-7b"
    
    enhancer = HunyuanPromptEnhancer(models_root_path=models_root_path, device_map="auto")
    
    # 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)
    

    Using PromptEnhancerImg2Img (Image Editing)

    For image editing tasks where you want to enhance editing instructions based on input images:

    from inference.prompt_enhancer_img2img import PromptEnhancerImg2Img
    
    # Initialize the image-to-image prompt enhancer
    enhancer = PromptEnhancerImg2Img(
        model_path="./models/your-model",
        device_map="auto"
    )
    
    # Enhance an editing instruction with image context
    edit_instruction = "Remove the watermark from the bottom"
    image_path = "./examples/sample_image.png"
    
    enhanced_prompt = enhancer.predict(
        edit_instruction=edit_instruction,
        image_path=image_path,
        temperature=0.1,
        top_p=0.9,
        max_new_tokens=2048
    )
    
    print("Enhanced editing prompt:", enhanced_prompt)
    

    Using GGUF Models (Quantized, Faster)

    from inference.prompt_enhancer_gguf import PromptEnhancerGGUF
    
    # Auto-detects Q8_0 model in models/ folder
    enhancer = PromptEnhancerGGUF(
        model_path="./models/PromptEnhancer-32B.Q8_0.gguf",  # Optional: auto-detected
        n_ctx=1024,        # Context window size
        n_gpu_layers=-1,   # Use all GPU layers
    )
    
    # Enhance a prompt
    user_prompt = "woman in jungle"
    enhanced_prompt = enhancer.predict(
        user_prompt,
        temperature=0.3,
        top_p=0.9,
        max_new_tokens=512,
    )
    
    print("Enhanced:", enhanced_prompt)
    

    Command Line Usage (GGUF)

    # Simple usage - auto-detects model in models/ folder
    python inference/prompt_enhancer_gguf.py
    
    # Or specify model path
    GGUF_MODEL_PATH="./models/PromptEnhancer-32B.Q8_0.gguf" python inference/prompt_enhancer_gguf.py
    

    GGUF Model Benefits

    🚀 Why use GGUF models?

    • Memory Efficient: 50-75% less VRAM usage compared to full precision models
    • Faster Inference: Optimized for CPU and GPU acceleration with llama.cpp
    • Quality Preserved: Q8_0 and Q6_K maintain excellent output quality
    • Easy Deployment: Single file format, no complex dependencies
    • GPU Acceleration: Full CUDA support for high-performance inference
    ModelSizeQualityVRAM UsageBest For
    Q8_035GBHighest~35GBHigh-end GPUs (H100, A100)
    Q6_K27GBExcellent~27GBRTX 4090, RTX 5090
    Q4_K_M20GBGood~20GBRTX 3090, RTX 4080

    Usage Comparison

    ModelInput TypeUse CaseModel Backend
    HunyuanPromptEnhancerText onlyText-to-Image generationTransformers (7B/32B)
    PromptEnhancerImg2ImgText + ImageImage editing tasksTransformers (32B)
    PromptEnhancerGGUFText onlyMemory-efficient T2Illama.cpp (quantized)

    Parameters

    Standard Models (Transformers)

    • models_root_path: Local path or repo id; supports trust_remote_code models.
    • device_map: Device mapping (default auto).
    • 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.

    GGUF Models

    • model_path (str): Path to GGUF model file (auto-detected if in models/ folder).
    • n_ctx (int): Context window size (default: 8192, recommended: 1024 for short prompts).
    • n_gpu_layers (int): Number of layers to offload to GPU (-1 for all layers).
    • verbose (bool): Enable verbose logging from llama.cpp.

    Image-to-Image Models (PromptEnhancerImg2Img)

    • model_path (str): Path to the pretrained Qwen2.5-VL model.
    • device_map (str): Device mapping for model loading (default: auto).
    • predict(...):
      • edit_instruction (str): Original editing instruction.
      • image_path (str): Path to the input image file.
      • sys_prompt (str): Optional system prompt (uses default if None).
      • temperature (float): Sampling temperature (default: 0.1).
      • top_p (float): Nucleus sampling threshold (default: 0.9).
      • max_new_tokens (int): Maximum tokens to generate (default: 2048).

    Citation

    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 Donghao, Li and Tiankai, Hang and Zhenxi, Li and Tao, Jiale and Wang, QiXun and Li, Ruihuang and Chen, Comi and Li, Xin and Wu, Mingrui and Deng, Xinchi and Gu, Shuyang and Wang, Chunyu and Lu, Qinglin},
      journal={arXiv preprint arXiv:2509.04545},
      year={2025}
    }
    

    Acknowledgements

    We would like to thank the following open-source projects and communities for their contributions to open research and exploration: Transformers and HuggingFace.

    Contact

    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 ([email protected]).

    Github Star History

    Star History

    Star History Chart