Organizations: School of Computer Science, University of Nottingham, Nottingham, United Kingdom · School of Informatics and Computing, Northern Arizona University, Flagstaff, United States of America · School of Computer Science, University of Nottingham, Ningbo, China
Recent work applies Large Language Models (LLMs) to source-code vulnerability detection, but most evaluations still rely on random train-test splits that ignore time and overestimate real-world performance. In practice, detectors are deployed on evolving code bases and must recognise future vulnerabilities under temporal distribution shift. This paper investigates continual fine-tuning of a decoder-style language model (microsoft/phi-2 with LoRA) on a CVE-linked dataset spanning 2018-2024, organised into bi-monthly windows. We evaluate eight continual learning strategies, including window-only and cumulative training, replay-based baselines and regularisation-based variants. We propose Hybrid Class-Aware Selective Replay (Hybrid-CASR), a confidence-aware replay method for binary vulnerability classification that prioritises uncertain samples while maintaining a balanced ratio of VULNERABLE and FIXED functions in the replay buffer. On bi-monthly forward evaluation Hybrid-CASR achieves a Macro-F1 of 0.667, improving on the window-only baseline (0.651) by 0.016 with statistically significant gains (p=0.026) and stronger backward retention (IBR@1 of 0.741). Hybrid-CASR also reduces training time per window by about 17 percent compared to the baseline, whereas cumulative training delivers only a minor F1 increase (0.661) at a 15.9-fold computational cost. Overall, the results show that selective replay with class balancing offers a practical accuracy-efficiency trade-off for LLM-based temporal vulnerability detection under continuous temporal drift.
Figures & tables
Component
Setting
Component
Setting
Base model
microsoft/phi-2
Learning rate
2×10−4
Classification head
Binary (2 logits)
Weight decay
0
LoRA rank r
16
Training epochs
3
LoRA α
32
Batch size (default)
32
LoRA dropout
0.05
Batch size (granularity)
4
Optimizer
AdamW
Evaluation frequency
Per epoch
Table 1: Training configuration maintained across all experimental conditions.
Figure 1: Distribution of vulnerability disclosures across bi-monthly windows (2018–2024), illustrating volume growth and temporal variability.
Strategy
Mechanism
Memory requirements
Replay-1P
Uniform sampling from previous window (Rebuffi et al., 2017).
Memory buffer storing samples from the immediately previous window.
Replay-3P
Uniform sampling from 3 previous windows (Rebuffi et al., 2017).
Memory buffer storing samples from the last 3 windows.
CASR
Uncertainty-based selective replay (Aljundi et al., 2019).
Memory buffer with prioritised vulnerable samples.
Hybrid-CASR
CASR + class balancing (this work).
Memory buffer with class-balanced sampling across VULNERABLE / FIXED.
LB-CL
Class-weighted loss (Wu et al., 2024).
No extra memory beyond model parameters.
OLoRA
Orthogonality constraints on LoRA updates (Lopez-Paz and Ranzato, 2017; Chaudhry et al., 2019).
LoRA adapter parameters (and small statistics for orthogonal subspace).
Table 2: Continual learning strategies with mechanisms and memory requirements.
Granularity
Windows
Mean F1
Std Dev
IQR
Min F1
Max F1
1-month
82
0.654
0.054
0.075
0.506
0.778
2-month
41
0.651
0.044
0.058
0.539
0.714
3-month
27
0.667
0.033
0.041
0.572
0.714
6-month
13
0.669
0.029
0.032
0.611
0.702
12-month
6
0.669
0.030
0.035
0.604
0.695
Table 3: Temporal granularity impact on vulnerability detection performance. All metrics are computed from forward evaluation on held-out windows.
Figure 2: Forward one-step F1 scores across different temporal granularities (1, 2, 3, 6, 12 months), showing variability and trends over chronological evaluation windows.
Figure 3: Forward F1 comparison across all methods using bi-monthly windows, highlighting differences in performance level and stability over time.
Method
IBR@1
IBR@3
IBR@5
IBR@6
Decay rate
AUC a
Replay-1P
0.791
0.747
0.734
0.729
7.8%
0.750
Hybrid-CASR
0.741
0.726
0.716
0.710
4.2%
0.723
CASR
0.734
0.719
0.707
0.706
3.8%
0.717
LB-CL
0.718
0.703
0.691
0.687
4.3%
0.700
Window-only
0.713
0.701
0.689
0.693
2.8%
0.699
Replay-3P
0.702
0.688
0.676
0.673
4.1%
0.685
Table 5: Knowledge retention measured by Immediate Backward Retention at multiple lags. Decay rate is defined as (IBR@1−IBR@6)/IBR@1 .
Figure 4: Plasticity–stability trade-off, showing the relationship between forward learning capability and performance consistency. Methods in the upper-right region achieve the best balance.
Method
Time (s)
Time (min)
Speedup
GPU (MB)
F1/min
Efficiency
Hybrid-CASR
432
7.2
1.20 ×
19,847
0.093
124%
Window-only
520
8.7
1.00 ×
13,525
0.075
100%
Cumulative
8,291
138.2
0.06 ×
13,525
0.005
6%
Table 6: Resource consumption and efficiency. Metrics are averaged across 41 bi-monthly training windows.
Method
2019_M05–06 F1
Δ F1
2020_M05–06 F1
Δ F1
Window-only
0.539
—
0.548
—
Hybrid-CASR
0.598
+0.059
0.612
+0.064
CASR
0.606
+0.067
0.597
+0.049
Replay-1P
0.584
+0.045
0.588
+0.040
Cumulative
0.585
+0.046
0.574
+0.026
LB-CL
0.557
+0.018
0.561
+0.013
Table 7: Method performance on challenging temporal windows. Values show F1 and improvement over the window-only baseline.