DiVaST-3L-768H

DiVaST (Distilled Vulnerability and SATD Transformer) predicts two labels for a C or C++ function, in the order [Vulnerability, SATD] (the SATD label is called MAT in the dataset). This model is the three-layer student: it keeps layers 2, 4, and 6 of a fine-tuned CodeBERTa-small teacher (hidden size 768, 62.2M parameters) and was trained on the labels and on the teacher's per-label probabilities. For functions longer than 512 tokens, its tokenizer keeps the end instead of the start (truncation_side: "left" in tokenizer_config.json), so fewer TODO and FIXME tags are cut off.

Code, replication notebook, and all results: https://github.com/nafiurahman00/divast

Usage

The model loads like the challenge baseline, and a label is predicted when its sigmoid probability exceeds 0.5:

import torch
from transformers import RobertaForSequenceClassification, RobertaTokenizer

tokenizer = RobertaTokenizer.from_pretrained("NafiuRahman/divast")
model = RobertaForSequenceClassification.from_pretrained("NafiuRahman/divast").eval()
code = "int f(char *s) { /* TODO: check the length */ char b[8]; strcpy(b, s); return 0; }"
enc = tokenizer([code], return_tensors="pt", truncation=True, max_length=512)
with torch.no_grad():
    vulnerability, satd = (torch.sigmoid(model(**enc).logits)[0] > 0.5).tolist()

The six-layer teacher is in the subfolder teacher/: RobertaForSequenceClassification.from_pretrained("NafiuRahman/divast", subfolder="teacher").

Results

Public test set, official protocol of the challenge (one Colab T4 session, batch 600, 10 repetitions, threshold 0.5):

Model F1 vulnerability F1 SATD Average F1 Runtime (s) GFLOPs Score
CodeBERT baseline 0.9390 0.8814 0.9102 242.61 2,666,510 0.7198
Teacher (teacher/) 0.9419 0.9283 0.9351 120.73 1,333,285 0.8480
DiVaST-3L-768H 0.9323 0.9274 0.9299 60.53 666,673 0.9014

Training

Teacher: CodeBERTa-small fine-tuned with binary cross-entropy, 3 epochs, AdamW, learning rate 3e-5, weight decay 0.01, warm-up over 6% of the steps, batch size 32, inputs of 400 tokens, fp16, seed 42, on 95% of the training set; the checkpoint with the best validation average F1 (remaining 5%) is kept.

Student: initialised from the teacher's embeddings, layers 2, 4, and 6, and classification head, then trained with the same settings on (1 - a) * BCE(sigmoid(z_s), y) + a * T^2 * BCE(sigmoid(z_s / T), sigmoid(z_t / T)), with a = 0.5 and T = 2; the teacher is frozen. Thresholds tuned on validation change the average F1 by at most 0.0002, so the model uses 0.5.

Downloads last month
12
Safetensors
Model size
62.2M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for NafiuRahman/divast

Finetuned
(71)
this model

Dataset used to train NafiuRahman/divast