On Discrete Prompt Optimization for Diffusion Models

Ruochen Wang, Ting Liu, Cho-Jui Hsieh, Boqing Gong
2/12/2026

No official code found. Best implementation: ruocwang/dpo-diffusion (64 stars, last commit 2024-08-14).

Abstract

This paper introduces the first gradient-based framework for prompt optimization in text-to-image diffusion models. We formulate prompt engineering as a discrete optimization problem over the language space. Two major challenges arise in efficiently finding a solution to this problem: (1) Enormous Domain Space: Setting the domain to the entire language space poses significant difficulty to the optimization process. (2) Text Gradient: Efficiently computing the text gradient is challenging, as it requires backpropagating through the inference steps of the diffusion model and a non-differentiable embedding lookup table. Beyond the problem formulation, our main technical contributions lie in solving the above challenges. First, we design a family of dynamically generated compact subspaces comprised of only the most relevant words to user input, substantially restricting the domain space. Second, we introduce"Shortcut Text Gradient"-- an effective replacement for the text gradient that can be obtained with constant memory and runtime. Empirical evaluation on prompts collected from diverse sources (DiffusionDB, ChatGPT, COCO) suggests that our method can discover prompts that substantially improve (prompt enhancement) or destroy (adversarial attack) the faithfulness of images generated by the text-to-image diffusion model.

View on arXivView PDF

Code Implementations(1)

[ICML 2024] On Discrete Prompt Optimization for Diffusion Models - Google

642Shell, PythonJun 26, 20242 years ago

Similar Papers

Cite this paper

@article{wang2026discrete,
  title  = {On Discrete Prompt Optimization for Diffusion Models},
  author = {Ruochen Wang and Ting Liu and Cho-Jui Hsieh and Boqing Gong},
  year   = {2026},
  eprint = {2407.01606},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2407.01606},
  journal = {ICML 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2407.01606.svg)](https://codeofpaper.com/paper/2407.01606)

Discussion