anicka commited on
Commit
22e2b5b
·
verified ·
1 Parent(s): 4b854c4

v4 model card: 93% recall, test generation, Gemini comparison

Browse files
Files changed (1) hide show
  1. README.md +103 -59
README.md CHANGED
@@ -5,6 +5,7 @@ tags:
5
  - security
6
  - patch-backporting
7
  - code-generation
 
8
  - qwen2
9
  - qlora
10
  - opensuse
@@ -15,70 +16,73 @@ language:
15
  pipeline_tag: text-generation
16
  ---
17
 
18
- # CVE Backport Code Generation — Qwen2.5-Coder-32B
19
 
20
- Fine-tuned [Qwen2.5-Coder-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct) for security patch backporting via per-hunk code generation.
21
 
22
- Instead of generating unified diffs directly, this model takes a vulnerable code region and a fix description, and outputs the **fixed version of the code**. A programmatic diff then produces the final patch. This plays to LLM strengths in code completion and avoids format-sensitivity issues.
23
 
24
  ## Quick Start
25
 
26
- The easiest way to use this model is with the **[cve-backport-tool](https://github.com/openSUSE/cve-backport-tool)** CLI, which handles the full pipeline: parse upstream patch, extract per-hunk regions, call the model, and reconstruct a unified diff.
27
-
28
  ```bash
29
- # Download and serve the model
30
- ./setup.sh
 
31
 
32
- # Generate a backport patch
33
  python3 cve-backport.py \
34
- --cve CVE-2025-3887 \
35
- --package gstreamer-plugins-bad \
36
- --patch upstream.patch \
37
- --obs-fetch --backend openai --retry 3
 
38
  ```
39
 
40
  ## GGUF Downloads
41
 
42
- | File | Quant | Size | Dataset | Notes |
43
- |------|-------|------|---------|-------|
44
- | `cve-backport-codegen-v3-q8_0.gguf` | Q8_0 | 33 GB | 35,667 examples | **Recommended** highest precision |
45
- | `cve-backport-codegen-v2-q8_0.gguf` | Q8_0 | 33 GB | 24,452 examples | Previous release |
46
- | `cve-backport-codegen-v1-q8_0.gguf` | Q8_0 | 33 GB | 17,007 examples | First release |
47
-
48
- Older GGUFs (v1, v2) are available in the [legacy repo](https://huggingface.co/anicka/cve-backport-codegen-qwen25-32b-v1).
49
 
50
- ## Evaluation
51
 
52
- Per-hunk evaluation on held-out test cases the model never saw during training:
53
 
54
- | Metric | v1 | v2 | v3 |
55
- |--------|----|----|-----|
56
- | Average recall | 91% | 94% | **94%** |
57
- | Average precision | — | 93% | **98%** |
58
- | Exact match | — | 15/20 | **16/20** |
59
- | Perfect hunks (>=95%) | 16/18 | 17/20 | **17/20** |
60
- | Fail (<10%) | 1/18 | 0/20 | **0/20** |
61
 
62
  By tier:
63
- - **Identical** (upstream patch applies directly): 95% recall, 98% precision
64
- - **Adapted** (line numbers/context differ): 89% recall, 97% precision
 
 
 
 
 
 
 
65
 
66
- ## Training Details
67
 
68
- | | v1 | v2 | v3 |
69
- |-|----|----|-----|
70
- | Dataset | 17,007 | 24,452 | **35,667** |
71
- | Learning rate | 2e-4 | 2e-4 | **1e-4** |
72
- | Epochs | 2 | 2 | 2 |
73
- | Training time | 13h | 27h | 41h |
74
- | Hardware | H100 NVL | H100 NVL | H100 NVL |
75
- | Method | QLoRA r=64 α=128 | QLoRA r=64 α=128 | QLoRA r=64 α=128 |
76
 
77
- v3 uses a lower learning rate (1e-4 vs 2e-4) for stability with the larger dataset, and includes data quality filtering to remove toxic examples (XML test data, huge outputs) that caused training instability in earlier runs.
 
 
 
 
 
 
78
 
79
  ## Prompt Format
80
 
81
- ChatML format. Each prompt covers one hunk region with 15 lines of context padding:
 
 
82
 
83
  **System:**
84
  ```
@@ -94,37 +98,77 @@ Rules:
94
  ```
95
 
96
  **User:**
97
- ```
98
- ## File: lib/url.c
99
- ## Lines: 100-130
100
 
101
- \`\`\`c
102
- <vulnerable source code region>
103
- \`\`\`
104
 
105
  ## Fix
106
- CVE-2024-1234: fix buffer overflow in url_parse()
 
 
 
 
 
 
 
 
 
 
 
107
 
108
- \`\`\`diff
109
- <upstream patch>
110
- \`\`\`
 
 
 
 
111
  ```
112
 
113
- **Assistant:** (the fixed source code, raw, no fences)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  ## Training Data
116
 
117
- **[anicka/cve-backport-codegen-dataset](https://huggingface.co/datasets/anicka/cve-backport-codegen-dataset)** — 35,667 per-hunk examples from openSUSE maintenance patches, covering 90+ packages and 2,300+ CVEs.
118
 
119
- ## Intended Use
120
 
121
- This model assists with security patch backporting in Linux distribution maintenance. It is a research tool — all generated patches must be reviewed by a maintainer before application. "Applies and builds" validates mechanical correctness, not semantic correctness.
122
 
123
- ## Links
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
- - **Tool**: [github.com/openSUSE/cve-backport-tool](https://github.com/openSUSE/cve-backport-tool)
126
- - **Dataset**: [anicka/cve-backport-codegen-dataset](https://huggingface.co/datasets/anicka/cve-backport-codegen-dataset)
127
- - **Legacy repo** (v1/v2 GGUFs + safetensors): [anicka/cve-backport-codegen-qwen25-32b-v1](https://huggingface.co/anicka/cve-backport-codegen-qwen25-32b-v1)
128
 
129
  ## License
130
 
 
5
  - security
6
  - patch-backporting
7
  - code-generation
8
+ - test-generation
9
  - qwen2
10
  - qlora
11
  - opensuse
 
16
  pipeline_tag: text-generation
17
  ---
18
 
19
+ # CVE Backport Code Generation — Qwen2.5-Coder-32B (v4)
20
 
21
+ Fine-tuned [Qwen2.5-Coder-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct) for security patch backporting via per-hunk code generation, with CVE test case generation.
22
 
23
+ Instead of generating unified diffs, this model takes a vulnerable code region and a fix description, and outputs the **fixed version of the code**. A programmatic diff then produces the final patch. Optionally, the model can also generate a **test case** that verifies the fix.
24
 
25
  ## Quick Start
26
 
 
 
27
  ```bash
28
+ git clone https://github.com/openSUSE/cve-backport-tool
29
+ cd cve-backport-tool
30
+ ./setup.sh # downloads GGUF, registers with ollama
31
 
 
32
  python3 cve-backport.py \
33
+ --cve CVE-2024-1234 \
34
+ --package curl \
35
+ --patch upstream-fix.patch \
36
+ --obs-fetch --obs-project openSUSE:Leap:15.6:Update \
37
+ --retry 3
38
  ```
39
 
40
  ## GGUF Downloads
41
 
42
+ | File | Quant | Size | Notes |
43
+ |------|-------|------|-------|
44
+ | `cve-backport-codegen-v4-q8_0.gguf` | Q8_0 | 33 GB | **Recommended** (v4, 36K dataset + test generation) |
45
+ | `cve-backport-codegen-v3-q8_0.gguf` | Q8_0 | 33 GB | v3 (35K dataset, 98% precision) |
 
 
 
46
 
47
+ ## Evaluation (v4)
48
 
49
+ Per-hunk evaluation on 100 held-out examples the model never saw during training:
50
 
51
+ | Metric | v3 (n=20) | v4 (n=100) |
52
+ |--------|-----------|------------|
53
+ | Average recall | 94% | **93%** |
54
+ | Average precision | 98% | **95%** |
55
+ | Exact match | 16/20 | **87/100** |
56
+ | Failures (<10%) | 0/20 | **4/100** |
 
57
 
58
  By tier:
59
+ - **Identical** (upstream patch applies directly): 94% recall
60
+ - **Adapted** (line numbers/context differ): 86% recall
61
+
62
+ ### Test Generation (new in v4)
63
+
64
+ 50 held-out CVEs with known reference tests:
65
+ - Average quality score: **0.67**
66
+ - All 50 produced structurally valid tests
67
+ - 17/50 matched reference test exactly
68
 
69
+ ### Comparison with Frontier Models
70
 
71
+ Same eval, same 100 examples, optimized prompts with markdown stripping:
 
 
 
 
 
 
 
72
 
73
+ | Model | Recall | Precision | Exact | Failures |
74
+ |-------|--------|-----------|-------|----------|
75
+ | **CVE Backport v4** (32B fine-tuned) | **93%** | **95%** | **87/100** | **4** |
76
+ | Gemini 3.1 Pro (frontier, zero-shot) | 27% | 24% | 10/100 | 50 |
77
+ | Gemini 2.0 Flash (frontier, zero-shot) | 13% | 17% | 4/100 | 81 |
78
+
79
+ Fine-tuning on 36K domain-specific examples outperforms frontier models by 3-7x on this task.
80
 
81
  ## Prompt Format
82
 
83
+ ChatML format. Each prompt covers one hunk region with 15 lines of context padding.
84
+
85
+ ### Code Generation (3-turn)
86
 
87
  **System:**
88
  ```
 
98
  ```
99
 
100
  **User:**
101
+ ````
102
+ ## File: lib/ftp.c
103
+ ## Lines: 2836-2912
104
 
105
+ ```c
106
+ {vulnerable code region with 15-line padding}
107
+ ```
108
 
109
  ## Fix
110
+ CVE-2017-8817: FTP wildcard matching zero terminate the entry path
111
+
112
+ ```diff
113
+ {upstream patch}
114
+ ```
115
+ ````
116
+
117
+ **Assistant:** The fixed code (same region with the security fix applied).
118
+
119
+ ### Test Generation (5-turn, new in v4)
120
+
121
+ After the code generation turn, an optional second turn:
122
 
123
+ **User:**
124
+ ```
125
+ Write a test case that:
126
+ 1. Triggers the vulnerability in the original code above
127
+ 2. Passes after applying your fix
128
+
129
+ Output ONLY the test code, nothing else.
130
  ```
131
 
132
+ **Assistant:** Test code targeting the specific CVE.
133
+
134
+ ## Training
135
+
136
+ | | |
137
+ |-|-|
138
+ | Base model | Qwen2.5-Coder-32B-Instruct |
139
+ | Method | QLoRA (4-bit NF4, r=64, alpha=128) |
140
+ | Epochs | 2 |
141
+ | Learning rate | 1e-4 |
142
+ | Max sequence length | 4,096 tokens |
143
+ | Batch size | 1 (gradient accumulation 8) |
144
+ | Training examples | 36,166 (35,396 codegen + 770 codegen+test) |
145
+ | Training time | 41.2 hours |
146
+ | Hardware | 2x NVIDIA H100 NVL 94GB |
147
+ | Label masking | Multi-turn aware (both assistant segments trained) |
148
 
149
  ## Training Data
150
 
151
+ **[anicka/cve-backport-codegen-dataset](https://huggingface.co/datasets/anicka/cve-backport-codegen-dataset)** — 36,166 per-hunk examples from openSUSE maintenance patches, covering 145+ packages and 2,300+ CVEs, with per-example SPDX license metadata.
152
 
153
+ ## Reproducibility
154
 
155
+ Trained using the [Teapot](https://github.com/anicka-net/teapot) composable training pipeline:
156
 
157
+ ```bash
158
+ teapot compose configs/cve-backport.config
159
+ teapot train configs/cve-backport.config --backend qlora-hf
160
+ teapot eval configs/cve-backport.config
161
+ ```
162
+
163
+ All versioned datasets available at the dataset repo (`train-v1.jsonl` through `train-v4.jsonl`).
164
+
165
+ ## How It Was Built
166
+
167
+ This model, tool, dataset pipeline, and training infrastructure were developed by Claude (Anthropic) with code review by Codex (OpenAI), under the direction of Anna Maresova (SUSE Engineering).
168
+
169
+ ## Intended Use
170
 
171
+ This model assists with security patch backporting in Linux distribution maintenance. It is a research tool — all generated patches must be reviewed by a maintainer before application.
 
 
172
 
173
  ## License
174