QLoRA on a code-repair dataset: eval loss rises after epoch 1 even with 2× more data. Early stopping, or mask the copied tokens?

I’m fine-tuning deepseek-coder-6.7b-instruct with QLoRA (4-bit NF4, r = 16, α = 32, all linear layers, dropout 0.05, LR 2e-4 cosine, warmup 3%, effective batch 16, paged_adamw_32bit, 3 epochs) for Java bug fixing. Each example is “buggy method → whole fixed method”; the loss covers only the answer tokens.

Validation loss is lowest after epoch 1 and then climbs (0.083 → 0.086 → 0.105), while training loss falls (0.081 → 0.061 → 0.034). Going from 10k to 18k training pairs gave practically the same curve. At the same time, sampling at T = 0.2 collapses: 20 samples per bug are often all identical. On held-out test-based benchmarks the epoch-3 model is mixed against the base model: better on one, worse on another.

One thing that may matter: ~85% of the answer tokens are lines copied unchanged from the input (the median example changes one line).

Questions:

1. Is this mostly overconfidence (cross-entropy punishing confident mistakes) rather than real loss of ability? Have you seen eval loss rise while task accuracy held?

2. For a study that *compares* configurations (bit-width × rank), would you use early stopping on eval loss (max 3 epochs, patience 1) or a fixed number of epochs for all?

3. Has anyone tried masking or down-weighting the unchanged lines in the loss for edit-style tasks? Did it help, or did the model lose the output format?

Welcome! :waving_hand:

1. Mostly overconfidence, probably. Your eval loss is averaged over ~85% copied tokens, so it is dominated by a handful of decision tokens where the model is confidently wrong. That also fits your identical samples at T = 0.2. CE-trained models getting sharper while pass@N drops with longer training is documented: Chen et al.. To confirm it, log eval loss separately for changed vs. copied tokens, and run a test-based pass@1/pass@k check on each epoch’s checkpoint. If changed-token loss rises while pass@k holds, it’s calibration, not lost ability. Note also that 0.083 → 0.086 is nearly flat; the real jump is epoch 3.

2. For a configuration study, use the same fixed schedule for all. Early stopping on eval loss would pick a different epoch per config and confound bit-width × rank. Pick the schedule (1 or 2 epochs, and I’d drop the LR below 2e-4) and save a checkpoint each epoch. Select and report by test-based metrics, not eval loss.

3. Yes, it helps on repair tasks. PAFT does QLoRA with token weighting that separates preserved from edited code, and reports pass@1 gains over standard SFT on Defects4J and HumanEval-Java. A SQL-repair paper (DM-SFT) randomly masks unchanged lines for the same reason. To avoid losing the output format, don’t zero out the copied lines entirely: down-weight them (e.g. 0.1-0.2) or mask a random fraction, and keep full weight on changed lines plus a few lines of context around them.

One more check that is worth doing before changing the training setup is how the train and eval splits were made. With code repair data, the same bug pattern, method, or file can appear in both splits in slightly different form, so a model can look good early and then the eval loss can behave oddly as it memorizes the training versions. Splitting by project or by the original issue, rather than by random rows, usually gives a cleaner signal.

I would also keep a small held-out set from projects that do not appear in training at all, and use it only for the test-based check mentioned above. If the model still improves there after epoch 1 while the main eval loss rises, that supports the calibration explanation. If it does not, the split may be part of the problem. Either way, writing down the split rule and the checkpoint selection rule before the next run makes the comparison between configurations much easier to trust.

Thanks both, this was really helpful. Here’s what I changed after your replies, in case someone with a similar setup finds the thread.

@RDTvlokip

1. Overconfidence. Thanks for the Chen et al. (2025) pointer, it describes exactly what I’m seeing. I now log the validation loss separately for changed-line and copied-line tokens for every epoch’s adapter. On the epoch-3 pilot adapter this confirms your point: only 18% of the validation answer tokens are on changed lines, but they carry ~94% of the loss (mean loss 0.52 per changed token vs 0.008 per copied token). So the validation loss is effectively the loss on the edit tokens. I also moved pass@10 to a separate sampling run at T = 0.8 and kept pass@1 at T = 0.2. The Codex paper notes that its fine-tuned model needs a higher temperature for k > 1, and at T = 0.2 my 20 samples were nearly identical, so pass@10 was just pass@1 again.

2. Checkpoint. I went with the epoch with the lowest validation loss for each configuration. The rule is fixed before the runs and identical for all configurations, as in most of the fine-tuning papers I follow. I also evaluate epoch 3 for every configuration, so the same-schedule comparison is reported as well. I’m not selecting on the test benchmarks, because they’re my only test sets.

3. Masking. I’m keeping the standard full-method loss for this study, since changing the objective would change what the study compares. PAFT goes into related work and future work; it’s very close to my setup (same model, HumanEval-Java). Do you have a link for the DM-SFT SQL-repair paper?

@fabbankbalnancecheck

Good point about the split. The dataset (Megadiff) has no repository field, so a project split isn’t possible. I split by file path, so different versions of the same file never end up in two splits. The test sets are separate benchmarks (HumanEval-Java and HumanEvalFix-Java), and training pairs that overlap with their methods were removed. The split rule and the checkpoint rule are both written down before the official runs.