A tuned model that was not better, and the test that showed it
Hyperparameter tuning produced a model that scored higher on validation. A paired test on the same messages showed the gap was within noise, so I did not promote it.
4 min read
- MLOps
- Model evaluation
- Canary rollout
- Katib
I tuned a text classifier with Katib, retrained the winning settings on all the data, and got a higher validation score than my current model. Then I tested the two against each other properly, and the evidence for "better" disappeared. This post covers what I did, and why the first comparison I ran could not have told me.
The classifier is part of my support-ticket triage platform. It sorts banking messages into 77 intents, and a model reaches users only after passing quality gates and a canary rollout.
The tuning run
Katib ran 8 trials of random search on a fine-tuned MiniLM-L6, varying learning rate (log scale, 3e-5 to 2e-4), epochs (3 to 8) and batch size (16 or 32). Training a 22M-parameter model on CPU is slow, so each trial used 2,000 of the 9,002 training rows. The objective was validation macro-F1.
One result was clear. Learning rate dominated: every trial at 1.3e-4 or higher beat every trial below 7e-5. The other two parameters could not be separated, because eight random trials cannot isolate three parameters.
The full-data check
Scores from 2,000 rows are far below a full-data run, so the winner needed retraining on everything. With a learning rate of 1.5e-4, 7 epochs and batch size 32, validation macro-F1 was 0.9172. My previous defaults had scored 0.9125.
That looks like an improvement. But I had two earlier runs of the same default settings, and they differed from each other by 0.0014 on validation and 0.0044 on test. Validation has only 1,001 rows, and each setting had run once. The +0.0033 to +0.0047 gap was about the size of the noise between identical runs.
Why the canary could not answer it
The obvious next step was to export the model to INT8 ONNX, register it as v7, and send it 10% of traffic next to the champion, v3. I did, and the router comparison on 1,000 test messages looked bad for the new model: 0.923 accuracy for v3 against 0.900 for v7.
It meant almost nothing. v7 saw only 100 requests, so its confidence interval was wide. Worse, the two versions were scored on different slices of the traffic. A gap of a few thousandths between two models is invisible when each one is judged on different, small samples.
The paired test
A paired test fixes both problems. compare_paired.py sends the same messages to both deployed versions, then compares answer by answer. It reports macro-F1 for each, a bootstrap interval on the difference, and McNemar's exact test on the messages where only one model was right.
| Set | v3 macro-F1 | v7 macro-F1 | Difference (95% interval) | Only v3 right / only v7 right | McNemar p |
|---|---|---|---|---|---|
| Validation (1,001, used to decide) | 0.9074 | 0.9162 | +0.0088 [-0.0041, +0.0254] | 18 / 23 | 0.53 |
| Test (3,080, reported only) | 0.9185 | 0.9181 | -0.0004 [-0.0066, +0.0067] | 55 / 54 | 1.00 |
The served models reproduced their offline scores exactly, so the comparison measured the real deployments and not a test harness.
On validation, v7 won 23 disagreements and v3 won 18. With that split, a p-value of 0.53 is what chance produces. On the test set the models were the same to three decimal places.
What I decided
I did not promote v7. Three things pushed me there:
- No evidence of a difference. Both intervals include zero, and neither p-value comes close to significance.
- Selection bias. The search chose its settings by scoring on the validation set, so some of the +0.0088 there is probably the search finding a lucky setting.
- The gates would have passed it. At default thresholds, all five promotion gates passed, so the pipeline's own promote step would have moved
@championautomatically. I registered v7 as@challengeronly, by raising the minimum gain over the champion to 0.05, then rolled the canary back.
The honest summary of the Katib work is that it found a setting as good as my old default, not a better one. That is still worth knowing, and it is cheaper than shipping a change that I could not distinguish from noise.
What I take from it
- A promotion gate is a floor, not a verdict. "At least as good as the champion" lets a coin-flip through. If a candidate should have to show it is better, the threshold has to say so.
- A canary shows behaviour, not quality. It is the right tool for errors, latency and "does it start". It is the wrong tool for deciding between two close models, because the traffic slices differ and the sample is small.
- Compare on the same inputs. Pairing the messages removes the biggest source of noise, and the exact test then uses only the disagreements, which are the only messages that carry information.
- Run the baseline twice. The most useful number in this exercise was the 0.0014 gap between two runs of identical settings. Without it, +0.0033 would have looked like a result.
The paired test stopped me from promoting a model on a difference I could not measure.