GreenFormer is a generalized pipeline that reduces the energy consumption, carbon footprint, and inference latency of any Transformer-based NLP model through a sequential compression pipeline: Knowledge Distillation β Structured Pruning β INT8 Quantization (PTQ & QAT).
- π Multi-Architecture Support β Works across BERT, RoBERTa, ALBERT, and ELECTRA via a pluggable Model Registry
- β‘ 4-Stage Compression Pipeline β Knowledge Distillation β Structured Pruning β Post-Training Quantization β Quantization-Aware Training
- π Real-Time Energy Tracking β CodeCarbon integration for measuring kWh and COβ emissions per training run
- π₯οΈ Dual-Platform Benchmarking β Compare algorithmic vs. datacenter efficiency on Apple M2 CPU and NVIDIA T4 GPU
- π Interactive Dashboard β Streamlit-based research visualization with comparative tables and charts
- π Auto-Generated Reports β One-click Word document generation for academic submissions
ββββββββββββββββββββββββββββββββββββββββββββ
β MODEL REGISTRY β
β bert | roberta | albert | electra β
ββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββββββββββββββ
β GENERALIZED PIPELINE β
β β
β Stage 1: Baseline Teacher Training β
β β β
β Stage 2: Knowledge Distillation (KD) β
β β β
β Stage 3: Structured Pruning (30%) β
β β β
β Stage 4a: Post-Training Quantization β
β Stage 4b: Quantization-Aware Training β
β β
ββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
ββββββββββββββββΌββββββββββββββββββββββββββββ
β OUTPUT β
β β’ Compressed INT8 model β
β β’ Energy & COβ metrics (JSON) β
β β’ ONNX export for deployment β
β β’ Streamlit dashboard β
β β’ Auto-generated DOCX report β
ββββββββββββββββββββββββββββββββββββββββββββ
| Stage | Model | Accuracy | Size (MB) | Speedup | Energy Reduction |
|---|---|---|---|---|---|
| Baseline | BERT-base (Teacher) | 93.1% | 418 | 1.0Γ | β |
| Knowledge Distillation | DistilBERT-6L (Student) | 81.0% | 255 | 1.9Γ | -36% |
| Structured Pruning | Pruned DistilBERT (30%) | 81.4% | 255 | 2.1Γ | -41% |
| INT8 QAT | Quantized DistilBERT | 81.3% | 91 | 4.7Γ | -68% |
Key Finding: INT8 quantization performance is highly hardware-dependent β Apple M2 (CPU) shows latency increases due to lack of native INT8 support, while NVIDIA T4 (GPU) achieves significant speedups.
# Clone the repository
git clone https://github.com/ATULSHARMA1234/GreenFormer.git
cd GreenFormer
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # macOS/Linux
# Install dependencies
pip install -r requirements.txtpython run_fast_pipeline.py --task sst2# Single model
python run_generalized_pipeline.py --model bert --task sst2
python run_generalized_pipeline.py --model roberta --task cola
python run_generalized_pipeline.py --model albert --task sst2
# All models Γ all tasks
python run_generalized_pipeline.py --model all --task bothstreamlit run dashboard/unified_paper_dashboard.pypython generate_report.pyGreenFormer/
βββ src/
β βββ model_registry.py # π Pluggable model family registry
β βββ train_baseline.py # Stage 1: Teacher training
β βββ distillation.py # Stage 2: Knowledge Distillation
β βββ pruning.py # Stage 3: Structured Pruning
β βββ quantization.py # Stage 4: PTQ & QAT
β βββ evaluation.py # Metrics & benchmarking
β βββ energy_tracker.py # CodeCarbon wrapper
β βββ export_onnx.py # ONNX model export
β βββ evaluate_onnx.py # ONNX Runtime benchmarking
β βββ utils.py # Shared utilities
βββ dashboard/
β βββ unified_paper_dashboard.py # Main Streamlit dashboard
β βββ graph_dashboard.py # Chart visualizations
β βββ tables_dashboard.py # Comparative tables
βββ run_generalized_pipeline.py # π± Generalized multi-model pipeline
βββ run_fast_pipeline.py # Original BERT-specific pipeline
βββ generate_report.py # Auto-generate Word report
βββ requirements.txt
βββ README.md
| Family | Teacher | Student | Parameters |
|---|---|---|---|
| BERT | bert-base-uncased (110M) |
DistilBERT-6L (66M) | 40% reduction |
| RoBERTa | roberta-base (125M) |
DistilRoBERTa (82M) | 34% reduction |
| ALBERT | albert-base-v2 (11.8M) |
ALBERT-tiny 4L (~4M) | 66% reduction |
| ELECTRA | electra-base (110M) |
ELECTRA-small (14M) | 87% reduction |
Adding a new model requires only a new entry in
src/model_registry.pyβ zero pipeline code changes.
| Platform | Role | Hardware |
|---|---|---|
| Apple MacBook Air M2 | Algorithmic efficiency (CPU) | 8-core CPU, 8GB RAM |
| Google Colab / RunPod | Datacenter efficiency (GPU) | NVIDIA Tesla T4, 16GB VRAM |
L = Ξ± Β· TΒ² Β· KL(student_soft β teacher_soft) + (1 - Ξ±) Β· CE(student, labels)
- Temperature T = 4.0, Alpha Ξ± = 0.7
- L1-norm global unstructured pruning targeting all
nn.Linearlayers - 30% sparsity with post-pruning fine-tuning for accuracy recovery
- PTQ: Dynamic INT8 quantization via
torch.quantization.quantize_dynamic - QAT: Quantization-aware training with fake quantization nodes during forward pass
- CodeCarbon for real-time energy (kWh) and COβ (kg) tracking
- PUE scaling: E_total = E_IT Γ PUE (industry avg 1.58 β optimized 1.09)
Frameworks: PyTorch, HuggingFace Transformers, ONNX Runtime, Streamlit
Libraries: CodeCarbon, Scikit-learn, Plotly, Matplotlib, Pandas, NumPy, TensorBoard
Platforms: Python 3.10+, Google Colab (NVIDIA T4 GPU), Apple M2 CPU
Benchmarks: GLUE (SST-2 β Sentiment, CoLA β Linguistic Acceptability)
Atul Sharma , Sarthak Goyal , Panya Kapoor
This project is licensed under the MIT License.
If you use GreenFormer in your research, please cite:
@software{greenformer2026,
author = {Sharma, Atul},
title = {GreenFormer: A Multi-Architecture Model Compression Framework for Sustainable AI},
year = {2026},
url = {https://github.com/ATULSHARMA1234/GreenFormer}
}