TL;DR
This paper introduces a novel framework to distinguish between benign code reuse and harmful memorization in Large Language Models (LLMs) using a technique called "code rewriting." By evaluating models on tasks that are syntactically similar but semantically distinct from standard benchmarks, the authors reveal that while scaling up model size mitigates memorization, standard Supervised Fine-Tuning (SFT) drastically inflates it, whereas Reinforcement Learning (PPO) offers a much safer path to generalization.
What Problem Does This Paper Address?
As LLMs achieve state-of-the-art performance on coding benchmarks, a critical question persists: are these models genuinely learning to reason, or are they simply regurgitating training data?
Traditional evaluations attempt to detect memorization by measuring surface-level or structural similarity (such as token overlap or edit distance). However, the authors argue this approach is fundamentally flawed. It conflates benign reuse (the natural repetition of common coding idioms, standard APIs, or boilerplate code) with harmful memorization (where a model blindly copies a solution without understanding the underlying logic).
To solve this, the paper defines harmful memorization behaviorally: a model is harmfully memorizing if it outputs code highly similar to a known solution but fails to adapt when the task's semantics are slightly altered.
Methods
The authors propose an automated pipeline called Code Rewriting to introduce precise semantic shifts into existing benchmark problems.
Unlike standard robustness checks that preserve a prompt's meaning (like paraphrasing or adding typographical noise), code rewriting works backward:
- Logic Modification: It alters exactly one core logic or structural element in a benchmark problem's ground-truth code while keeping the function signature identical.
- Reverse-Engineering: It leverages an LLM (GPT-5) to generate a new natural language prompt that accurately describes this modified code.
- Quality Control: An LLM judge filters the generated tasks to ensure strict prompt-code alignment and difficulty equivalence.
To quantify a model's vulnerability, they introduce the Memorization Risk Index (MRI), which is calculated as the product of two signals:
- Similarity: A combined score of Abstract Syntax Tree (AST) overlap and token-level edit distance between the model's new output and the original ground-truth solution.
- Relative Accuracy Drop ($RAD_{rew}$): The performance degradation observed when moving from the original task to its rewritten counterpart.
A high MRI indicates that a model blindly copied the original surface patterns and consequently failed the new, modified task.
Datasets
The framework was evaluated using two widely adopted Python code generation benchmarks:
- MBPP+: Consisting of 378 introductory-level programming tasks.
- BIGCODEBENCH: Comprising 1,140 more complex, instruction-heavy tasks that utilize diverse library ecosystems.
For fine-tuning experiments, the datasets were split into a 4:1 train/test ratio.
Key Insights and Ideas
- Scaling cures harmful memorization, not code reuse: As models grow larger, their surface-level similarity to original solutions often remains high (they still use common idioms), but their accuracy drop on rewritten tasks vanishes. This proves that scaling enhances semantic understanding rather than just increasing rote memorization.
- Task difficulty locks in memorization: While larger models completely eliminate harmful memorization on simple tasks (MBPP+), the risk persists on complex tasks (BIGCODEBENCH), showing that harder reasoning tasks are more prone to memorization traps.
- SFT is a double-edged sword: Supervised Fine-Tuning significantly boosts a model's raw benchmark scores, but it does so by heavily incentivizing surface-level memorization, severely damaging true generalization.
- PPO acts as a regularizer against memorization: Reinforcement learning via Proximal Policy Optimization provides a much healthier trade-off, achieving competitive accuracy gains without inflating the memorization risk index.
Key Results
- Model Scaling: On MBPP+, Qwen-2.5-Instruct’s MRI dropped from 0.0722 (at 0.5B parameters) to 0.0000 (at 32B), meaning harmful memorization was entirely eliminated. However, on the more challenging BIGCODEBENCH, the decline was non-monotonic, with the 32B model retaining a significant MRI of 0.1143 due to a persistent 38.65% accuracy drop on rewritten tasks.
- Fine-Tuning Impact: Evaluating Qwen-2.5-7B on BIGCODEBENCH revealed stark differences between alignment strategies. SFT boosted original task accuracy from 31.58% to 37.72%, but more than doubled its MRI from 0.0799 to 0.1747. Conversely, PPO achieved a solid accuracy boost to 35.09% while keeping the MRI completely flat at 0.0795.
Limitations and Future Work
While the paper provides an excellent diagnostic framework for identifying memorization, it does not introduce a novel training algorithmic mitigation strategy to inherently prevent it during pre-training. Additionally, the current rewriting pipeline and MRI metrics are tailored specifically for code generation. The authors note that exploring how these semantic perturbation concepts transfer to other domains, such as mathematical reasoning, is a promising direction for future work.
Summary updated