Run this model with HF Jobs

Run NafiuRahman/divast on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/NafiuRahman/divast. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/NafiuRahman/divast on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-classification", model="NafiuRahman/divast")
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("NafiuRahman/divast")
model = AutoModelForSequenceClassification.from_pretrained("NafiuRahman/divast", device_map="auto")
Quick Links

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
17
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