Papers
Topics
Authors
Recent
Search
2000 character limit reached

EG-CFG: Execution-Guided Code Generation

Updated 23 January 2026
  • Execution-Guided Classifier-Free Guidance is a paradigm that integrates runtime execution feedback with LLM inference, enabling iterative correction of code errors.
  • It employs a multi-stage pipeline including candidate sampling, execution signal extraction, and classifier-free guidance to enhance task success rates.
  • Empirical benchmarks on MBPP and HumanEval demonstrate significant improvements in accuracy and efficiency compared to conventional decoding methods.

Execution-Guided Classifier-Free Guidance (EG-CFG) is a neural code generation paradigm that infuses real-time runtime execution signals into LLM inference. Unlike standard token generation pipelines that rely exclusively on learned syntax and pattern recognition, EG-CFG tightly incorporates line-by-line execution feedback, emulating the iterative, error-correcting workflow of expert programmers. The framework consists of a multi-stage pipeline that synthesizes candidate code completions, extracts granular runtime information through active code execution, and re-injects this feedback into the generation process via classifier-free guidance mechanisms. This approach achieves substantial gains in task success rates and supports native parallelism, enabling broad exploration of solution space and efficient computation (Lavon et al., 12 Jun 2025).

1. Formalization and Motivation

A code generation task in EG-CFG is structured as a prompt pinst=(p0,ptask,T,fname)p_\mathrm{inst} = (p_0,\, p_\mathrm{task},\, T,\, f_\mathrm{name}) where p0p_0 defines the instruction template, ptaskp_\mathrm{task} specifies the problem, T={t1,,tT}T=\{t_1,\dots,t_{|T|}\} denotes test cases for correctness, and fnamef_\mathrm{name} is the target function name. The principal objective is to autoregressively emit a token sequence w=[w0,w1,,wN1]w^* = [w_0^*, w_1^*, \dots, w_{N-1}^*] such that, when assembled as a Python program, every test tjTt_j \in T passes: tjT:Execute(w,tj)=success.\forall\,t_j \in T:\quad \mathrm{Execute}(w^*, t_j) = \text{success}. Traditional LLM decoding strategies (greedy, temperature, top-pp) postpone runtime validation until after program completion. This design epoch fundamentally restricts models’ ability to repair semantic and logical faults at intermediate steps. EG-CFG bridges this gap by actively injecting execution traces at each token or line, guiding generative progress toward executable, correct solutions.

2. EG-CFG Multistage Pipeline

EG-CFG proceeds in three tightly interleaved stages for each line of code:

  • Stage 1: Line-by-Line Beam Candidate Sampling The model, configured with temperature tt, emits p0p_00 candidate continuations of p0p_01 new lines via beam search:

p0p_02

Each p0p_03 is a raw code segment.

  • Stage 2: Execution Signal Extraction Each candidate p0p_04 is parsed into executable form p0p_05 (e.g., via AST modification or truncation to ensure syntactic validity). Duplicates are removed:

p0p_06

For every p0p_07 and test case p0p_08, the code fragment is executed:

p0p_09

yielding traces such as variable states, outputs, or error signals.

  • Stage 3: Classifier-Free Guidance with Dynamic Execution Signals The execution feedback is encoded as a guidance prompt ptaskp_\mathrm{task}0, then spliced into the current solution at index ptaskp_\mathrm{task}1. CFG merges the unconditional prior ptaskp_\mathrm{task}2 and conditional distribution ptaskp_\mathrm{task}3, amplifying tokens favored by successful partial executions.

3. Mathematical Characterization of CFG with Execution Signals

Execution feedback is integrated mathematically via a weighted convex combination. For each token position ptaskp_\mathrm{task}4: ptaskp_\mathrm{task}5 where ptaskp_\mathrm{task}6 determines the strength of execution-guided conditioning. When ptaskp_\mathrm{task}7, decoding reduces to the unconditional prior, while large ptaskp_\mathrm{task}8 values shift generation toward code fragments empirically validated against test cases. Token selection either follows

ptaskp_\mathrm{task}9

or stochastic sampling, per design.

4. Signal Propagation and Refreshing

Execution signals are computed only once per line and reused for all tokens within that line, providing coherent local guidance. At line boundaries, the signals are refreshed. The core pseudocode is as follows: fnamef_\mathrm{name}0 The persistent use of p_signal within a line ensures the invariance of execution feedback across token positions, while systematic recomputation at line starts admits timely correction.

5. Native Parallelism: Multiple Independent Agents

EG-CFG inherently supports parallel exploration across diverse agent configurations: hyperparameters such as beam size T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}0, horizon T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}1, temperature T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}2, classifier-free guidance strength T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}3, and instruction template T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}4 can be systematically enumerated. Each T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}5 tuple constitutes a fully-independent agent, which processes the coding task in isolation. The parallel execution model allows for early termination upon solution discovery (first agent to pass all tests), unlike iterative multi-agent systems that exhibit sequential dependencies.

6. Empirical Performance and Benchmarking

On MBPP (500 tasks) with DeepSeek-V3-0324, standard prompting yields 82.8% accuracy; EG-CFG elevates task success to 96.6%, a state-of-the-art result. For MBPP-ET, performance rises from 64.8% to 73.0%. On HumanEval (164 tasks), EG-CFG increases accuracy from 82.9% to 96.95%; HumanEval-ET from 79.2% to 87.2%. On CodeContests, EG-CFG achieves 58.18% compared to 41.81%—an absolute improvement of 16.4 points. These results markedly surpass previous self-debugging and multi-agent methods, even when restricted to a single open-source model.

7. Computational Complexity and Overhead

EG-CFG imposes additional computational requirements relative to conventional decoding:

  • Beam search for T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}6 candidate completions per line
  • AST parsing and duplicate filtering
  • T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}7 executions per line
  • Two forward LLM passes per token (unconditional, conditional distributions)

With typical settings (T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}8, T={t1,,tT}T=\{t_1,\dots,t_{|T|}\}9), execution counts remain tractable, and per-token double LLM evaluations double inference time. MBPP mean per-task runtime under full parallel scheduling is approximately 271 s (DeepSeek-V3-0324), modestly lower than MapCoder (283 s) and substantially faster than MGDebugger (842 s). Early termination further reduces wall-clock time.

In conclusion, EG-CFG integrates semantic runtime feedback with generative token modeling, producing executable code in an efficient, guided fashion. The combination of linewise sampling, AST-based execution tracing, and classifier-free conditional weighting forms a robust architecture for high-fidelity neural code synthesis (Lavon et al., 12 Jun 2025).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Execution-Guided Classifier-Free Guidance (EG-CFG).