DDPT: Diffusion-Driven Prompt Tuning for Large Language Model Code Generation
Jinyang Li, Sangwon Hyun, M. Ali Babar · 2025
Read DDPT: Diffusion-Driven Prompt Tuning for Large Language Model Code Generation by Jinyang Li, Sangwon Hyun, M. Ali Babar (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2504-04351.txt.
Introduction
Jinyang Li, Sangwon Hyun, and M. Ali Babar automate prompt crafting for code-writing language models. Their 2025 paper notes that output code quality hinges on prompt shape, yet good prompts demand rare skill to build by hand. Their method learns to grow a top prompt embedding from plain noise.
A diffusion model trains on the code loss signal from the language model itself. That training teaches it the spread of near-best prompt embeddings. At use time, the model walks a path from noise to that best zone in the sampling phase. Tests show the approach lifts prompt optimization for code generation. The work frames prompt tuning as a generative task rather than a hand craft.
Catalog record
| CREATOR | Jinyang Li, Sangwon Hyun, M. Ali Babar |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 43 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2504-04351
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
DDPT: Diffusion-Driven Prompt Tuning for Large Language Model Code Generation Jinyang Li, Sangwon Hyun, M. Ali Babar Abstract Large Language Models (LLMs) have demonstrated remarkable capabilities in code generation. However, the quality of the generated code is heavily dependent on the structure and composition of the prompts used. Crafting high-quality prompts is a challenging task that requires significant knowledge and skills of prompt engineering. To advance the automation support for the prompt engineering for LLM-based code generation, we propose a novel solution Diffusion-Driven Prompt Tuning (DDPT) that learns how to generate optimal prompt embedding from Gaussian Noise to automate the prompt engineering for code generation. We evaluate the feasibility of diffusion-based optimization and abstract the optimal prompt embedding as a directional vector toward the optimal embedding. We use the code generation loss given by the LLMs to help the diffusion model capture the distribution of optimal prompt embedding during training. The trained diffusion model can build a path from the noise distribution to the optimal distribution at the sampling phrase, the evaluation result demonstrates that DDPT helps improve the prompt optimization for code generation. I Introduction Fig. 1 : A diagram showing our diffusion-based training process. We first split each input sentence into context and instructions and transform them into word vector embeddings before feeding them into the diffusion model. Gray-colored components indicate Gaussian noise elements and the frozen LLM. GT stands for Ground Truth and text elements that are discrete are highlighted in pink. Large Language Models (LLMs), also called foundation models, like ChatGPT [ 1 ] have garnered significant attention due to their remarkable ability to comprehend human language and generate text outputs accordingly. Based on their large-scale parameter sizes and a broad range of training datasets, several efforts have shown that LLMs can also be successfully applied code generation tasks [ 2 ] . Using NL2Code (natural-language-to-code) [ 2 ] configuration, a code generation model takes natural language instruction as input and outputs code snippets. However, due to the large sizes of the foundation models and the the context window size limitation [ 3 ] , that limits the number of tokens LLM can proceed, instructing a model to perform accurately is considered a challenge. While it is possible to fine-tune a model using various datasets, the associated computational overhead can be a significant obstacle, particularly with large size LLMs. Prompt engineering, which focuses on improving the quality of prompt structure, template, and composition, has emerged as a promising solution [ 4 ] to obtain the desired output from a LLM. The fundamental premise of prompt engineering is to retrieve the learned knowledge embedding within a language model through the optimization of prompt structure, template, and token selection [ 4 , 5 ] . In this setting, a language model is kept ‘frozen‘ and is often referred to as a Pre-trained Language Model (PTM) to avoid the huge computational overhead caused by fine-tuning the modern LLMs. However, prompt engineering is still a time-consuming process. Significant manual labor efforts are needed to explore the optimal structure of the prompts, and manually searching for the most downstream task-related keywords that provide conditioning to the model is a highly tedious process [ 4 ] . Several studies have addressed the difficulty of producing optimized prompts by automating the prompt engineering process at the prompt embedding level. For example, Black Box Tuning (BBT) [ 6 ] uses a derivative-free Evolution algorithm to produce samples of prompt candidates with lower dimensions than the original prompt sample and uses a random projection matrix to project it back to the dimension of the original sample and add them. Prompt Tuning [ 7 ] proposed to prepend a fixed number of update-able tokens to the original prompt, these tokens have associated trainable parameters and can be updated by gradient computed from language modeling losses on the downstream objective. Prefix tuning [ 8 ] is similar to prompt tuning whereas the trainable prompt embedding is prepended to every layer of the model instead of only the input prompt embedding. P-tuning [ 9 ] employs a prompt encoder to optimize trainable prompt embeddings, and the insertion of the embedding is not restricted to prepend. Many of the above-mentioned approaches optimize prompt embedding by assigning additional parameters to the embedding and the optimal modification is directly performed over the embedding’s trainable parameters. Besides that, prompt embedding optimization suffers from finding a suitable prompt initialization. BBT overcomes this issue by treating the optimized embedding as an add-on to the original prompt embedding. Prompt Tuning has settings that initialize the prompt embedding from random or based on words selected from the LLM’s vocabulary space. Initializing prompt embedding based on the real word has little or even negative impact on the downstream task performance as the language model size increases Pre-trained Prompt Tuning (PPT) [ 10 ] . We propose a novel solution, called Diffusion-Driven Prompt Tuning (DDPT) to address the above-mentioned prompt optimization problems. Drawing inspiration from Diffusion’s capability to transform noise into high-quality outputs, our approach, DDPT, moves away from maintaining parameters for prompts. We develop a diffusion-based generator that transforms random noise into a meaningful direction vector. Whilst a LLM is kept frozen during training, an input sentence is decomposed into context and instruction components and converted to word vector embeddings. We perturb the context embedding with Gaussian noise before entering the diffusion model that performs information compression via down projection and generates a directional vector by up-projecting the embedded information to the original word embedding space and guiding the original embeddings to an optimal space through vector addition. The optimized context embedding is concatenated with the instruction embedding to create the input prompt for a frozen LLM. The diffusion model parameters are updated through gradient descent based on the LLM’s code generation loss. We evaluate our approach’s efficacy through language model outputs and quantitative metrics. To address the challenge of interpreting optimized prompt embeddings, we identify the top-k nearest words to each generated token, revealing the semantic relationships within the embeddings. The key contributions of this work are as follows: 1. We explore the use of diffusion as a prompt embedding optimizer and proposed DDPT framework as a novel solution that optimizes prompts through prompt embedding generation. 2. Our work demonstrates that a diffusion model, trained with language modeling loss, can successfully learn and generate optimal prompt embeddings. Our approach eliminates the need for embedding parameter storage and encompasses effective random initialization by directly modeling the transformation from random noise to target embeddings. 3. Our experiment’s results show that diffusion optimizer can improve the code generation result produced by LLM. The sampled result obtained from sampling indicates that the model is able to capture the distribution of optimal prompt embedding distribution. Therefore, this is a novel contribution to the diffusion-based optimization and text-domain application. The remainder of this paper is organized as follows: Section 2 introduces the background and related studies for this research, Section 3 explains our method in detail, Section 4 describes the experiment and empirical analysis result, Section 5 evaluates the threads to validity of our study, Section 6 discusses directions for future work and Section 7 concludes the study. Our code implementation can