跪拜 Guibai
← Back to the summary

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

We always assume the large model is a black box, but if the engineering pipeline surrounding it is also a black box, then this becomes pure metaphysics. These 4 days I used countless extreme controlled variables and finally became certain: the model's interior can be a black box, but the experiment's exterior must be absolutely white box.

Let me first describe a scenario.

There is a defect Lang-33 in Defects4J: when traversing an object array, the code directly calls array[i].getClass(), but the array may contain null.

The test clearly tells the model: there is a null in the input, and the expected output keeps null at the corresponding position. The reference fix only needs to add a null check before the call.

This is a one-line change, and there is no need to understand the entire repository.

But 0.6B did not fix it, and 4B did not fix it either.

What truly made me stop and reflect was not that both models failed, but another question:

I have been trying to teach the model to fix bugs through fine-tuning, but I have never systematically verified whether it actually possesses the basic Java capabilities required to support repair work.

This article is not a success tutorial, nor is it a verdict that "0.6B cannot learn Java."

It records: starting from a realistic repair target, I propose hypotheses, design validations, negate hypotheses, and push the problem further. In the end, I did not obtain a 0.6B model that can fix Java, but I did gain a set of experimental methods that can be reused in the future.

1. Starting Point: First Define What "Repair Success" Means

I6's initial goal was clear: Java defect localization and minimal repair.

I chose Defects4J as the first training and validation ground. It provides real Java projects' buggy/fixed versions, and, more importantly, provides trigger tests: the same test fails on the buggy version and passes on the fixed version.

This means whether the model is correct does not need to be judged by another model based on text style; it can be directly answered by the compiler and the test:

Localization correct
→ Patch applies
→ Project compiles
→ Trigger test changes from fail to pass
→ Related regression tests remain passing

To control variables, the first version evaluation fixed the same prompt, greedy generation, single generation without retry.

Failures were also categorized: empty output, invalid format, patch not applicable, compilation failure, trigger test failure, rather than all written as "the model didn't fix it."

Looking back now, this is the most important step in the entire experiment. Because many seemingly contradictory results later ultimately come back to the same question:

Which step exactly did not pass?

2. First Illusion: Being Able to Write a Complete Method Does Not Mean Being Able to Fix a Bug

The initial training approach was to let the model read the buggy method and trigger test, then output the fixed complete method.

Single-sample experiments quickly revealed the first "memory and migration separation."

The fine-tuned model could learn the repair of Lang-5 and pass Defects4J's real compilation and trigger test; but applying the same fine-tuned model to Lang-3, precision limitations were still not patched, and the test continued to fail.

This already shows:

Training samples learned
≠
Unseen samples will also be repaired

Full-method training also exposed another issue.

Lang-16's reference fix is actually only one line: allow the hexadecimal prefix check to support both uppercase 0X and -0X.

But the full fixed method has 6079 characters and 1212 supervised tokens. Most of the model's training capacity is spent copying the originally correct method body, and the truly needed one-line modification is diluted by a large amount of copy loss.

So the problem may not be "too little data," but possibly: the output contract puts the supervision signal in the wrong place.

So I changed the output to a structured local edit:

{
  "action": "replace",
  "target_method": "createNumber",
  "old_text": "exact original text to be modified",
  "new_text": "minimal repair code to replace the original text"
}

The model only proposes the modification, and the evaluator checks whether the original text is uniquely matched, performs one replacement, then compiles and runs the test. The supervised target dropped from 1212 tokens to about 80 tokens.

This adjustment again proved: the fine-tuned model can memorize training samples and generate correct replacements, but repair on unseen defects still did not occur.

Learning the structured format, memorizing training samples, and repairing unseen defects are three different conclusions.

3. Applicable Patches Went from 0/4 to 4/4, Why Still 0/4 Repairs?

Next, I did comparative experiments with sample size, training epochs, and LoRA rank.

After increasing sample size and training steps, training metrics improved somewhat, but the number of trigger tests passing on the same validation set remained 0/4.

When increasing rank from 8 to 16, training set fitting became stronger, validation set repairs remained zero, and there was stronger overfitting.

Finally, on the unseen Time project, there was a result easily misread:

Metric Original model Fine-tuned model
Applicable patches 0/4 4/4
Compilation 0/4 1/4
Trigger tests 0/4 0/4

If only the first row is reported, it seems that fine-tuning brought clear success.

But the full result only shows that the fine-tuned model better adheres to structured output requirements on unseen projects and accurately quotes original text. It does not prove that the repair content is correct.

At the end of the first day, I had to accept:

Loss declining, more regular output, patch applicability, none equal to the formation of true repair capability.

4. Day 2: Given the Location, Changed Prompts, Tried 4B, Still No Answer

At the start of day 2, I planned to continue with candidate location selection, but soon discovered a more fundamental issue:

Were previous failures because the model did not understand the repair, or because the model was blocked by the new output protocol?

So I first took out the "localization" variable and directly provided the correct original text to be replaced.

Under the protocol of only outputting Java replacement snippets, the model frequently returned complete methods or even complete classes. Stuffing these declarations into a small position in the original method usually produces nested methods or nested classes, and compilation naturally fails.

Strengthening the prompt and adding toy examples actually made the problem more obvious: the model started copying examples, copying prompt labels, or continuing to output unrepaired full methods.

Finally, I switched to a more compatible full-method protocol, still giving the correct location, and letting the model output the entire repaired method. Most candidates maintained method structure and compiled, but trigger tests still all failed.

At this point, the conclusion only became slightly clearer:

Even given the correct location and using a compatible output protocol, the repair content and defect understanding themselves are clearly the bottleneck.

At this time, several natural hypotheses followed.

Is 0.6B too small?

I sent the same batch of failed cases to the official Qwen3-4B original weights, keeping the same prompt, numerical precision, greedy generation, and single evaluation.

Result: 4B on all four problems returned the buggy method verbatim, without attempting modification.

It compiled because the copied method compiles; but trigger tests still failed. Increasing model size did not bring repair benefits under the current task description.

Is the prompt inducing copying?

The original prompt placed the original text to be replaced verbatim at the end of the input, possibly making the model think it need only reproduce the full method. So I changed the verbatim text to line numbers.

The output behavior on three problems did change; the model began to modify methods, but none passed the trigger tests.

This only shows the prompt affects behavior, not that it is the root cause.

Is there a lack of real behavioral evidence?

For Math-2, I actually invoked the target method in the buggy workspace, got a negative mean, then independently calculated the positive expected value according to the distribution definition, and provided these two actual numbers to the model.

4B still copied the buggy method verbatim.

Does enabling thinking solve it?

With thinking enabled, the model repeatedly guesses, negates itself, until it exhausts the output budget, without forming a candidate method.

It even wrote a multiplication that would exceed Integer.MAX_VALUE, but did not connect that to integer overflow.

These rounds of experiments did not give me the success I wanted, but they prevented me from continuing to treat "larger model, different prompt, more information, enabling reasoning" as universal answers without verification.

5. Lang-33: The Truly Ignored Prequel Assumption

Next, I filtered Lang-33, which is closer to a minimal repair target.

The buggy method directly executes while traversing an object array:

classes[i] = array[i].getClass();

The test explicitly includes a null element, expecting it to be mapped to null. The reference fix only needs:

classes[i] = array[i] == null ? null : array[i].getClass();

Neither the original model nor the fine-tuned model produced a compilable correct patch under the structured edit protocol.

Switching to the full-method protocol, both 0.6B and 4B could generate legal methods and compile, but both retained the original direct call without adding the null check.

At this point it was already the second night. After consecutive failures, I truly realized a previously ignored problem:

I assumed that "large models have read Java code, so they should already know Java," but this assumption was never systematically verified.

The model being able to repeat methods, preserve signatures, generate legal JSON, or even produce compilable code does not prove it understands types, boundaries, null, integer division, and basic logical semantics.

So the problem needs to be moved forward:

Not first ask whether the model can fix real defects
But first ask whether the model even knows the most basic Java

6. Back to Basic Concepts: Train More, Give More, Make It Bigger

On day 3, I first gave the original 0.6B a set of clearly specified short methods: add two numbers, return larger value, sum array, count evens, handle null strings, perform double division.

Each problem required strict method structure validation, then javac and independent assertions. The reference implementations first passed the same pipeline, to avoid attributing evaluator failures to the model.

The basic instruction version eventually only passed 2/6. Continuing to strengthen completeness requirements, pre-setting assistant opening, changing to plain text continuation or minimal natural language, none improved pass rates; some approaches made output more divergent.

Along the way, we also found an evaluator issue: the structural check read the model candidate, but the compilation and assertion stages wrote the reference implementation. After fixing, the previously seemingly better results were revoked.

This interlude again reminded me:

Whether an evaluation result is trustworthy first depends on what the evaluator is actually testing.

Concept and code reading tests also exposed similar issues:

But the model is not entirely ignorant of Java. Adding two numbers, returning the larger of two numbers, some String.equals and overload answers were correct.

A more accurate state is: knowledge points are scattered and surface-level, unable to stably support precise execution.

So I began trying to supplement basic concepts with LoRA + supervised fine-tuning.

Training data covered static, final, integer division, == / equals. Initially 100 items had 92 used for training; later, because static errors were concentrated, I added 30 more, making 122 training items.

The next three hypotheses were almost the most natural reactions.

Hypothesis 1: Is it not enough training epochs?

After 4 epochs there was partial concept improvement. Increasing to 8 epochs did not surpass the former as a whole; some problems improved, others regressed. Continuing to 16 or 32 epochs lacked basis.

Hypothesis 2: Is it not enough static samples?

After adding 30 static scenarios, the problem still did not stably improve. The model would even first say "static fields are shared by all instances," then immediately compute the output that should be 2 2 2 as 0 0 0.

Hypothesis 3: Is the learning rate too small?

I raised the learning rate from 1e-5 to 1e-4, keeping other conditions unchanged.

Looking only at training metrics, it seemed effective:

Metric lr = 1e-5 lr = 1e-4
final train loss 1.880346 1.150991
final full validation loss 2.064561 1.843811
optimization steps 488 488

But generation on both the original training problems and independent problems showed multiple degradations.

So the question became:

Both train loss and validation loss are declining, why is the target behavior getting worse?

Continuing to tune parameters cannot explain this contradiction; I needed to first examine the experimental environment itself.

7. I Started Doing "Environment Validation" on the Training Pipeline

1. Training and Evaluation Prompts Were Not Aligned

Rechecking scripts, I found that during training I used:

system = Java teacher requirement
user   = original problem

The old evaluation, however, wrapped the teacher requirement and [problem] together into the user, with different role assignment and text wrapping.

To exclude this variable, I added an SFT prompt mode and performed token prefix validation on all 122 training samples.

In the end, all 122 passed, confirming that training and evaluation are consistent item by item in input contract, not just "the text looks roughly the same."

2. Training Was FP32, Old Generation Was BF16

Training used PyTorch's default FP32, but old generation explicitly used BF16. Runtime verification confirmed that the trained model and saved fine-tuned parameters were both FP32.

Therefore there was no need to retrain for precision alignment; I directly let the fine-tuned model generate in FP32.

FP32 indeed changed some outputs; some problems improved, some showed new contradictions, but core errors did not disappear.

Precision affects generation trajectories but is not the explanation for all failures.

3. Forced Overfitting with 8 Samples

To verify whether the training, saving, loading, and generation chain could accomplish the most basic learning, I selected 8 static training originals, deliberately strengthened optimization, and only looked at whether the model could memorize them.

Training samples: 8
epochs: 64
optimization steps: 512
learning rate: 1e-4
initial train loss: 3.149048
final train loss: 0.000205

Then I had the fine-tuned model retest the same 8 problems, and the result was 8/8 verbatim identical to the reference answers.

This proves that on the current conceptual task, the entire pipeline has clear learning and reproduction capability. It cannot prove generalization, but it can exclude wrong directions such as "training completely ineffective," "fine-tuned parameters not loaded successfully," and "the generation chain cannot reproduce training results."

This reminds me of environment verification when troubleshooting Java production issues: first confirm source code, dependencies, configuration, network, and target environment, then discuss complex business logic.

Model training is the same:

The large model is a black box, but the engineering pipeline around it must be as white box as possible.

8. Between Loss and Free Generation, What Else?

Next, I measured the loss of the high learning-rate model on these 8 training answers.

I used "teacher forcing": at each step, the correct prefix is provided to the model, rather than letting the model consume its own generated prefix.

As a result, the loss on all 8 samples further decreased, averaging from 1.729874 down to 0.851884.

This rules out the explanation that "the average loss decrease is because these 8 samples were sacrificed by other samples."

But it still cannot prove the model can answer autonomously.

When computing loss, even if the model originally wanted to write "wrong" at the beginning, the subsequent computation still feeds it the correct "correct. ...". The model can learn to follow a correct conclusion with plausible text; during free generation, once it first writes "wrong," it may continue along the wrong conclusion to explain.

Long answers with lots of generic wording can also make the model more and more like the reference answer without guaranteeing that key contents like "can/cannot," 1 1/2 2, true/false are correct.

So:

The reference answer appearing under teacher forcing is not equivalent to the model being able to independently give the correct answer during free generation.

To rule out engineering differences between full-sequence training and incremental decoding, I also compared generation results with and without key-value cache (KV cache).

Under the same model, prompt, FP32, and greedy settings, the 8 problems had verbatim identical outputs, and KV cache was also excluded as a major cause.

As for "whether long explanations dilute the supervision of key conclusions," this remains only a hypothesis at this point. The conclusion needs to be separated from the explanation and validated independently.

9. Red Team Intervention: Test Questions and Test Roles Can Also Deceive

While preparing the short-answer experiment, I invited another model to do a red team review.

It first pointed out that one original question, L0-HOLDOUT-01, had a current() method that itself couldn't compile, yet the question also asked for main output. The reference answer's output values could only be measured after removing or fixing the illegal method.

This shows that short answers cannot simply be the first sentence of long answers. Each question should be rewritten into a single, executable question; compilation labels are determined by javac, and output labels by actual execution.

The red team also pointed out that the original 20 "independent validation questions" were marked as eval_holdout in the file, but I had repeatedly used their results to choose training directions, adjust prompts, adjust precision, and design the next experiments.

They fit better as a development regression set, and can no longer pretend to be a final validation set that never participated in design decisions.

This made me realize:

Whether a test set is independent depends not only on the role in the file, but also on whether it later participated in design decisions.

At the same time, I also began to shrink the goal.

The Java specification is a small piece of knowledge for humans, but for a 0.6B model, the combination space of programs and their behaviors is enormous. If I first require myself to "complete the entire Java" before fixing bugs, this branch might never close.

So I finally verified only one rule:

Static methods cannot directly access instance fields, but can access them through explicit object references.

10. Pairwise Validation: Single Question 50%, Whole Pair 0%

I constructed pairs of code. Each pair has the same class, method signature, and other code, with only the access form changed, for example:

class Wallet {
    int balance;

    static int peek(Wallet w) {
        return balance;
    }
}

and:

class Wallet {
    int balance;

    static int peek(Wallet w) {
        return w.balance;
    }
}

The first is illegal, the second is legal, and labels are determined by actual javac compilation.

The original 0.6B answered legal for all 8 code snippets. The old fine-tuned model answered illegal for both versions of the first pair, and legal for both versions of the other three pairs.

Counting per question, both models happened to answer 4/8 correctly, looking like 50% accuracy; counting per pair, they both scored 0/4.

This proves the necessity of pairwise acceptance:

If legal and illegal versions always get the same answer, single-question guessing cannot be considered mastering the rule.

Free short answers and candidate-answer scoring gave the same results, indicating that the issue is not just the output protocol; the model truly does not use the difference in field access form to distinguish code behavior.

Subsequently, I re-froze 4 final question pairs and one Thermostat single-line repair question. The final set only runs javac to validate labels, not the model, and all 10/10 checks passed.

11. The Last Short-Label Training: No Transfer and No Repair Occurred

The final training used only 4 development pairs, a total of 8 short-label samples, 4 illegal and 4 legal each.

The model started from the original 0.6B, without stacking previous fine-tuning results, to avoid mixing two training goals.

The actual execution configuration was:

Training samples: 8 short labels
epochs: 16
optimization steps: 128
learning rate: 1e-4
Training and generation: FP32

Before training, there was discussion about changing the learning rate to 3e-5, but the actual command still executed 1e-4, and the record kept the true value.

The final training loss changed from 0.933424 to 0.989837, not decreasing.

Using the fine-tuned model to evaluate the frozen 4 final pairs, all 8 unseen code snippets were answered legal:

generation_correct_pairs: 0/4
score_correct_pairs: 0/4
generation_same_answer_pairs: 4/4
score_same_answer_pairs: 4/4

Short-label training did not make the model learn this rule on unseen code.

Finally, the Thermostat single-line repair. The model needed to output a replace JSON, and after the repair, it had to pass javac and runtime assertions to confirm Thermostat.read(t) returns the degrees of the passed object.

The model actually only output:

int degrees;

So it did not generate a patch that conforms to the contract and could be compiled and evaluated; it cannot be written as "patch compilation failed."

At this point, the pre-agreed stopping condition was met: short-label training neither transferred to the final pair questions nor completed a miniature repair under the same rule.

I no longer continued increasing epochs, learning rate, rank, data volume, or new Java topics.

12. What Stops Is the Route, Not a Death Sentence for the Model

The conclusion we can currently draw is only:

Under the current data scale, training objective, LoRA configuration, and experimental budget, I have not taught a 0.6B model to form transferable Java rule capability. Continuing to scale up along the existing route lacks evidential support.

This does not prove that 0.6B can never learn Java, nor that its base capability has been fully adjudicated.

What I truly investigated is:

These results are enough to support stopping the current route, but they are not enough to attribute all failures to model capacity.

Data coverage, curriculum design, training methods, and other optimization strategies may still have different answers; it's just that continuing to explore them no longer fits the current project's closing goal.

13. What I Truly Learned in These 4 Days

From a technical goal perspective, this fine-tuning was not successful. But an experiment does not have only one kind of outcome, "model training success."

First, the layers of the problem became clearer:

Output structure legal
Original text uniquely matchable
Patch applicable
Code compiles
Trigger test passes
Unseen samples transfer

These outcomes correspond to different capabilities, and no layer can replace the next.

Second, training metrics and behavioral capability were completely separated:

Loss decline ≠ target capability formation
Memorizing answers ≠ transferring rules
Judging rules ≠ fixing defects
Passing tests ≠ semantic correctness

Third, I got a more reliable troubleshooting order:

Check data and input contract first
→ Check device, precision, and generation method
→ Check if optimization changes target probabilities
→ Check storage and loading of fine-tuned results
→ Use minimal overfitting to verify memorization loop
→ Use unseen problems to verify transfer
→ Use compilation and behavior to verify repair

If the lower layer is not verified, do not rush to add variables at a higher layer.

Fourth, I re-understood the value of red team.

Red team is not adding another voter; it introduces an examiner specifically challenging premises. Whether data is executable, whether the test set is still independent, whether metrics measure the target behavior, these are often more worth checking first than "try another parameter."

Red team judgments are still hypotheses to be verified, and ultimately must be adjudicated by the compiler, tests, and real reports.

Finally, my own way of participating also changed.

Previously, when seeing code from AI, I more easily copied and executed directly; now I first check input, output, paths, configuration, and side effects, and also actively question experimental order and conclusion boundaries.

These 4 days did not give me a 0.6B model that can fix Java, but they made me truly start participating in experimental design: propose hypotheses, question directions, check code, invite red team, and finally decide to stop.

14. Follow-up: 4B Can Continue, but Don't Forget These Evidences Just by Switching Models

4B is not the first time in this experiment.

On day 2 it already participated in full-method, Math-2 behavioral evidence, thinking, and Lang-33 control, and did not bring a real repair pass.

If 4B is used again later, it is for recalibration on the new static pair rule task, not "the first time trying a larger model."

Subsequent controls should still use the same pair questions, short prompts, candidate scoring, javac, and miniature repairs, and record implementation, precision, memory, and time. Otherwise, the last observed differences may not come from parameter count.

For later reference, one can also look at Nan Jiang et al.'s ICSE 2023 paper Impact of Code Language Models on Automated Program Repair (arXiv:2302.05020).

This paper evaluates 10 code models on 4 benchmarks with 442 Java single-hunk defects, and several conclusions align well with this experiment's methodology:

But the paper uses about 129,300 APR training instances and checks Top-10 candidates per defect, which is not the same experimental caliber as my small-sample LoRA and single greedy repair; one cannot directly compare repair rates.

This conclusion is not because "the experiment failed, so we stop," but because continuing along the original path already lacks new evidential support.

What truly should be carried to the next stage is not greater expectations, but this verified set of experimental methods.

The model's interior can be a black box, but data, input, numbers, optimization, artifacts, and evaluation should be made white box layer by layer. First ensure the foundation is good, then discuss the upper layers; first let every step have evidence, then let conclusions move forward.