Detecting Functional Memorization in Code Language Models
Matthieu Meeus, Anil Ramakrishna, Shengyuan Hu, Matthew Grange, Zheng Xu, Luca Melis
cs.LG, cs.CL, cs.CR
Submitted: 2026-08-20
Updated: 2026-08-24
License: http://creativecommons.org/licenses/by/4.0/
The gist: Large language models (LLMs) are increasingly used to generate code at scale.
Terminology
Abstract
Large language models (LLMs) are increasingly used to generate code at scale. Meanwhile, prior work has investigated whether training data may be recoverable from model outputs, by auditing the textual overlap between training examples and model generations. Code, however, can preserve the same logic while differing substantially in syntax and structure. We here study functional memorization: the leakage of training data logic from LLM generations in ways that textual audits fail to detect. We leverage AI coding agents to generate diverse test inputs for training data functionality and evaluate whether model-generated continuations produce the same outputs. We formalize this through a counterfactual framework, comparing target models (exposed to specific code) against reference models (not exposed) and requiring functional equivalence only for the target. We instantiate this framework across 4 open-source models and explicitly filter for functions with meaningful logic in 5 programming languages. We find that 0.3-3.4% of filtered functions are counterfactually functionally memorized, i.e., reproduced with equivalent behavior in restructured code that textual metrics fail to detect. We further show that LLM-based judges offer a scalable proxy for execution-based testing, achieving a true positive rate of 68% at 1% false positive rate, and find that functional memorization is associated with semantic duplication in the training corpus.
Sources
- SmolLM2: When Smol Goes Big -- Data-Centric Training of a Small Language Model
- Extracting alignment data in open models
- The Llama 3 Herd of Models
- HyClone: Bridging LLM Understanding and Dynamic Execution for Semantic Code Clone Detection
- How much do language models memorize?
- How Small Transformation Expose the Weakness of Semantic Similarity Measures
- Olmo 3
- CodeBLEU: a Method for Automatic Evaluation of Code Synthesis
- Code Llama: Open Foundation Models for Code
- Evaluating Harmful Memorization in LLM Code Generation
Related papers
- Polynomial-Augmented Neural Networks (PANNs) with Weak Orthogonality Constraints for Enhanced Function and PDE Approximation
- AIRL-S: Unifying Reinforcement Learning and Search-Based Test-Time Scaling via Adversarial Inverse Reinforcement Learning
- Transformers as Bayesian In-Context Experimenters: Smoothness-Adaptive Efficient ATE Estimation
- Convergence issues in Relational Concept Analysis based on AOC-posets
- Beliefs Beyond Posteriors: The Predictive Cost of ELBO Binding
- Understanding Diffusion Models via Ratio-Based Function Approximation with SignReLU Networks