Solution or skeleton? Distribution alignment and pattern switching in code language modelsSolution or Skeleton? Distributional Alignment and Mode Switching in Code Language Models
The authors analyze when code models write a solution or a skeleton, claim that documentation cues trigger deferred answering, and that targeted interventions outperform coarse-grained comment bans in two instruction-model settings.
- When code models are given a function signature and docstring, they may write an implementation, or they may write a placeholder opening that defers the implementation. The authors study how surrounding documentation triggers this mode switch, and its accuracy cost in benchmarks and real code completion.
- The authors manipulate neighboring functions, file headers and FIM suffixes on tasks such as HumanEval to distinguish skeleton copying from file-type cues; they then use logit lens, linear probes, activation patching, attention blocking and representation editing to localize the decision and test targeted interventions.
- The authors report that skeleton neighbors increase deferral by at least 50 pp relative to completion neighbors across 21 comparable models; exercise-style file headers increase deferral on all 23 models. In two instruction-model settings, targeted representation interventions improve pass@1 relative to coarse-grained comment bans, but not all other settings show statistically significant gains.
- The authors state that the full generation experiments cover only models of at most 14B, the mechanistic analysis covers three models; FIM measures only first-line deferral, not pass@1, and repository-level completion was not tested. Some intervention configurations come from parameter sweeps, and the gains are limited to the reported models and settings.
- Evaluated models
- Qwen2.5-Coder-1.5BQwen2.5-Coder-7BDeepSeek-Coder-1.3B-BaseQwen2.5-Coder-1.5B-ITQwen3-8B-InstructQwen2.5-Coder-7B-InstructQwen2.5-Coder-3BStarCoder2-3BStarCoder2-7BStableCode-3BGrammarCoder-1.5B-BaseSeed-Coder-8BGemma4-E2BGemma4-4BQwen3-14BQwen2.5-Coder-14BDeepSeek-Coder-6.7BCodeLlama-7B-PythonCodeGemma-2BQwen2.5-7B
- Benchmarks
- HumanEvalEvalPlus base testsMBPP+MultiPL-EBigCodeBench-hard completethe-stack-smolLiveCodeBench
- Metrics
- deferralplaceholder ratepass@1copy ratenormalised patching effectAUC
Code language models decide from context whether a function signature with a docstring and empty body should be completed as a solution or as an exercise skeleton; when the context resembles a skeleton, models output deferred placeholder openings such as pass rather than real code. Across 24 open-source models, the form of neighboring functions can determine the model's choice; when there is nothing to copy, file-level text serves as a genre cue, and changing a single word in the path raised the deferral rate on all 23 comparable models. In real GitHub files, the same cue raised the proportion of real code mistakenly written as placeholder openings from 0.5% to 7.1%. Mechanistic analysis located late comment and code decision points and distributed read-write circuits; a representation-level intervention designed accordingly outperformed coarse-grained comment suppression by 8.5 and 5.5 percentage points on two instruction-tuned HumanEval settings and avoided failures caused by suppressing useful comments. This behavior appears only under completion-style prompts and disappears under chat templates that allow free-form responses.
Related events and news
1 events · 0 news mentions
- This event's paper
研究发现代码模型按上下文补全代码或骨架
Paper analysis
What problem does this paper attempt to solve?
Studies how code models switch between implementation and skeleton based on surrounding documentation, and the accuracy cost and internal mechanisms of this switching.
The core question is: why do code language models write a “deferral opener” such as a placeholder comment or no-op when a function implementation is needed, and how does surrounding documentation determine whether they write a solution or a skeleton.
- Where it occurs: The same function signature and docstring can open either a solution file or a course exercise skeleton; editor and repository-level completion also provide surrounding file content. The authors argue that the model must judge which kind of file it is continuing.
- Gap in existing research: The paper states that prior work studies how user-provided comments, errors or formatting context change code generation, whereas this work focuses on the opening the model itself generates and the documentation cues that trigger it, and distinguishes the “solution or skeleton” decision.
- Core observation: Skeleton forms of neighboring functions are copied verbatim; when there is nothing to copy, text such as file paths and exercise-style headings acts as a type cue. The authors also hypothesize that this behavior matches the skeleton distribution of real files, but causes erroneous deferral in benchmarks or editors.
- Paper contributions: The authors measure first-line behavior on 26 checkpoints, test calibration and false triggering in real GitHub files, and analyze the mechanism with logit lens, probes, activation patching and attention blocking, further comparing lexical bans with representation-level interventions.
- Research boundary: This is a study of the model’s own completion behavior and interventions; the paper does not posit an external attacker, malicious input or victim system; interventions are performed only at decoding time, for diagnosis and targeted mitigation.
What related research exists?
Related work is divided into comment scaffolding, contextual side effects, style and copying, and localization and editing; this paper focuses on the model’s spontaneous openings and documentation cues.
Comments and plans as scaffolding
- Song et al. (2024): trained on comment-dense code, improving alignment between code and natural language.
- MANGO, self-planning and structured CoT: Chen et al. (2024) require writing logical comments first; Jiang et al. (2024), Li et al. (2025), Ma et al. (2023), and Lei et al. (2025) insert a plan before the code.
- Pan et al. (2026), Ghoshal et al. (2026): the former studies the help that comments describing the correct solution give to weaker models; the latter finds that a specific step-by-step thinking prefix acts in different directions on Coder-1.5B base and instruct. The paper notes that these works study user-provided comments, whereas this paper studies the opening the model itself emits.
When code context produces side effects
- Documentation and comment problems: Macke and Doyle (2024) study incorrect documentation degrading code comprehension; O'Brien et al. (2024) find that TODOs in prompts may be copied rather than resolved; Huang et al. (2026) study flawed commented-out code increasing completion defects.
- Prefix and format perturbations: Dinh et al. (2023) study latent bugs in code prefixes reducing completion accuracy; Wang et al. (2023b) study docstrings, naming, and format perturbations; Sclar et al. (2024) study the effect of prompt format on accuracy. The authors position this paper as isolating one specific solution/skeleton decision.
Register, genre, and context copying
- Biber (1988): studies the conditioning of word choice by register and genre in human text; on this basis the authors ask whether code models infer the genre of the source file.
- Olsson et al. (2022): studies induction heads copying previous token patterns; this paper uses the skeleton form to test distinguishing copying from substitution, and checks which heads carry the copying.
Localization, editing, and control settings
- Mechanistic tools: the paper uses logit lens, linear probes, activation patching, and residual steering, citing nostalgebraist (2020), Alain and Bengio (2016), Meng et al. (2022) et al., and Turner et al. (2024) et al., respectively.
- Baselines and benchmarks: the lexical controls are a global comment ban, a placeholder-only ban, and a deferral ban; the representation-level methods are WS-gated, probe-gated, latent steering, and document gate; experiments use HumanEval/EvalPlus, MBPP+, MultiPL-E, BigCodeBench-hard, and the-stack-smol, and audit LiveCodeBench prompts.
The authors state that the difference is in simultaneously tracking whether document cues match the real file, how they enter the network, and how to intervene in a targeted way without globally suppressing useful comments.
How does the paper address this problem?
Through controlled document perturbations, real-file comparisons and mechanistic interventions, decompose skeleton copying, genre cues and the late comment–code decision.
The overall approach is to first define and measure the deferral opener, then separately manipulate adjacent functions, file headers and FIM context, and finally use representation reading, causal patching and attention blocking to localize the decision, and design targeted edits accordingly.
Behavioral definition and experimental protocol
- Task and decoding: HumanEval has 164 problems, using EvalPlus base tests, greedy decoding and raw completion; the first-line experiment generates up to the first non-empty line, and full generation is evaluated with pass@1.
- Deferral definition: A placeholder is a first-line comment or empty comment that defers work, and a stub is a function-body form such as a no-op, ellipsis, or raising a not-implemented exception; either occurrence counts as a deferral opener. The placeholder rate counts only placeholders.
- Models and comparability: The main set is 24 open checkpoints from 13 families, with two additional checkpoints in the first-line experiment. StarCoder2-3B/7B and StableCode-3B skip the function body at the token boundary under ordinary prompts and are excluded from the corresponding counts, leaving 21 or 23 comparable models.
- Statistical comparison: Paired comparisons use the two-sided exact McNemar test; multiple paired comparisons are at the task level, reporting task-bootstrap 95% CI and sign-flip permutation test, with Holm correction across models. Values from different harnesses are compared only within the same column.
Document cues and copy discrimination
- Adjacent functions: A function with a doctest docstring is placed above the task, with the function body being completed code, one of five stub forms, or no function body; the neighbours count_vowels, merge_intervals and is_palindrome are used, and up to four neighbours are tested.
- Copying rather than replacement: Whether the target first line equals the neighbour's first function-body line is compared, as is whether another deferral form appears. If different stub forms each elicit the same form, the authors interpret this as in-context copying, rather than merely inferring the exercise genre and then choosing an arbitrary placeholder form.
- File-level genre: With no neighbour, five exercise-style, five reference-style and two neutral file headers are added; additionally, minimal pairs without verbs vary the role word in the path, the curriculum directory or the file completion status, to rule out the explanation that the model is merely following a fill-in instruction.
- Difficulty control: Capability c is measured by pass@10 (T=0.8) under a completed neighbour, and propensity q by the logit of the placeholder opener under an ordinary prompt, and the explained variance is compared with surface features such as docstring length, number of examples, number of defs and imports.
Real files, FIM and chat templates
- Real files: The Python portion of the-stack-smol, i.e. a sample of 10,000 GitHub files; the model is given the real file text preceding each documented function, comparing 1,430 functions each with and without a skeleton above, with a window of 6,000 characters.
- FIM setting: The function body is the hole, the prefix contains the cue and the HumanEval prompt, and the suffix is the following text; each model uses its own sentinel tokens, greedily generating the first non-empty line of the middle part, and an empty middle also counts as deferral.
- Chat templates: Distinguishing prefilled code as the start of the answer from the model answering freely, measuring separately whether a stub neighbour and a file header still elicit deferral.
Mechanistic localization and targeted intervention
- Late-layer decision reading: At body start, logit lens is used to observe comment and implementation token mass, and linear probes are trained at statement starts; probe AUC is about 0.99. The difference-in-means direction between comment and code states is denoted d, used for reading out and editing.
- Causal path analysis: The decoder block outputs of the solution-cue run are patched into the skeleton-cue run, with the metric being the log-odds of a canonical first-line code relative to a placeholder opening; attention is then blocked in the first or second half of the network, and neighbour copying is tested head by head.
- Representation editing: Probe-Gated Residual Editor performs hℓ ← hℓ − α dℓ when p(comment) reaches threshold τ, i.e. modifying the hidden state along the separation direction without masking vocabulary tokens; Document Gate trains a classifier on prompt-end activations and triggers editing only in skeleton contexts.
- Lexical controls: coarse ban globally masks comment tokens, and ban_placeholder only rolls back and masks placeholder comments; the paper emphasizes that ban is only a constrained-decoding restriction for diagnosis. Appendix C gives the full neighbour and file-header strings, and Appendix E gives the intervention matrix.
What experiments did the paper conduct?
The experiments cover document perturbations, real files, mechanistic localization and representation interventions; the main gains have clear setting boundaries and are not universal improvements.
Experimental setup
- Models tested: Table 5 lists 24 checkpoints: Qwen2.5-Coder-0.5B/1.5B/1.5B-IT/3B/7B, Qwen2.5-7B, Qwen3-4B/8B/8B-Instruct/14B, Qwen3.5-0.8B/4B, DeepSeek-Coder-1.3B, Seed-Coder-8B, CodeGemma-2B, Gemma3-4B, Gemma4-E2B/4B, Llama-3.1-8B, OpenCoder-1.5B, GrammarCoder-1.5B, StarCoder2-3B/7B, StableCode-3B.
- Additional models: the first-line experiments additionally include CodeLlama-7B-Python and Qwen3-30B-A3B; Appendix G additionally tests Qwen2.5-Coder-14B, DeepSeek-Coder-6.7B, and Qwen2.5-Coder-7B-Instruct, and the chat template also tests Coder-7B-IT.
- Data scale: HumanEval n=164; MBPP+ n=378; BigCodeBench-hard complete n=148; MultiPL-E Java/C++/JS n=158/161/161 respectively, counting only the first line, not executed.
- Metrics and determination: first-line deferral, placeholder rate, copy/other-form rate, and full-generation pass@1; the deferral classifier is a regular expression. Mechanistic experiments use log-odds, normalised patching effect, and probe/gating AUC.
- Classifier check: Limitations reports a stratified table of 213 distinct first lines, annotated by one human blind annotator and by Grok 4.7 and GPT-5.6, Krippendorff's α=0.97; the regex matches most labels 209/213 (98.1%) and finds 77/80 deferrals, but this is not a completion-level error rate.
- Repetition and sampling: main experiments are greedy; the sampling-robustness experiments in Appendix G use top-p 0.95 and five samples on three models, with T=0.2 and 0.8. Neighbour first-line statistics are 3×164 per model, and the patched-head analysis uses 82 held-out tasks.
Main results
The table below summarises the paper's cross-model statistics, not per-model raw scores; according to Section 4.1, Table 1, Table 2, and Section 5.
Swipe horizontally to read the table
Document condition and scope Metric Result Source stubbed vs finished neighbour, 21 comparable models deferral difference at least +50 pp for each model, median +95.7 pp Section 4.1 five stub forms, 23 comparable models median first-line copy 93.3%–98.4% Table 1 same as above median other-form deferral 0.0%–0.2% Table 1 exercise vs reference header, 23 comparable models median deferral difference +37.6 pp, positive in 23/23 and significant after correction Table 2 real function with/without skeleton above median deferral or blank 34.5% / 1.1% Section 5 real function body is code, skeleton above, 21 comparable models false deferral 0.5% rises to 7.1%, positive in 21/21 Section 5 - Neighbour effect: Figure 2 reports that one stubbed neighbour makes 20 of 24 models defer on at least 96% of tasks; under ordinary prompts Seed-Coder-8B goes from 0.0% to 98.2%, and Qwen3-14B from 5.5% to 97.6%. The effect saturates at one neighbour, tested up to four.
- Copying exceptions: the text after Table 1 states that GrammarCoder substitutes another form after an ellipsis neighbour in 57.7% of cases, Qwen2.5-7B in 11.6%, and all other models in no more than 6%; with no neighbour function body, median deferral falls back to 30.7%.
- File-header exceptions: the exercise–reference difference holds across all five paraphrase groups for 22 models, and for four groups for Qwen2.5-Coder-3B. The file-incomplete statement raises deferral on 21 models; for CodeLlama-7B-Python and DS-1.3B the direction reverses after removing the echo that restates the file header.
The cost of ordinary prompts and lexical bans
- Occurrence rate: under ordinary HumanEval prompts, 11 of 21 pre-registered artefact-free models, from 7 families, start at least 10% of function bodies with a placeholder; in Table 5, GrammarCoder-1.5B is 79.9%, Gemma4-4B 38.4%, Coder-1.5B 34.8%, and Coder-3B 10.4%.
- Coder-1.5B breakdown: the full ban raises pass@1 by 8.5 pp (18 rescues, 4 breaks), the placeholder-only ban by 7.3 pp (14/2), and other comment bans by 1.2 pp (3/1, not significant); the gain comes mainly from the 57 problems that by default start with a placeholder, on which this subset rises by 21.1 pp.
- Cross-model exceptions: the individually significant gain from the placeholder-only ban appears only for GrammarCoder (+21.3 pp, 35/0), Coder-1.5B, and Coder-1.5B-Instruct; although Gemma4-4B has 38.4% deferral, it rises by only 1.8 pp (p=0.55). The pre-registered mixed model gives p=0.001 after removing the two Coder-1.5B checkpoints, and after additionally removing GrammarCoder non-pre-registered, β=+0.08, p=0.17.
Representation-level interventions and boundaries
- Instruction-model gains: in Table 3, on HumanEval Coder-1.5B-IT with WS-gated versus comment ban is +8.5 pp (24/10, p=0.024); on Qwen3-8B-IT latent steering versus comment ban is +5.5 pp (10/1, p=0.012). The latter versus allow is +5.5 pp with only p=0.093, because the ban has 13 rescues and 13 breaks.
- BigCodeBench boundaries: on Coder-1.5B the coarse ban is −2.0 pp and probe gating is +1.4 pp; on Coder-7B they are +2.0 and +4.7 pp respectively. The direct differences in Table 3 are not significant, and the authors only use this to state that statement-level gating avoids the direction of coarse-ban damage, not to claim a general BCB advantage.
- Document gating: in Table 3, DS-1.3B under the ellipsis-neighbour setting with document-gated versus deferral ban is +7.9 pp (p<0.05), and Coder-7B under the exercise header is +10.4 pp (p<0.05); the authors state that the remaining shells show no reliable increment, and the gains are limited to the reported model–setting combinations.
Mechanisms, FIM, and prompt audit
- Late decision: Figure 5 and Section 7 state that comment-opener mass is near zero in the middle layers and rises in the last third; for Coder-1.5B layer 18 is 0.03 and implementation is 0.54, they cross at layer 20, and the comment peak is 0.77. The layers at which block patching reaches 50% of the neighbour effect are 19/18/13, and for the file header 15/17/12, corresponding to Coder-1.5B/Coder-7B/DS-1.3B respectively.
- Different pathways and distributed copying: in Figure 4a, the share of the file-header effect removed by the gap in the first half of the network is 0.78/0.87/0.77, and the neighbour in the second half is 0.92/0.55/0.83; the DS-1.3B neighbour also splits 0.39 into the first half. In Figure 4b, blocking the 16 high-attention heads removes 0.58/0.28/0.39 of the copy gap, and 16 random heads at most 0.04; the authors state that this is not a typical prefix-matching induction circuit.
- FIM and chat template: in Table 10, a stub below raises Coder-1.5B from 1.2% for none to 27.4–49.4%, Coder-3B to 97.6–98.8%, and Coder-7B to 62.8–67.1%; only the first line is measured. In Table 9, the three instruction models answering freely all have 0% deferral, and with prefilled code the stub neighbour still has an effect.
- Benchmark audit: Appendix I states that the LiveCodeBench stdin prompt itself contains a placeholder line; Coder-1.5B and DS-1.3B restate it in 67/67 allow completions. After removing that line, Coder-1.5B's allow and ban are both 35.8%, so the authors do not treat the +20.9 pp of ban on LiveCodeBench easy as evidence of this paper's effect.
Other ablations and analyses
- Difficulty control: among the three mechanistic models, capability c explains 8–15% of the variance in q, and the four surface features explain 33–47% (Section 4.4).
- Docstring style: after removing the doctest format on 76 problems, deferral rises for 15/23 models and falls for 4; Coder-1.5B is +11.8 pp and significant.
- Sampling robustness: in Appendix G, stub versus finished neighbour is +88.5 to +97.3 pp at T=0.2, and +84.5 to +92.6 pp at T=0.8.
- MBPP+ generalisation: the neighbour difference is at least 50 pp for 25/25 comparable models, and the median difference of exercise over reference is +30.8 pp.
- Intervention speed: in the A100 profile of Appendix E, probe is 45.6 tok/s, allow is 40.1 tok/s, and coarse ban is 34.5 tok/s.
- FIM head comparison: the Pearson r in Figure 6 is 0.52 and 0.56; the authors explicitly state that this analysis is correlational and cannot show that the two cues share the same circuit.
What are some points that can be further explored?
The authors list limitations including language, prompt form, model scale and statistical power; the experiments also cover only specific completion settings and model ranges.
Limitations and future directions noted by the authors
- Language and execution scope: Limitations states that only Python function completion and English text are evaluated; MultiPL-E results are first-line only and were not executed.
- Prompt form: Limitations states that the behavior is limited to completion-style prompts and disappears under free-response chat templates, and that this setting was tested on only three instruction models.
- FIM and repository completion: Limitations states that FIM tested first-line deferral on only four models and three suffix functions, with no pass@1; repository-level completion was not tested, and the real-file experiments are the closest proxy.
- Statistical power and classifier: Limitations states that per-model HumanEval tests have limited power (n=164), that after removing the two Coder-1.5B checkpoints the mixed model depends on GrammarCoder, and that the deferral classifier is a regular expression whose validation table samples different strings, not completion error rates.
- Cue and intervention selection: Limitations states that the neighbors and file headers come from a small hand-written set, and that minimal pairs, MBPP+ and real files can only reduce, not eliminate, this dependence; some steering configurations come from sweeps, and the gains support only the reported model–setting pairs.
- Mechanism and corpus sources: Limitations states that attention blocking by network half is exploratory and that the FIM header comparison is correlational; most training corpora are not public, the 10,000-file deduplicated GitHub sample underestimates near-duplicate course templates, and the source of the default tendency remains open.
Experimental coverage
- Model scale: Limitations states that the full generation experiments use models of at most 14B parameters, and that the mechanistic analysis covers three models, Coder-1.5B, DS-1.3B and Coder-7B, the largest being Coder-7B.
- Real-file sample: Section 5 uses 10,000 GitHub files from the-stack-smol and 23,617 documented functions, and takes 1,430 functions each under the with/without above-skeleton condition.
- Intervention evaluation: Table 7 covers seven models on HumanEval and BigCodeBench-hard under allow, coarse ban, WS-Gated and Probe-Gated; Table 3 separately reports the targeted comparison of latent steering and document-gated.
- Human and model annotation: Limitations reports only annotations by one human annotator and two LLMs on 213 distinct first lines, with Krippendorff’s α=0.97; agreement among multiple human annotators is not reported.
- Benchmark audit boundary: Limitations and Appendix I state that LiveCodeBench prompts themselves embed placeholders, so their ban gains are not treated as evidence for the effect studied in this paper.
Summarize the main content of the paper
The paper interprets placeholder openings as documentation-driven mode switching and characterizes them with behavioral, real-file and mechanistic experiments and targeted interventions.
This is a behavioral and mechanistic study of completion-mode switching in code language models: when facing the same function task, the model chooses, based on the surrounding document, to either implement the code or generate a placeholder opening that defers implementation.
- Problem: The authors argue that curriculum skeletons and solution files share similar function openings, so the model infers the genre from adjacent functions and file-level text; this inference may be appropriate in real files, but in benchmarks or editors it can cause avoidable failures.
- Method: The study systematically varies neighbor function bodies, file headers, paths and FIM suffixes, using the first-line form to distinguish copying from replacement; it then combines logit lens, linear probes, activation patching, attention blocking and representation editing to localize the comment–code decision.
- Document effects: A stubbed neighbour relative to a finished neighbour increases deferral by at least 50 pp for 21 comparable models, with a median difference of +95.7 pp; in Table 1, the median first-line copying rate for five stub forms is 93.3%–98.4%.
- Genre and false triggering: In Table 2, the median difference in deferral for exercise relative to reference header is +37.6 pp, positive for 23/23 models. When a skeleton is present above a real code function, false deferral rises from 0.5% to 7.1%, positive for all 21 comparable models.
- Mechanistic conclusions: The authors report that the decision forms in later layers of the network; the file-header effect relies mainly on the first half of attention, and the neighbour effect mainly on the second half. Neighbour copying is carried by distributed reader heads and a few writer heads, rather than a typical induction circuit.
- Interventions and boundaries: In the targeted settings for Coder-1.5B-IT and Qwen3-8B-IT, representation intervention improves pass@1 by 8.5 and 5.5 pp respectively relative to comment ban; the direct difference on BigCodeBench is not significant. The authors therefore argue for editing by context and statement position rather than globally suppressing comments, while explicitly limiting the gains to the reported model–setting combinations.