gemma-2-2b-it — cybersecurity advisory QLoRA adapter
A QLoRA adapter for google/gemma-2-2b-it, fine-tuned on 2,028 synthetic question–answer
pairs written from cybersecurity vulnerability advisories published in calendar year 2025
(NVD, GitHub Security Advisories, CISA ICS).
It exists to answer one question, as coursework: does fine-tuning a small model on domain Q&A beat retrieving the right passage at inference time? This adapter is system B (fine-tuned, closed book) and also underlies system C (same weights, retrieved passages in the prompt).
The short version of the results below: it does not. Closed book this adapter does not beat the base model, and with retrieval it is not detectably better than the base model with the same passages. It is published because a measured negative result is the finding, not despite it.
Try all four systems live, on the same question: https://a3-cyber-rag.vercel.app
Intended use
Research and reproduction of the A3 experiment. That is the whole of it.
- ✅ Reproducing or auditing the comparison this adapter was built for, against the held-out set and the harness that produced the numbers below.
- ✅ A worked example of QLoRA on Gemma 2, and of what domain fine-tuning does and does not buy.
- ❌ Not for security decisions. Do not use its output to judge whether you are affected by a vulnerability, to decide remediation or priority, or as a source of advisory facts. It states version numbers, attack vectors and mitigations confidently and is frequently wrong about them — see the invention rate below.
- ❌ Not a general cybersecurity assistant, and not evaluated as one.
Results, measured
65 held-out questions, the same questions for every system, from documents excluded from
training by a CVE-identifier cluster split. Judge: gpt-6-sol,
rubric-v2, blind, pointwise, reference-grounded (question + gold answer +
verbatim evidence in every call), under a rubric where an honest refusal outscores a confident
error. Judge noise floor 0.2 points on the 0–10 total, measured by
re-judging 15 answers 3 times — a difference smaller
than that is not measurable with this judge.
| System | What it is | Score /10 |
|---|---|---|
| A | gemma-2-2b-it, untouched, closed book |
2.49 ± 0.13 |
| B | this adapter, closed book | 2.18 ± 0.19 |
| C | this adapter + retrieved passages (k=5) | 6.77 ± 0.39 |
| D | gemma-2-2b-it + the same retrieved passages |
6.52 ± 0.41 |
Paired t-tests on all 65 items (the pairing removes item difficulty from the comparison):
| Comparison | Difference | 95% CI | p | Cohen's dz | |
|---|---|---|---|---|---|
| A → B | -0.31 | [-0.71, +0.10] | 0.135 | -0.19 | fine-tuning, closed book |
| B → C | +4.58 | [+3.73, +5.44] | < 0.001 | 1.33 | adding retrieval to the fine-tune |
| C → D | -0.25 | [-0.91, +0.42] | 0.464 | -0.09 | the adapter, on top of retrieval |
| A → D | +4.03 | [+3.20, +4.87] | < 0.001 | 1.20 | retrieval alone, no fine-tuning |
Three things this says, stated plainly:
- Closed book, the fine-tune does not beat the base model. A → B is -0.31 points, p = 0.135 — a measured null, not a win for either side. After the full data pipeline and the training run, this adapter is not better than the model it was fine-tuned from.
- Retrieval is what moves the score — +4.58 points, p < 0.001 — and it moves the base model just as far (+4.03, p < 0.001).
- On top of retrieval, the adapter adds nothing detectable. C → D is -0.25 points, p = 0.464, with a CI that spans zero ([-0.91, +0.42]). Same passages, same prompt, same decoding, same judge; the weights are the only difference. This was pre-registered as the outcome that would be least flattering to the work, before the run.
How it fails, which matters more than the score
| System | Refusals | Answers with ≥1 invented detail | Mean completion tokens |
|---|---|---|---|
| A — base, closed book | 28/65 | 37/65 (57%) | 404 |
| B — this adapter, closed book | 0/65 | 59/65 (91%) | 57 |
| C — this adapter + passages | 0/65 | 21/65 (32%) | 33 |
| D — base + the same passages | 6/65 | 16/65 (25%) | 70 |
Closed book, this adapter never declines and invents a specific in 59 of 65 answers (91%). The base model declines 28 times out of 65. Trained on 2,028 bare question→answer pairs with no refusal anywhere in the target text, the adapter learned that an answer is always produced — so it answers, in the register of a real advisory, with a version range where a version range belongs, and fills it in. Its groundedness component (0.14/2) is far below the base model's (0.78/2) for exactly this reason.
That behaviour survives retrieval. Observed counts, on the same 65 items, with no significance test run on them: with passages in the prompt this adapter declined 0/65 times; the base model, handed the identical passages, declined 6/65. Those are raw counts and the difference between them was never tested, so treat it as a behaviour to be aware of rather than a measured effect — but if your use depends on a model that can say "it isn't in here", check that behaviour yourself before relying on this adapter for it.
System C depends on the retriever, not on these weights
Held-out retrieval recall@5 is 0.769 (BAAI/bge-small-en-v1.5, exact flat
FAISS index). Splitting C by whether the gold chunk was actually retrieved:
| C's top-5 | n | C's score | C invents ≥1 detail |
|---|---|---|---|
| hit — gold chunk retrieved | 50 | 7.68 ± 0.37 | 18% |
| miss — gold chunk not retrieved | 15 | 3.73 ± 0.77 | 80% |
Handed the wrong passages, the grounded system writes a fluent, well-sourced, incorrect answer.
Limitations
- 65 held-out questions. Small. The C → D confidence interval admits a true advantage for this adapter of up to 0.42 points; a null is not proof of absence.
- Scored by an LLM judge, not by humans. The rubric is reference-grounded and the judge's own jitter was measured (0.2 points), but it remains a model grading a model, with whatever blind spots that carries.
- Training pairs are machine-generated (by
claude-sonnet-5), filtered by local checks and an LLM quality gate, not human-verified. - 2025 advisories only, English only. Vulnerability data ages quickly, and this adapter's knowledge is frozen. It knows nothing of 2026.
- One adapter, one rank, one domain, one base model. These results are about this adapter, not about fine-tuning in general. In particular it was trained closed book — no passages in any training prompt — so system C uses it outside the distribution it was trained for. An adapter trained for grounded answering is a different experiment.
- The held-out set is drawn from the same three sources as training; only the documents differ.
What it was trained on
2,028 training pairs (plus 106 held out for validation, split by source document)
generated by claude-sonnet-5 from a 62.5 MB corpus of 52,325 documents:
| Source | Documents | Licence |
|---|---|---|
| NVD CVE records (API 2.0) | 48,153 | US Government work, public domain |
| GitHub Security Advisories (reviewed) | 3,690 | CC-BY-4.0 |
| CISA ICSA / ICSMA / AA advisories | 482 | US Government work, public domain |
Every pair passed free local filters (verbatim-evidence check, context-leak and dangling-reference
detection, numeric-token grounding, embedding dedupe) and then an LLM quality gate
(claude-haiku-4-5) requiring groundedness ≥ 4/5 and total ≥ 12/15. 2,810 pairs were generated;
676 were rejected and retained rather than deleted.
Domain choice note: all source documents postdate Gemma 2's mid-2024 training cutoff. Probed
closed-book, base gemma-2-2b-it named the affected product for 0 of 30 sampled 2025 CVEs.
The train/held-out line is drawn by CVE-identifier cluster, not by document, because 88% of
GHSA advisories share a CVE with an NVD record and a per-document split would have put the same
vulnerability on both sides. Zero identifiers straddle the split.
Configuration
| Method | QLoRA, 4-bit NF4, double quantisation, bf16 compute |
| Rank / alpha / dropout | 16 / 32 / 0.05 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj (all linear) |
| Trainable parameters | 20,766,720 (0.796% of ~2.61 B) |
| Sequence length | 384 (measured p100 of the data = 337; zero truncation) |
| Batch | 8 × 2 accumulation = 16 effective |
| LR / schedule | 2e-4, cosine, 11 warmup steps (3%) |
| Optimiser | paged_adamw_8bit |
| Epochs / steps | 3 / 381 |
| Precision | trained and served in bf16 |
| Hardware | 1 × NVIDIA L4 (Modal), 743 s |
| Attention | eager — required, see below |
attn_implementation="eager" is not optional
gemma-2-2b-it sets attn_logit_softcapping = 50.0, but in transformers 5.17 the default
attention implementation is sdpa, and sdpa_attention_forward silently discards the softcap
argument — no warning is emitted. Loading this model the default way runs something numerically
different from what Google trained. Load the base model with attn_implementation="eager", or the
adapter will be applied to a base it was not fitted against.
Checkpoint selection
| Epoch | Validation loss | Perplexity |
|---|---|---|
| 0 (base) | 2.9635 | 19.3649 |
| 1 | 1.3385 | 3.8132 ← selected |
| 2 | 1.3401 | 3.8195 |
| 3 | 1.5246 | 4.5932 |
This adapter is the epoch-1 checkpoint, chosen by a rule registered before training: keep the lowest validation loss. Training loss fell from 2.91 to 0.67 while validation loss rose after epoch 1 — the model was memorising 2,028 examples, not generalising.
Usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE = "google/gemma-2-2b-it"
tok = AutoTokenizer.from_pretrained(BASE)
model = AutoModelForCausalLM.from_pretrained(
BASE,
dtype=torch.bfloat16,
attn_implementation="eager", # required — see above
device_map="cuda",
)
model = PeftModel.from_pretrained(model, "DexterP29/gemma-2-2b-it-cyber-advisories-qlora")
model.eval()
# Trained on the bare question, with no system preamble. Keep it that way.
# (Deliberately a generic question: no held-out item appears anywhere in this card.)
msgs = [{"role": "user", "content": "What is the difference between a CWE and a CVE?"}]
prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
ids = tok(prompt, return_tensors="pt", add_special_tokens=False).to(model.device)
out = model.generate(**ids, do_sample=False, max_new_tokens=512)
print(tok.decode(out[0][ids["input_ids"].shape[1]:], skip_special_tokens=True))
Evaluation used greedy decoding (do_sample=False, max_new_tokens=512,
repetition_penalty=1.0) and the bare question with no preamble — the format the adapter was
trained on. Changing either changes the numbers above.
License
This adapter is released under the Gemma Terms of Use.
It is a derivative of google/gemma-2-2b-it and your use of it is subject to those terms,
including the Gemma Prohibited Use Policy.
The adapter weights are useless without the base model, which is itself gated.
Attribution
Training data derived from NVD (NIST), CISA, and the GitHub Advisory Database (CC-BY-4.0). Advisory text from NVD and CISA is a US Government work in the public domain; GHSA content is CC-BY-4.0.
More
- Live demo, all four systems answering the same question against real endpoints, with the retrieved passages shown: https://a3-cyber-rag.vercel.app
- Full results, the per-item disagreements, the two pre-registered prompt arms, the decision log
and
report.pdflive in the project repository (coursework; not public at the time of writing).
Model card generated by train/make_model_card.py from eval/leaderboard.json and
eval/recall_at_k.json — the files the evaluation harness wrote. No result on this page was typed
in by hand.