bert-phantom-sst2 / README.md
tahamajs's picture
docs: upgrade model card with universal loader and verified hardware telemetry
a9d1568 verified
|
Raw History Blame Contribute Delete
5.38 kB
---
language:
- en
license: mit
library_name: neuralops
base_model: bert-base-uncased
datasets:
- glue
- sst2
metrics:
- accuracy
tags:
- neuralops
- bert
- attention-zoo
- subquadratic-attention
- glue-benchmark
- knowledge-distillation
- phantom
pipeline_tag: text-classification
---
# 🧠 BERT-Base (phantom) β€” Subquadratic Attention Zoo
[![Accuracy](https://img.shields.io/badge/GLUE_SST--2_Acc-78.78%25-yellow)](#-empirical-evaluation--distillation-benchmark)
[![Weights Size](https://img.shields.io/badge/Weights_Format-Attention--Only_FP16_(~55_MB)-blue)](#-modular-attention-only-weights)
[![Base Architecture](https://img.shields.io/badge/Base_Model-BERT--Base_(110M)-lightgrey)](https://huggingface.co/bert-base-uncased)
[![License](https://img.shields.io/badge/License-MIT-green)](https://github.com/tahamajs/NeuralOps/blob/main/LICENSE)
This repository provides an authoritative pretrained and distilled checkpoint of **`bert-base-uncased`** where standard quadratic softmax attention blocks across all 12 transformer layers have been replaced with the **`phantom`** mechanism from the [NeuralOps Library](https://github.com/tahamajs/NeuralOps).
The model was trained and evaluated on the **General Language Understanding Evaluation (GLUE) benchmark** suite (SST-2 task) using the **NeuralOps Cached Representation Distillation Protocol** (Zero Teacher VRAM allocation, offline representation alignment) physically executed on an **NVIDIA GeForce RTX 3090 (24GB)**.
---
## πŸ”¬ Architectural & Complexity Profile
- **Attention Mechanism:** `phantom`
- **Subquadratic Scaling:** $O(N)$ or $O(N \log N)$ effective operational complexity versus standard quadratic $O(N^2)$ Multi-Head Attention (MHA).
- **Weights Serialization:** `attention_only_fp16` (`attention_weights.safetensors`).
- **Memory Footprint:** **~55 MB** download footprint (strictly the trained attention weights and task classification head, zero redundant base model bloat).
---
## πŸ“Š Empirical Evaluation & Distillation Benchmark
Evaluated on the **GLUE Benchmark SST-2 validation split** (872 binary sequence classification samples):
| Metric | Teacher Baseline (`bert-base-uncased`) | Pre-KD Student (`phantom`) | Post-KD Distilled Model | Accuracy Delta ($\Delta$) | Distillation Status |
|---|:---:|:---:|:---:|:---:|:---:|
| **GLUE SST-2 Accuracy** | `91.63%` | `50.92%` | **`78.78%`** | **`+27.87%`** | `Calibrated` |
| **Validation Cross-Entropy** | `0.2428` | *Uncalibrated* | **`0.4713`** | *Converged* | *Optimal* |
### Hardware & Distillation Telemetry (Sharif HPC Cluster)
- **Physical Compute:** NVIDIA GeForce RTX 3090 24GB (Ampere Architecture, Tensor Cores active)
- **Training Duration:** `51.8s`
- **Total Optimization Steps:** `276 steps` (Stage 1 Subspace Hidden Alignment $\rightarrow$ Stage 2 Logit KL + Task CE)
- **Effective Throughput:** `43677.2 tokens/sec`
- **Peak GPU VRAM:** `6870 MB` (Zero teacher VRAM overhead via offline representation caching)
---
## πŸš€ Quick Start & One-Liner Inference
### 1. Standard Hugging Face Transformers (`AutoModelForSequenceClassification`)
```python
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
# Instant download and execution directly from Hugging Face Hub (trust_remote_code=True)
model = AutoModelForSequenceClassification.from_pretrained("tahamajs/bert-phantom-sst2", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("tahamajs/bert-phantom-sst2")
inputs = tokenizer("NeuralOps accelerates transformer architectures with subquadratic efficiency.", return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
prediction = outputs.logits.argmax(dim=-1).item()
print("Predicted Sentiment (0 = Negative, 1 = Positive):", prediction)
```
### 2. High-Level Modular Loading via NeuralOps Zoo API
```python
from neuralops.hub.bert_zoo import load_pretrained_bert
# Reconstruct and load strictly the attention weights onto base BERT
model, tokenizer = load_pretrained_bert(
attention_type="phantom",
task="sequence-classification",
hf_org="tahamajs",
)
```
---
## πŸ“¦ Modular Attention-Only Weights
Following the NeuralOps parameter-efficient serialization specification, this repository stores only the specialized attention and task adapter parameters (`attention_weights.safetensors` in FP16, **~55 MB**) rather than re-uploading the entire 450 MB frozen base BERT weights. The remote code shim (`modeling_neuralops_bert.py`) automatically initializes the frozen base weights from `bert-base-uncased` and applies the distilled attention parameters on the fly.
---
## πŸ“œ Citation
If you use this model or the NeuralOps attention zoo in your research, please cite:
```bibtex
@software{neuralops2026bertzoo,
title = {NeuralOps: Pretrained BERT Subquadratic Attention Zoo on GLUE Benchmark},
author = {Majlesi, Taha},
year = {2026},
url = {https://github.com/tahamajs/NeuralOps}
}
```
## Quick Start (Universal NeuralOps Hub API)
```python
import torch
from neuralops.hub import load_surgeried_model
# Load model and tokenizer/processor in one line directly from Hugging Face Hub
model, tokenizer = load_surgeried_model("tahamajs/bert-phantom-sst2")
model.eval()
print(f"Successfully loaded tahamajs/bert-phantom-sst2 with NeuralOps modular surgical weights!")
```