CoolFace
Modelpublic

saketgarodia1/distilbert-IT-ticket-student-4bit

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes6downloads
Model Card

๐Ÿ“˜ DistilBERT IT Ticket Classifier โ€“ 4-bit NF4 Student

This repository contains a 4-bitโ€“quantized version of my DistilBERT IT ticket classifier:

The goal of this repo is to provide a much smaller, GPU-friendly model that still achieves strong performance on IT ticket topic classification.


๐Ÿง  Task

Task: Multi-class text classification Domain: IT service / support tickets Labels (8 classes): internal IT โ€œTopic_groupโ€ categories (e.g. VPN, Email, Storage, Hardware, etc.)


๐Ÿ”ง Model Details

  • โ€”Architecture: DistilBERT (distilbert-base-uncased)
  • โ€”Head: AutoModelForSequenceClassification with 8 labels
  • โ€”Training scheme (base student):
  • โ€”Knowledge distillation from the BERT teacher
  • โ€”Combined loss: \[ \mathcal{L} = \alpha \cdot \text{CE}(\text{student}, y) + (1 - \alpha) \cdot \text{KL}(pT, pS) \]
  • โ€”ฮฑ = 0.3 (more weight on hard labels)
  • โ€”Temperature T = 2 for softened logits
  • โ€”Optimizer: AdamW
  • โ€”Learning rate: 2e-5
  • โ€”Weight decay: 0.01
  • โ€”Epochs: 3
  • โ€”Batch size: 16 / 32
  • โ€”Teacher is frozen (used only to produce logits)

The full-precision student lives in saketgarodia1/bert-it-ticket-student. This repo is a post-training 4-bit quantized copy of that model.


๐Ÿงฎ Quantization (4-bit NF4 with bitsandbytes)

Quantization is done using bitsandbytes with NF4 (NormalFloat4):

  • โ€”load_in_4bit=True
  • โ€”bnb_4bit_quant_type="nf4"
  • โ€”bnb_4bit_compute_dtype=torch.bfloat16
  • โ€”bnb_4bit_use_double_quant=True

Rough behavior:

  • โ€”Quantized to 4-bit (stored as `torch.uint8`):
  • โ€”Most large linear weights in the transformer (attention & FFN weights, pre-classifier, etc.).
  • โ€”Kept in FP16 (`torch.float16`):
  • โ€”Token & position embeddings
  • โ€”LayerNorm weights & biases
  • โ€”All bias terms
  • โ€”Quantization metadata (scales/zero-points, etc.)

This gives a large memory reduction compared to the FP32 teacher and FP16 student, while keeping accuracy close to the original student.


๐Ÿ“Š Evaluation

Evaluated on the same validation/test splits of Dataset: `saketgarodia1/IT-service-topic-classification-data`

Metrics are accuracy and macro-averaged F1.

๐Ÿ” Student 4-bit NF4

SplitLossAccuracyMacro F1
Validation~0.389~0.884~0.882
Test~0.422~0.880~0.875
Values are computed with a standard cross-entropy loss on the hard labels, and sklearn.metrics.accuracy_score / f1_score(average="macro").

๐Ÿ”— Comparison (for context)

From the full-precision models (trained in earlier notebooks):

ModelApprox. AccuracyApprox. Macro F1Notes
BERT teacher (FP32)~0.937~0.936Larger, ~110M parameters
DistilBERT student (FP32)~0.93X~0.93X~67M parameters
DistilBERT student (4-bit)~0.88~0.88Quantized, much smaller

(Replace 0.93X with your final student numbers if you log them.)


๐Ÿš€ How to Use

Simple inference (auto-quantization with bitsandbytes)

python
import torch
from transformers import (
    AutoTokenizer,
    AutoModelForSequenceClassification,
    BitsAndBytesConfig,
)

model_id = "saketgarodia1/distilbert-IT-ticket-student-4bit"

# 4-bit NF4 config (same as used for export)
nf4_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
    bnb_4bit_use_double_quant=True,
)

tokenizer = AutoTokenizer.from_pretrained(model_id)

model = AutoModelForSequenceClassification.from_pretrained(
    model_id,
    quantization_config=nf4_config,
    device_map="auto",   # place layers on available GPU(s)
)

text = "VPN not connecting to corporate WiFi"
inputs = tokenizer(text, return_tensors="pt").to(model.device)

with torch.no_grad():
    logits = model(**inputs).logits

pred_id = logits.argmax(dim=-1).item()
print("Predicted class id:", pred_id)