Skip to content

CGMIA: detecting data leakage in code generation benchmarks with membership inference attacksKeep Evaluation Fair: Detecting Data Leakage in Code Generation Benchmarks via Membership Inference Attacks

arXiv: Adversarial Attacks, Backdoors & Poisoning· arXiv:2609.09865· Dongdong Zhao, Jian Chen, Guancheng Lin, Jianwen Xiang, Jacky Wai Keung, Xiao Yu·Indexed by this site · 2026-10-01· Originally publishedAttacks

Quick read

Attacks

Based on the paper PDF (AI-generated); refer to the original

CGMIA uses shadow models and expert+semantic features to detect code generation benchmark leakage, achieving average Precision of 0.82–0.92 across four models.

Threat modelscore-access black-box: the attacker cannot access the target LLM's architecture, parameters, gradients, or training data, and can only query to obtain generated code and token-level log-probabilities, used to determine whether benchmark samples belong to its training set.

Questions
Public code generation benchmarks may enter LLM training sets, inflating evaluation scores; commercial models do not release training data, so direct corpus comparison is impossible. The authors state that among existing methods, only DetectLeak targets full-program generation benchmarks, with accuracy around 40–50%.
Methods
CGMIA fine-tunes shadow models under score-access black-box, labeling fine-tuned samples as member and held-out samples as non-member, extracts CodeBLEU, edit distance, perplexity, test pass rate, and CodeBERT embeddings, and after alignment feeds them into a classifier to determine whether benchmark samples are in the target training set.
Experiments and results
When target and shadow are the same model, CGMIA achieves average Precision of 0.89, 0.89, 0.92, 0.82 across four target models and eight benchmarks. Relative to each model's strongest baseline, average Precision improves by 0.05–0.16. On StarCoder-7B, it identifies over 65% of the 108 known leaked APPS samples.
Limitations and future work
In Section 6, the authors discuss internal, external, and construct validity threats, including simulated leakage, shadow models not perfectly matching the target, and the relatively small size of the benchmarks. The experiments cover four open-source small models and eight benchmarks, and known-leakage detection was performed on StarCoder-7B/APPS; repeated five times with the median taken.
Experimental setupQwen2.5-Coder (3B)、CodeGemma (2B) et al. · HumanEval-X (Python)、HumanEval-X (Java) et al. · Precision、Recall et al.
Evaluated models
Qwen2.5-Coder (3B)CodeGemma (2B)DeepSeek-Coder (1.3B)Phi-2 (2.7B)StarCoder-7B
Benchmarks
HumanEval-X (Python)HumanEval-X (Java)MBXP-PythonMBXP-JavaNaturalCodeBench-PythonNaturalCodeBench-JavaEvoCodeBenchClassEvalAPPS
Metrics
PrecisionRecallMCCAUCpass@1
AI summaryTo address the problem of inflated evaluation caused by data leakage in code generation benchmarks, the researchers propose CGMIA (Code-Generation-specific Membership Inference Attack), which constructs member and non-member labeled data by fine-tuning shadow models on a subset of benchmark samples, and fuses expert features such as CodeBLEU, edit distance, test pass rate, and perplexity with CodeBERT embedding semantic features for ensemble learning, to determine whether samples have entered the target model's training set. Across eight code generation benchmarks, CGMIA outperforms eight existing membership inference methods in most cases, and effectively detects known leaked APPS samples in StarCoder-7B's training data.

To address the problem of inflated evaluation caused by data leakage in code generation benchmarks, the researchers propose CGMIA (Code-Generation-specific Membership Inference Attack), which constructs member and non-member labeled data by fine-tuning shadow models on a subset of benchmark samples, and fuses expert features such as CodeBLEU, edit distance, test pass rate, and perplexity with CodeBERT embedding semantic features for ensemble learning, to determine whether samples have entered the target model's training set. Across eight code generation benchmarks, CGMIA outperforms eight existing membership inference methods in most cases, and effectively detects known leaked APPS samples in StarCoder-7B's training data.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Public code generation benchmarks may leak into training sets; CGMIA performs membership inference under black-box access to detect leakage.

    How to determine, without access to the training corpus, whether code generation benchmark samples have entered the target LLM's training set, so that evaluation is not inflated by memorization.

    • Scenario and importance: The authors state that LLMs are often pretrained on large-scale corpora containing code such as GitHub, and public benchmarks may be unintentionally included; Zhou et al. found that 108 samples from APPS appear in StarCoder-7B's pretraining data, with pass@1 being 4.9 times that of unconfirmed samples. The authors also note that developers may deliberately mix in benchmarks to inflate leaderboard results, and commercial models do not disclose training data, making direct corpus comparison infeasible.
    • Shortcomings of existing methods: The authors state that, to their knowledge, DetectLeak is currently the only method specifically designed to detect code generation benchmark leakage, relying only on perplexity, performing poorly on complex or rare samples, with detection accuracy around 40–50%, even below random guessing. Gotcha, CodeMI, TraWiC, and Buzzer target local completion or masked prediction in copyright protection and do not fully exploit functional correctness.
    • Core observation: The authors hypothesize that leaked and memorized samples have generated code closer to the reference solution and higher test pass rates; perplexity, edit distance, BLEU, and Pass@k can all serve as memorization signals.
    • Proposed in this paper: Proposes CGMIA (Code-Generation-specific Membership Inference Attack), which uses shadow models to construct member/non-member labels and fuses expert features with CodeBERT semantic features to train a membership inference classifier. The authors state that, to their knowledge, this is the first application of MIA to data leakage detection in code generation benchmarks.
    • Threat model:
      • Target: Determine whether benchmark sample (x, y) belongs to target model M's training set D_train.
      • Knowledge: Architecture, parameters, gradients, and training data are all inaccessible; the authors call this query-based, score-access black-box.
      • Capability: Given code generation prompt x, one can obtain generated result ŷ=M(x) and token-level log-probabilities, used to compute perplexity.
      • Victim system: The code generation LLM being evaluated; its training data may unintentionally or intentionally contain samples from benchmark D_bench.
  2. What related research exists?

    Related work is organized into classifier-based code-domain MIA, metric-based MIA, and the functional correctness that is overlooked in benchmark leakage.

    Section 2 of the paper organizes code-domain membership inference into classifier-based and metric-based types, and points out their gap with full-program generation benchmarks.

    • Classifier-based code MIA (copyright protection)
      • Gotcha (Yang et al.): Fine-tunes shadow models on a known subset of the target training data for code completion, and uses CodeBERT to encode (input code, completion code, reference) to train a neural classifier.
      • CodeMI: Uses multiple shadow models, converts outputs into ranked probability vectors, and trains a neural membership classifier, also for code completion.
      • TraWiC: Masks identifiers and then performs exact matching and fuzzy matching, training a random forest on the match rates. The authors state that these three works target local completion or masked prediction and are not fully applicable to full-program benchmarks.
    • Metric-based MIA
      • General literature: Min-k% Prob Attack uses output confidence; Loss Attack uses cross-entropy loss to determine membership.
      • Buzzer: Perturbs inputs such as by changing case, and compares changes in [CLS] embeddings, assuming members are more sensitive. The authors state that LLMs are relatively robust to slight perturbations, so this method has limited discriminative ability.
      • DetectLeak (Zhou et al., 2025): The authors state it is the only method specifically designed to detect leakage in code generation benchmarks, using the perplexity of generated code, where low perplexity is considered more likely to be memorized; but perplexity mainly reflects familiarity with common patterns, performs poorly on complex or rare samples, with accuracy around 40–50%, and improper threshold selection can cause high false positives or false negatives.
    • Functional correctness signal: The authors state that the above works often ignore the test cases that come with the benchmark; Zhou et al. observed that leaked samples have abnormally high pass rates.
    • Baselines and benchmarks: Experimental baselines are DetectLeak, Gotcha, CodeMI, plus LR and RF trained on four expert features (with SVM, NB, DT, MLP in the appendix), and CNN, LSTM, Transformer that learn semantics only from generated code and reference solutions. TraWiC and Buzzer are excluded because of task incompatibility. Benchmarks are HumanEval-X (Python/Java), MBXP (Python/Java), NaturalCodeBench (Python/Java), EvoCodeBench, ClassEval; known-leakage validation uses the APPS samples reported by Zhou et al. and StarCoder-7B.

    The authors position this paper as MIA for full-program code generation benchmarks: using correctness, similarity to reference solutions, perplexity, and semantic features simultaneously, rather than only completion or only a single metric.

  3. How does the paper address this problem?

    Shadow models construct labels, and a membership classifier is trained by fusing four expert features with CodeBERT embeddings.

    CGMIA first uses a controllable shadow model to mimic the target model's behavior on member and non-member data, then fuses expert features with semantic features to train classifier F.

    Problem Setting and Formalization

    • Judgment target: Given prompt x, reference solution y, and generated code ŷ=M(x), the classifier outputs whether the sample is in D_train. The formula is F(x, y, ŷ)=1 if and only if (x,y)∈ Dtrain, otherwise 0.
    • Access assumption: score-access black-box. The authors cite that OpenAI, Google Vertex AI, as well as vLLM, TensorRT-LLM, and llama.cpp can expose token-level log-probabilities.
    • Two stages: first train the classifier on a shadow model, then query the target model and predict.

    Shadow Model and Label Construction

    • Positive and negative samples: randomly sample p items from D_bench to fine-tune shadow model S, denoted as member; the remaining q items are non-member. To avoid imbalance, set p=q. Query S to obtain (x, y, ŷ) triples.
    • Attack stage: use target model M to generate ŷ for benchmark samples, and feed the triples into the trained F.
    • Simulated leakage split: the experiment randomly divides D_bench equally into four mutually exclusive parts. The target model is fine-tuned on D_bench1, with D_bench1 as member and D_bench2 as non-member; the shadow model is fine-tuned on D_bench3, with D_bench3/D_bench4 as the classifier's positive and negative samples, respectively. The shadow and target member/non-member sets do not overlap, to maintain black-box access to the target.

    Feature Extraction

    • Expert features (20 dimensions per sample): each prompt uses nucleus sampling (top-p=0.95, temperature=0.8) to sample 5 outputs, and each output computes four features. CodeBLEU measures semantic and syntactic similarity to the reference solution; edit distance is the normalized token-level minimum number of edits to turn ŷ into y; perplexity is computed from token-level log-probabilities, with lower values indicating more predictable generation; test pass rate is a binary value, 1 if all tests pass, otherwise 0.
    • Semantic features: use frozen CodeBERT to encode the 5 generated outputs and the reference solution. When exceeding the length limit, split into chunks with a sliding window of at most 510 code tokens and stride 256, take [CLS] and average the chunk representations to obtain a 768-dimensional sequence embedding, for a total of 6 vectors.

    Fusion and Classifier

    • Alignment: the five generated code embeddings are compressed to 768 dimensions via a one-dimensional CNN; the 20-dimensional expert features are first standardized, then linearly projected to 2048 dimensions. Concatenated with the reference solution's 768 dimensions, a 3584-dimensional vector is obtained. The CNN and expert feature projection are frozen after initialization and are not updated with member labels; the authors state this borrows fixed feature transformations to reduce trainable parameters and overfitting risk.
    • Classifier: a three-layer feedforward network, 3584→1024→512→2, trained with cross-entropy after softmax. Optimizer Adam, learning rate 1e-4, batch size 100, 50 epochs.
    • Fine-tuning settings: both target and shadow use LoRA, rank 8, α=32, dropout 0.04, applied to attention Q/K/V and FFN linear layers; AdamW, learning rate 2e-5, 20 epochs, batch size 2, maximum sequence length 2048.
    • Cross-benchmark training: because some benchmarks have limited data, one classifier is trained on a merged training set from eight benchmarks, then predicted separately on each benchmark; repeated five times, taking the median. Deep learning baselines set aside 40% of the training set as a validation set.

    Success Determination

    • Metrics: Precision, Recall, MCC (−1 to 1, 0 equivalent to random), AUC. In the main experiments, the evaluation set has 50% member; DetectLeak labels the half with the lowest perplexity as member.
    • Significance: with each benchmark as one paired observation, perform a Wilcoxon signed-rank test on the eight benchmarks, BH correction, α=0.05, and use Cliff's δ to classify effect size.
  4. What experiments did the paper conduct?

    With same-model shadows, CGMIA achieves average Precision 0.82–0.92 and detects over 65% of known leaked APPS samples.

    Experimental setup

    • Models under test: Qwen2.5-Coder (3B), CodeGemma (2B), DeepSeek-Coder (1.3B), Phi-2 (2.7B), used both as targets and shadows. The authors state these models were deduplicated against HumanEval, MBPP, etc. at release. StarCoder-7B is additionally used for the known-leak experiment.
    • Benchmarks and scale: HumanEval-X Python/Java, 164 each; MBXP-Python 974, MBXP-Java 966; NaturalCodeBench Python/Java, 70 each; EvoCodeBench 275; ClassEval 100 (Table 2). Languages are Python and Java. Known leaks are the 108 APPS samples reported by Zhou et al.
    • Baselines: Gotcha, DetectLeak, CodeMI, RF, LR, CNN, LSTM, Transformer; the appendix additionally reports SVM, NB, DT, MLP. TraWiC and Buzzer are excluded as incompatible with code generation.
    • Metrics and tests: Precision, Recall, MCC, AUC. Wilcoxon signed-rank + BH, α=0.05, Cliff's δ. Each benchmark is first scored on all test samples, then compared across the eight benchmarks.
    • Protocol: Four mutually exclusive subsets simulate leakage; in the main experiment (RQ1) target and shadow are the same LLM, with member proportion 50%. Due to limited data, one classifier is trained on the combined eight benchmarks and then predicted per benchmark; repeated five times, taking the median. Generation uses top-p=0.95, temperature=0.8, 5 samples per prompt.
    • pass@1 before and after fine-tuning: In Table 2, the four models are ordered Qwen2.5-Coder, CodeGemma, DeepSeek-Coder, Phi-2. For example, HumanEval-X(Python) before fine-tuning is 48.7/20.7/59.7/30.5, and after fine-tuning 60.4/32.9/68.2/48.8. Pre-fine-tuning pass@1 across the eight benchmarks ranges from 0% to 59.7% (CodeGemma is 0 on EvoCodeBench).

    Main results

    In RQ1, target and shadow are the same model. The table below shows average Precision / Recall / MCC / AUC across the eight benchmarks (AVG rows of Tables 3–6 and Section 5.1).

    Swipe horizontally to read the table

    Target=ShadowPrecisionRecallMCCAUC
    Qwen2.5-Coder0.890.890.750.95
    CodeGemma0.890.850.810.94
    DeepSeek-Coder0.920.830.730.95
    Phi-20.820.840.630.89
    • Average absolute gain over the strongest baseline: Precision gains are 0.07, 0.05, 0.11, 0.16; Recall 0.11, 0.08, 0.06, 0.11; MCC 0.17, 0.26, 0.18, 0.21; AUC 0.10, 0.09, 0.09, 0.13 (same order: Qwen2.5-Coder, CodeGemma, DeepSeek-Coder, Phi-2). The authors state that RF and CNN are second-best among baselines in Precision, MCC, and AUC; LSTM and CNN are second-best in Recall.
    • Relative to DetectLeak: Under the favorable setting of known member proportion, averaged over the eight benchmarks, CGMIA still exceeds it by Precision 0.12–0.23, Recall 0.21–0.64, MCC 0.23–0.36, AUC 0.18–0.58. The authors state the classifier does not require manually setting thresholds by prevalence.
    • Significance: Of 128 groups (8 baselines × 4 models × 4 metrics), 99 have BH-corrected p<0.05, and 29 (23%) have p≥0.05. The authors state reference solutions are 152–1347 tokens long, and RQ1 performance shows no clear correlation with length. In Table 3 there are cells where CGMIA is not first; for example, on Qwen2.5-Coder's HumanEval-X(Python), DetectLeak Precision is 1.00 and CGMIA is 0.90; on NaturalCodeBench-Python, DetectLeak Precision is 0.00.

    Feature combinations (RQ2)

    • What was tested: Beyond semantic features, all 16 combinations of CodeBLEU, edit distance, perplexity, and test pass rate (including no expert features) are enumerated.
    • Results: The paper's main text discusses combination levels in Section 5.2; because intermediate tables have incomplete column alignment in the text conversion, cell-level numbers that cannot be aligned to specific combinations are not transcribed here. The authors aim to answer how the four expert features affect CGMIA.
    • Authors' interpretation: The authors group combinations into five tiers by the number of expert features used, to compare surface memorization signals against using only semantic features.

    Shadow model mismatch and real leakage

    • Shadow mismatch (RQ3): The authors state they will switch to shadow models of different architectures to analyze the effect of architecture differences on CGMIA. Specific cell-level results are misaligned in the converted text and are not filled in here.
    • Known leakage (Contribution 3 and abstract): On StarCoder-7B, CGMIA identifies over 65% of the 108 known leaked APPS samples reported by Zhou et al. This is a setting where the target model is not one of the four fine-tuned models in the experiment, and leakage comes from an existing report rather than this simulation's split.
    • Class imbalance: The contributions state that class imbalance was also analyzed; the main protocol given in the text is p=q, with members comprising 50% of the evaluation set.

    Other ablations and analyses

    • Appendix traditional classifiers: Table 13 gives AUC for SVM, NB, DT, MLP. For example, average AUC across eight benchmarks on Qwen2.5-Coder: SVM 0.66, NB 0.53, DT 0.54, MLP 0.57; on CodeGemma, SVM average AUC is 0.50. These are lower than CGMIA's 0.89–0.95 in Table 6 of the main text.
    • DetectLeak threshold: When member proportion is known, the lowest-perplexity 50% are labeled member; the authors argue this proportion is usually unknown in real deployment.
    • Fine-tuning improves performance: Table 2 shows that after fine-tuning, pass@1 is higher than before for all four models on all eight benchmarks (CodeGemma on EvoCodeBench goes from 0 to 2.9).
    • W/D/L: On Precision in Table 3, Phi-2 against the eight baselines is mostly 7/0/1 or 8/0/0; Qwen2.5-Coder against DetectLeak is 4/0/4, p=0.95.
    • Statistical exceptions: The authors explicitly state that Precision comparisons against DetectLeak and LSTM on Qwen2.5-Coder, CodeGemma, and DeepSeek-Coder, as well as several Transformer and RF cases, do not all reach significance.
    • Implementation details: Classifier 50 epochs, learning rate 1e-4; LoRA fine-tuning 20 epochs, learning rate 2e-5. Deep learning baselines use the same epochs and learning rate as CGMIA, with 40% of the training set as validation.
  5. What are some points that can be further explored?

    Section 6 discusses equivalent-threat settings such as simulated leakage and shadow mismatch; experiments are repeated five times and the median is taken.

    Limitations and future directions noted by the authors

    • Section 6 is titled threats to validity; the paper discusses limitations under internal, external, and construct validity rather than as a separate Future Work list. The organization description states that Section 6 discusses potential validity threats and Section 7 is the conclusion. A large portion of the converted text is missing after Section 5.2, and the item-by-item original sentences of Section 6 could not be fully read, so the experimental discussion is not rewritten as the authors' limitation list.
    • Validation difficulty already stated in Section 4.1: For models with closed-source or not fully public training sets, even if CGMIA infers leakage, it cannot be verified because there is no ground truth for the training data; the authors state this weakens the assessment of effectiveness in real scenarios, so the experiments use simulated leakage.
    • Planned or unfinished items by the authors: The paper does not state in the read portions that code release is completed; no explicit future work items could be verified sentence by sentence.
    • Any other limitation statements appearing only in the missing main text are not supplemented here.

    Experimental coverage

    • Models: Main experiments use Qwen2.5-Coder (3B), CodeGemma (2B), DeepSeek-Coder (1.3B), and Phi-2 (2.7B) as both targets and shadows, four in total; additionally, 108 known leaked APPS samples are detected on StarCoder-7B (abstract and Section 1.2).
    • Benchmarks: Eight benchmarks, with sizes in Table 2 (70–974 tasks), in Python and Java; tasks range from algorithm problems to class-level and repository-level. APPS is used for known-leakage validation.
    • Baselines: Eight main baselines (DetectLeak, Gotcha, CodeMI, LR, RF, CNN, LSTM, Transformer); appendix Table 13 additionally has AUC for SVM, NB, DT, MLP. TraWiC and Buzzer are stated by the authors to be excluded due to task incompatibility (Section 4.4).
    • Protocol: Each benchmark is randomly split into four mutually exclusive subsets; in RQ1 the target and shadow are the same model, and the evaluation set is 50% member; one classifier is trained on the merged eight benchmarks and then predicts per benchmark; repeated five times with the median taken (Section 4.1). The paper reports Wilcoxon + BH and Cliff's δ.
    • Not reported in the paper: The read main text does not give the exact number of detected samples in the StarCoder-7B experiment (only states over 65%), nor does the abstract give query counts or runtime. The 16 feature combinations in RQ2 and the cross-architecture shadow results in RQ3 could not be verified cell by cell because of column misalignment in the converted text.
  6. Summarize the main content of the paper

    CGMIA fuses similarity, pass rate, perplexity, and CodeBERT, outperforming eight MIA baselines on simulated leakage.

    CGMIA uses membership inference to detect whether code generation benchmarks have leaked into LLM training sets, making evaluation independent of direct access to training corpora.

    • Problem: Public benchmarks may enter crawled corpora or be deliberately mixed in. Zhou et al. found 108 APPS samples in StarCoder-7B pretraining data, with pass@1 4.9 times that of unconfirmed samples. The authors state that DetectLeak only looks at perplexity, with accuracy around 40–50%, and is the only method they know of aimed at full-program benchmarks.
    • Method: Under score-access black-box, a subset of the benchmark is used to fine-tune a shadow model as member, with a held-out portion as non-member. Each prompt is sampled 5 times; CodeBLEU, edit distance, perplexity, and test pass rate are extracted and fused with the [CLS] embedding of a frozen CodeBERT via alignment, then a three-layer classifier is trained. The main experiment splits the benchmark into four equal parts so that the shadow and target member sets do not overlap.
    • Main results: When target and shadow are both Qwen2.5-Coder, CodeGemma, DeepSeek-Coder, or Phi-2, average Precision across eight benchmarks is 0.89, 0.89, 0.92, 0.82, and average AUC is 0.95, 0.94, 0.95, 0.89. Relative to each model's strongest baseline, average Precision improves by 0.05–0.16 and MCC by 0.17–0.26. Of 128 comparisons, 99 have corrected p<0.05. Not every benchmark exceeds all baselines; for example, in several cells DetectLeak has higher Precision or CGMIA is 0.
    • External verification: The authors report that CGMIA identifies over 65% of the 108 known leaked APPS samples in StarCoder-7B training data. In Table 2, pass@1 after fine-tuning is higher than before for all four models.
    • Authors' conclusion: The authors argue that CGMIA outperforms other MIAs in the vast majority of cases, and the classifier does not require manually setting thresholds by member prevalence, making it more suitable for leak detection in real evaluations where member proportions are unknown.
Read originalarxiv.org