Frontier parity with an on-premise 22B model

/ 3 min read / #ai #llm #fine-tuning #security #dpo

This is my rewrite of a piece I co-authored on the Symbiotic Security blog.

Summary

Regulated industries, defense and proprietary codebases often cannot send their code to a cloud API. They need a model whose weights and traffic never leave the perimeter. We asked whether a mid-sized self-hosted model could match a frontier cloud model at fixing vulnerable code, and after two stages of fine-tuning it did, reaching statistical parity on our benchmarks.

The model

The result is SecFix-V3, built on the open-weight Codestral-22B. It runs entirely on a single NVIDIA DGX Spark with 128 GB of unified memory, with no external calls during inference. A 22B model was the sweet spot: large enough to be strong, small enough to fit comfortably in unified memory and be deployed on-premise.

Fine-tuning

Training happened in two stages.

  • Supervised fine-tuning. The model learned to map vulnerable code to a correct patch with next-token prediction, using LoRA at rank 32 over three epochs.
  • Direct preference optimization. Using 4-bit QLoRA, the model learned to prefer a correct patch over a plausible but still-vulnerable one. The preference strength mattered a lot. A beta of 0.05 was optimal, while an earlier beta of 0.1 caused a clear regression.

The dataset

We built 4,811 triples, each one a vulnerable snippet, a correct patch and an incorrect patch, spanning twelve languages. The validation was strict. Near-duplicate removal cut 30 percent of the raw pairs. Syntactic validity required fewer than 5 percent error nodes. Static analysis had to confirm that the vulnerable code triggered a rule and the fix resolved it. A CWE-based stratified rebalancing kept common weakness classes from dominating.

Results

Against a frontier cloud model, with 95 percent bootstrap confidence intervals:

BenchmarkSecFix-V3Frontier cloud model
SecurityEval, Python, n=12185.1%91.7%
CyberSecEval, C and C++, n=20098.0%97.0%

The two are statistically tied on CyberSecEval, with overlapping intervals. On SecurityEval the frontier model keeps a point-estimate edge, but the gap is not statistically significant at these sample sizes. Concretely, buffer overflows dropped from 20 to 32 percent unsafe down to 3 percent, and XML injection fell from 17 percent to zero.

What actually drove the gains

The most useful finding is about where the improvement came from. Against the un-fine-tuned Codestral-22B baseline on identical items, SecFix-V3 gained 4.1 points on Python generation and 18.5 points on C and C++ remediation. A larger 24B teacher without fine-tuning scored close to the 22B base, which tells us the gain comes from the security-specific data and the preference optimization, not from model scale. Across iterations, scaling the dataset sixfold and widening it to twelve languages produced the consistent gains, while chasing optimizer settings did not. Dataset breadth beat optimizer tuning.

Honest limitations

Static analysis detection is an upper bound on real security, not a guarantee. The sample sizes leave the confidence intervals wide, so a six-point gap on one benchmark is not meaningful. We did not verify functional correctness of the patches, and some classes such as deserialization and eval injection still fail systematically.

Takeaways

Frontier-level security remediation is achievable in a self-hosted model an order of magnitude smaller than the cloud frontier. For an organization that cannot ship its code off-site, that is the difference between having a capable security assistant and having none. The lever that made it work was data quality and breadth, built and validated with the same static analysis we ship, not raw parameter count.