NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

DiffBench Meets DiffAgent: End-to-End LLM-Driven Diffusion Acceleration Code Generation

Jiajun Jiao, Haowei Zhu, Puyuan Yang, Jianghui Wang, Ji Liu, Ziqiong Liu, Dong Li, Yuejian Fang, Jun-Hai Yong, Bin Wang, Emad Barsoum

TL;DR

Researchers have introduced DiffBench and DiffAgent, a combined framework that uses Large Language Models (LLMs) to automatically write and optimize code for accelerating diffusion models. By using a closed-loop system powered by a genetic algorithm, DiffAgent can navigate the complex trade-offs between image quality and generation speed, outperforming standard LLMs by up to 81% in producing functional, high-performance inference code.

What Problem Does This Paper Address?

Diffusion models (like Stable Diffusion) are the gold standard for high-fidelity image and video generation, but they have a major flaw: they are incredibly slow. Because they generate data through an iterative "denoising" process, they require dozens of computational steps to produce a single image.

While many acceleration techniques exist—such as DeepCache (reusing features), ToMe (merging tokens), and T-Gate (skipping steps)—combining them effectively is a "black art." It requires deep expertise to know which methods work together for a specific model architecture (U-Net vs. Transformer) and hardware target without destroying the output quality. Current LLMs often fail at this task because they lack domain-specific "intuition" and a way to test if the code they've written actually meets performance targets.

Methods

The authors propose a two-part solution:

  1. DiffAgent: A multi-agent system designed to automate the optimization workflow. It consists of:
  2. Planning Agent: Breaks down the user's request into a strategy.
  3. Coding Agent: Generates the actual Python code using a "Knowledge Base" of pre-vetted acceleration templates.
  4. Debugging Agent: Uses a "Reflexion" strategy to identify and fix execution errors iteratively.
  5. Genetic Algorithm (GA) Selector: This is the core innovation. It treats different code versions as a "population," evaluates them in a real execution environment, and selects the best-performing versions to "breed" the next generation of optimized code.
  6. The Closed-Loop Workflow: Unlike a standard LLM that just "guesses" the code, DiffAgent runs the code, measures the actual latency and image quality (using CLIP scores), and feeds that data back into the system to refine the implementation until it hits the user's specific speedup targets (e.g., "Make this 4x faster with less than 5% quality loss").

Datasets

The paper introduces DiffBench, a new benchmark specifically for this task. It includes:

  • 604 Prompts: Ranging from simple pipeline setup to complex multi-method optimization with strict latency constraints.
  • Diverse Architectures: Covers U-Net models (SD1.5, SD2.1, SDXL) and Transformer-based models (DiT, PixArt-α/Σ).
  • Five Difficulty Levels:
    • Levels 1-3: Basic setup and single/compositional acceleration.
  • Levels 4-5: Optimization against explicit speedup targets and hardware-specific latency constraints.

Key Insights and Ideas

  • LLMs are "Acceleration Blind" Out of the Box: Standard models like GPT-4 or Claude 3.5 Sonnet have pass rates below 35% on complex acceleration tasks. They struggle to balance the "quality vs. speed" trade-off without environmental feedback.
  • The Power of the Genetic Algorithm: The GA module was found to be essential for Level 4 and 5 tasks. Without it, the system's ability to find a valid solution dropped from ~56% to a mere 6%.
  • Domain Knowledge is a Force Multiplier: Providing the LLM with a "Knowledge Base" of reference implementations for specific acceleration methods was the single biggest contributor to overall success, reducing the absolute error rate by nearly 17%.
  • Synergy over Individual Parts: The agents (Planning, Coding, Debugging) and the GA work synergistically; removing any one component leads to a significant performance degradation.

Key Results

  • Massive Performance Gains: DiffAgent improved the pass rate of Claude 3.5 Sonnet from 54.30% to 81.59% and o3-mini from 11.92% to 56.46%.
  • Error Reduction: In high-difficulty scenarios (Level 5), DiffAgent reduced "Compile Errors" from over 31% to just 2.15%.
  • Pareto Optimization: DiffAgent successfully produced code that achieved 4x speedups on hardware while maintaining image quality within a 5% threshold—a task that standard LLMs almost never completed successfully.

Limitations and Future Work

  • Hardware Dependency: The system requires access to the target hardware (e.g., a specific GPU) during the optimization loop to provide accurate latency feedback.
  • Search Time: Because it uses a genetic algorithm and iterative debugging, generating the final "perfect" code takes more time and API calls than a single-shot LLM prompt.
  • Library Constraints: The current system is limited to the acceleration techniques included in its Knowledge Base. Future work could involve allowing the agent to "discover" or implement entirely new acceleration mathematical kernels from scratch.

Summary updated

BibTeX
@inproceedings{jiao2026diffbench,
  author = {Jiajun Jiao and Haowei Zhu and Puyuan Yang and Jianghui Wang and Ji Liu and Ziqiong Liu and Dong Li and Yuejian Fang and Jun-Hai Yong and Bin Wang and Emad Barsoum},
  title = {{DiffBench Meets DiffAgent: End-to-End LLM-Driven Diffusion Acceleration Code Generation}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  doi = {10.1609/aaai.v40i27.39395},
}
Figure