On Discrete Prompt Optimization for Diffusion Models
Ruochen Wang, Ting Liu, Cho-Jui Hsieh, Boqing Gong
TL;DR
This paper tackles the problem of aligning text prompts with diffusion-model outputs by formulating prompt engineering as a discrete optimization over natural language. It introduces DPO-Diff, a gradient-based framework that uses compact, dynamically generated word subspaces and a novel Shortcut Text Gradient to backpropagate through diffusion inference with constant memory. The approach supports both prompt enhancement and adversarial prompt discovery, leveraging Gumbel-Softmax relaxation and Evolutionary Search to efficiently explore candidate prompts; negative prompts via Antonym Space notably outperform positive synonym-based prompts in practice. Empirical results across DiffusionDB, COCO, and ChatGPT-derived prompts show that DPO-Diff can outperform human-engineered prompts and prior baselines in faithfulness and attack efficacy, with supportive human evaluations. The work highlights a complementary paradigm to learning-based methods, offering a train-free, scalable avenue for prompt optimization in text-to-image diffusion systems, with implications for debugging, safety, and content quality.
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.
