跪拜 Guibai
← All articles
AI

A 0.6B Model Can Memorize Answers but Can't Fix a One-Line Java Bug: A 4-Day Fine-Tuning Autopsy

By 吕炘嵘 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

This experiment shows that fine-tuning a small model for code repair is pointless if the base model lacks fundamental language semantics; the gap between training loss and behavioral capability is wide, and developers need rigorous verification pipelines—not just more data or bigger models—to avoid false confidence.

Summary

For four days, a developer systematically fine-tuned a 0.6B model on Java defect repair tasks, only to conclude that the model could memorize exact training examples but never generalize a single meaningful rule. The target was Lang-33 in Defects4J, a one-line fix adding a null check; both the 0.6B and a 4B model failed to produce a correct patch, even when given the exact location and a compatible output format.

The developer progressively isolated variables: output protocol, prompt phrasing, model size, reasoning mode, and even precision (FP32 vs BF16). None moved the needle. Training loss dropped, validation loss dropped, and patches became more applicable, yet trigger tests never passed. The model also failed basic concept checks: it thought `1 / 2` is `0.5`, confused `==` with `equals`, and didn't know that static methods can't access instance fields directly.

The breakthrough came from treating the experiment itself as a system to validate: aligning training and evaluation prompts, forcing overfitting on 8 samples to prove the pipeline worked, and using pairwise code (legal vs illegal) to reveal that the model consistently judged both versions as legal, exposing a total lack of rule understanding. The dev's methodical approach, including red-team review and a strict compile-and-test evaluation chain, offers a reusable template for anyone probing small-model capabilities.

Takeaways
— Fine-tuning a 0.6B model on Java repair tasks did not produce any correct fix on unseen defects, even for a one-line null-check change.
— The 4B Qwen3 model also failed, repeatedly copying the buggy method verbatim instead of fixing it.
— Training loss and validation loss can both drop while behavioral accuracy remains zero, as shown by learning-rate comparisons.
— A model can memorize 8 training samples perfectly (8/8 verbatim) after 64 epochs, yet completely fail to generalize to similar unseen code.
— Pairwise validation (legal vs illegal code) revealed the model judged all 8 snippets as legal, scoring 4/8 by single question but 0/4 by pairs, proving it had no rule understanding.
— Aligning training and evaluation prompts (including role assignment and text wrapping) and using FP32 for both disappeared several confounds, but did not fix the core issue.
— The developer halted the experiment because the pre-defined stopping condition was met: short-label training neither transferred nor enabled a minimal repair, and continuing lacked evidence.
— A reference to the ICSE 2023 paper (arXiv:2302.05020) shows that test-based evaluation, not BLEU, is necessary for assessing code repair models, and that more data isn't always better.
— The entire experiment was run with a controlled variable approach: same prompt, greedy generation, single attempt, and categorized failure types.
— The final conclusion is that the model did not acquire transferable Java rule capability, but this does not prove it can never learn Java; only that this particular route is exhausted.
— Red-team review of test questions invalidated some validation items, highlighting the need to ensure test sets remain independent and executable.
— The experiment resulted in a reusable troubleshooting order for small-model fine-tuning: data contract, device/precision, optimization, save/load, minimal overfit, transfer, then compile and behavior.
— The developer now checks inputs, outputs, paths, and side effects before running AI-generated code, a habit formed from debugging the experiment pipeline itself.
Conclusions

The experiment exposes a fundamental flaw in many fine-tuning workflows: the objective function (loss) is disconnected from the behavior you actually care about. A model can memorize patterns and still have zero understanding of the underlying rules.

The rigorous use of controlled variables and environment verification (e.g., FP32 vs BF16, prompt alignment, forced overfitting) demonstrates that many "model inabilities" might actually be pipeline artifacts; until the pipeline is white-boxed, you can't trust the results.

The pairwise validation technique is a powerful diagnostic: if a model gives the same answer to legal and illegal code, it hasn't learned the rule, regardless of single-question accuracy.

The 4B model's verbatim copying of the buggy method suggests that larger models may be more prone to mimicking input patterns when the task is ambiguous, rather than reasoning from the code's semantics.

The developer's decision to stop is a valuable example of scientific discipline: knowing when to halt a research direction because the evidence for progress is exhausted, even if the goal isn't achieved.

The use of a red-team review to invalidate test questions shows that test set independence is not a static property; a set that was previously held out can become tainted if it influences design decisions.

Concepts & terms
Defects4J
A collection of real Java defects with buggy and fixed versions and trigger tests, used to evaluate automated program repair. A test that fails on the buggy version and passes on the fixed version provides an objective correctness signal.
LoRA (Low-Rank Adaptation)
A parameter-efficient fine-tuning technique that updates a small number of low-rank matrices instead of all model weights. The experiment varied the rank (8 vs 16) to test its effect on overfitting and generalization.
Teacher forcing
In sequence generation, feeding the ground-truth prefix as input at each step during training. This can lower loss without guaranteeing that the model can independently generate correct sequences from scratch.
KV cache (key-value cache)
A technique to speed up autoregressive generation by caching key-value pairs from previous attention steps. The experiment compared generation with and without it to rule out an engineering difference in decoding.
Red team review
An adversarial review process where a separate party (here, another model) challenges assumptions, finds flaws in test data, and questions whether the evaluation truly measures intended behavior.
Single-hunk defect
A bug that can be fixed with a single contiguous patch (hunk) in a source file. The cited ICSE 2023 paper evaluates on 442 such Java defects, making it a focused benchmark for repair models.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗