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

TRACED: Execution-aware Pre-training for Source Code

Yangruibo Ding, Benjamin Steenhoek, Kexin Pei, Gail Kaiser, Wei Le, Baishakhi Ray · OpenReview

TL;DR

This paper introduces TRACED, a novel pre-training strategy for source code models that incorporates program execution traces. By learning from both static code and dynamic execution behavior, TRACED significantly improves performance on tasks like predicting execution paths, runtime variable values, semantic clone retrieval, and vulnerability detection, outperforming existing statically trained models.

What Problem Does This Paper Address?

Modern machine learning models for source code primarily rely on static analysis of code text, often augmented with structural information like abstract syntax trees. However, many crucial software engineering tasks, such as detecting semantic clones or identifying vulnerabilities, require understanding a program's dynamic behavior – how it executes, what values variables take, and which code paths are taken. Statically trained models struggle with these dynamic aspects because the true semantics of a program often only manifest during execution. This gap limits their effectiveness in real-world applications where understanding program behavior is paramount.

Methods

TRACED proposes an "execution-aware" pre-training strategy that goes beyond static code analysis. The core idea is to train models using not just source code, but also executable inputs and their corresponding execution traces. This multi-modal approach involves three key stages:

  1. Tracing & Feature Engineering: Programs are executed with given inputs to generate traces. These traces capture runtime variable values and code coverage (which lines are executed). To manage the complexity and sparsity of raw execution data, variable values are "quantized" into a predefined set of categories. This creates "program state labels" and "execution coverage labels" to be used as ground truth.
  2. Execution-aware Pre-training: A Transformer-based model (initialized with UnixCoder weights) is trained with three objectives:
  3. Learning Code Text: Standard masked language modeling (MLM) on the source code.
  4. Learning Program States: Predicting the quantized values of variables at different points in execution.
  5. Learning Execution Coverage: Predicting which code branches are executed. This multi-task learning forces the model to learn both static code properties and dynamic execution behaviors simultaneously.

  6. Task-specific Fine-tuning: The pre-trained TRACED model is then fine-tuned on downstream tasks without requiring further execution traces. The model leverages its learned execution awareness to perform tasks like static execution estimation, clone retrieval, and vulnerability detection.

Datasets

  • Pre-training Dataset: Built using C language solutions from the IBM CodeNet dataset, specifically from 1,805 programming challenges. An additional 95 challenges were held out for evaluation to prevent data leakage. The dataset comprises 121,319 training traces.
  • Downstream Tasks Datasets:
    • Static Execution Estimation: Evaluated on held-out CodeNet challenges (95 challenges).
  • Semantic Clone Retrieval: Uses the CodeXGLUE-POJ104 dataset, which contains 104 programming challenges with multiple C/C++ solutions.
  • Vulnerability Detection: Utilizes three publicly available datasets: REVEAL (RV), D2A, and CodeXGLUE-Devign (CXG).

Key Insights and Ideas

  • Execution is Key: The paper strongly argues that static analysis alone is insufficient for many code understanding tasks, and incorporating dynamic execution information is crucial for capturing true program semantics.
  • Quantization for Tractability: Directly learning concrete runtime variable values is problematic due to sparsity and high dimensionality. Quantizing these values into meaningful categories significantly improves the model's ability to learn general execution patterns without overfitting to specific values.
  • Multi-task Learning Synergy: Combining MLM, program state prediction, and execution coverage prediction during pre-training creates a more robust and "execution-aware" model than any single objective alone. The different objectives complement each other to build a comprehensive understanding.
  • Static Estimation of Dynamic Behavior: TRACED's core innovation is enabling models to statically estimate dynamic properties (like execution paths and variable values) after being trained on execution traces. This is vital for applications where runtime execution is not feasible or desired.

Key Results

  • Static Execution Estimation: TRACED improves UnixCoder's performance by 12.4% for full execution path prediction and 25.2% for runtime variable value prediction.
  • Semantic Clone Retrieval: TRACED achieves 91.2% MAP@R on the CodeXGLUE-POJ104 benchmark, outperforming strong baselines like UnixCoder (89.5%).
  • Vulnerability Detection: TRACED achieves 50.4% F1 on REVEAL, 62.1% accuracy on D2A, and 65.9% accuracy on CodeXGLUE-Devign, generally outperforming other models.
  • Ablation Studies: Removing any of the three pre-training objectives (MLM, state prediction, coverage prediction) significantly degrades performance, highlighting the importance of the multi-task approach.
  • Quantization Effectiveness: TRACED's quantized values perform better than using concrete values or other abstraction strategies, demonstrating their effectiveness in reducing data sparsity while retaining discriminative power.

Limitations and Future Work

  • Language Support: Currently, TRACED is limited to the C programming language due to the capabilities of the tracing tools used. Extending TRACED to other languages would require developing or adapting tracers for those languages.
  • Input Validity: The current approach assumes valid and executable inputs that do not terminate or throw errors. This might limit the model's ability to capture program termination or error-handling behaviors.
  • Variable Coverage: The quantization scheme does not cover all possible variables, especially complex data structures, due to their inherent complexity.
  • Future Work: The authors suggest extending TRACED to support more programming languages and exploring its application to a wider range of software engineering tasks. They also note the potential for further improvements by incorporating more sophisticated tracing and feature engineering techniques.

Summary updated

BibTeX
@misc{ding2023traced,
  author = {Yangruibo Ding and Benjamin Steenhoek and Kexin Pei and Gail Kaiser and Wei Le and Baishakhi Ray},
  title = {{TRACED: Execution-aware Pre-training for Source Code}},
  year = {2023},
  eprint = {2306.07487},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.07487},
}
Figure