DiffAgent: Fast and Accurate Text-to-Image API Selection with Large Language Model

Lirui Zhao, Yue Yang, Kaipeng Zhang, Wenqi Shao, Yuxin Zhang, Yu Qiao, Ping Luo, Rongrong Ji

Introduction

The open-source generative AI community has seen an explosion of specialized models. Platforms like Civitai host over 70,000 community-contributed models, including Checkpoints and LoRAs, tailored for specific artistic styles such as pixel art, 3D animation, or oil painting. While this variety offers immense creative potential, it introduces a "paradox of choice." Finding the optimal model and hyperparameters (e.g., CFG scale, sampling steps) for a specific prompt typically requires a tedious, multi-hour trial-and-error process. Standard models like Stable Diffusion XL often fail to capture niche styles without extensive prompt engineering.

DiffAgent is a Large Language Model (LLM) agent designed to automate this selection process. By identifying the ideal "API call"—the specific combination of model and settings—DiffAgent can fulfill complex stylistic requests in seconds, significantly outperforming generic base models in both aesthetic quality and prompt adherence.

DiffAgent automates the search through 70K+ models, finding the right one in seconds compared to hours of manual user attempts.

The SFTA Training Framework

To transform a general-purpose LLM (specifically LLaMA-2-7B) into a specialized text-to-image (T2I) agent, the researchers developed a two-stage training framework called SFTA (Supervised Fine-Tuning and Alignment).

Stage 1: DiffAgent-SFT

In the first stage, the model undergoes supervised fine-tuning on the DABench dataset. This process teaches the agent the basic syntax required to respond to user prompts with structured API calls. These calls include specific model names and the necessary generation parameters.

Stage 2: DiffAgent-RRHF

To align the agent's selections with human aesthetic preferences, the authors employed the Rank Responses to Align Human Feedback (RRHF) algorithm. During this stage, the agent generates multiple potential API calls for a single prompt. These responses are ranked by a reward model that evaluates the resulting images using a "Unified Metric" (a combination of CLIP Score, ImageReward, and HPS v2). This alignment stage is critical for reducing "hallucinations," ensuring the agent suggests models that both exist and accurately match the requested style.

The SFTA training framework, showing the transition from basic fine-tuning (SFT) to human-preference alignment (RRHF).

DABench: A Specialized Dataset for API Selection

The foundation of DiffAgent's performance is DABench, a high-quality dataset curated from the Civitai community.

  • Scale and Scope: DABench contains 50,482 instruction-API pairs, covering 39,670 pairs for Stable Diffusion 1.5 and 10,812 for SDXL.
  • Data Quality: The authors utilized GPT-3.5-turbo to reconstruct missing or inadequate model descriptions by analyzing sample images and metadata. This ensures the LLM learns from high-quality, descriptive text.
  • Processing: The pipeline includes rigorous filtering for quality and NSFW content to maintain a high standard for training data.

Key Results and Insights

DiffAgent demonstrates that LLMs can serve as highly effective "routers" for specialized generative tasks when provided with structured data and proper alignment.

  • Efficiency: DiffAgent selects the appropriate model and parameters in approximately 4.81 seconds on a single A100 GPU.
  • Performance Gains: On the SD 1.5 architecture, DiffAgent achieved a 40% improvement in the Unified Metric compared to the base model.
  • Human Preference: User studies reveal an 86% win rate for DiffAgent over baselines in aesthetic preference and a 78% win rate for prompt relevance.
  • Alignment Impact: The RRHF stage reduced hallucination errors by over 20%, proving that supervised learning alone is insufficient for accurate model selection.

Conclusion and Future Directions

While DiffAgent currently focuses on the Stable Diffusion ecosystem, its success points toward a future where AI agents manage the complexity of vast model libraries. Future work includes expanding the agent's scope to newer architectures like Flux, incorporating direct human-in-the-loop feedback, and developing methods for dynamic updates as new models are released. By turning a manual search into a "one-shot" automated process, DiffAgent makes the wealth of community-contributed AI models accessible to all users.

Summary updated

BibTeX
@inproceedings{zhao2024diffagent,
  author = {Lirui Zhao and Yue Yang and Kaipeng Zhang and Wenqi Shao and Yuxin Zhang and Yu Qiao and Ping Luo and Rongrong Ji},
  title = {{DiffAgent: Fast and Accurate Text-to-Image API Selection with Large Language Model}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2024},
}
Figure