compressgpt-core 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- compressgpt_core-0.1.0/LICENSE +21 -0
- compressgpt_core-0.1.0/PKG-INFO +139 -0
- compressgpt_core-0.1.0/README.md +98 -0
- compressgpt_core-0.1.0/compressgpt/__init__.py +34 -0
- compressgpt_core-0.1.0/compressgpt/compute_metrics.py +440 -0
- compressgpt_core-0.1.0/compressgpt/config.py +378 -0
- compressgpt_core-0.1.0/compressgpt/create_dataset.py +517 -0
- compressgpt_core-0.1.0/compressgpt/label_space.py +201 -0
- compressgpt_core-0.1.0/compressgpt/model_check.py +645 -0
- compressgpt_core-0.1.0/compressgpt/model_runner.py +413 -0
- compressgpt_core-0.1.0/compressgpt/trainer.py +1436 -0
- compressgpt_core-0.1.0/compressgpt/utils.py +170 -0
- compressgpt_core-0.1.0/compressgpt_core.egg-info/PKG-INFO +139 -0
- compressgpt_core-0.1.0/compressgpt_core.egg-info/SOURCES.txt +22 -0
- compressgpt_core-0.1.0/compressgpt_core.egg-info/dependency_links.txt +1 -0
- compressgpt_core-0.1.0/compressgpt_core.egg-info/requires.txt +16 -0
- compressgpt_core-0.1.0/compressgpt_core.egg-info/top_level.txt +1 -0
- compressgpt_core-0.1.0/pyproject.toml +73 -0
- compressgpt_core-0.1.0/setup.cfg +4 -0
- compressgpt_core-0.1.0/tests/test_dataset_builder.py +631 -0
- compressgpt_core-0.1.0/tests/test_label_space.py +284 -0
- compressgpt_core-0.1.0/tests/test_train_script.py +287 -0
- compressgpt_core-0.1.0/tests/test_trainer.py +456 -0
- compressgpt_core-0.1.0/tests/test_utils.py +482 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 chandan678
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: compressgpt-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LLM Compression and Optimization Library - Build the smallest runnable models that preserve target accuracy
|
|
5
|
+
Author: chandan678
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/chandan678/compressgpt
|
|
8
|
+
Project-URL: Repository, https://github.com/chandan678/compressgpt
|
|
9
|
+
Project-URL: Issues, https://github.com/chandan678/compressgpt/issues
|
|
10
|
+
Keywords: llm,compression,optimization,fine-tuning,machine-learning,deep-learning,transformers,sft,supervised-fine-tuning
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: pandas>=1.5.0
|
|
26
|
+
Requires-Dist: datasets>=2.0.0
|
|
27
|
+
Requires-Dist: transformers>=4.40.0
|
|
28
|
+
Requires-Dist: scikit-learn>=1.0.0
|
|
29
|
+
Requires-Dist: torch>=2.0.0
|
|
30
|
+
Requires-Dist: tqdm>=4.60.0
|
|
31
|
+
Requires-Dist: numpy>=1.20.0
|
|
32
|
+
Requires-Dist: peft>=0.10.0
|
|
33
|
+
Requires-Dist: trl==0.19.0
|
|
34
|
+
Requires-Dist: accelerate>=0.20.0
|
|
35
|
+
Requires-Dist: bitsandbytes>=0.41.0
|
|
36
|
+
Requires-Dist: llama-cpp-python>=0.2.0
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# compressGPT
|
|
43
|
+
|
|
44
|
+
**compressGPT** is a flexible, modular training pipeline designed to bridge the gap between large foundation models and efficient edge-ready deployment.
|
|
45
|
+
|
|
46
|
+
It orchestrates the full lifecycle of Large Language Model (LLM) optimization — from supervised fine-tuning, through post-quantization recovery, to production-ready artifact generation — with a single, composable API.
|
|
47
|
+
|
|
48
|
+
Unlike rigid training scripts, compressGPT allows developers to define **custom compression workflows** by composing high-level stages such as `ft`, `compress_4bit`, and `deploy`. Whether you need a high-accuracy FP16 model for server inference or a highly compressed GGUF model for CPU-only deployment, compressGPT automates tokenization, adapter training, memory-efficient evaluation, and artifact generation to deliver the **smallest runnable model that preserves task-level accuracy**.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 🚀 Quick Start
|
|
53
|
+
|
|
54
|
+
Below is a complete example that transforms a CSV dataset into a compressed, deployment-ready 4-bit Llama-3 model.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from compressgpt import (
|
|
58
|
+
CompressTrainer,
|
|
59
|
+
DatasetBuilder,
|
|
60
|
+
TrainingConfig,
|
|
61
|
+
DeploymentConfig,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
prompt_template = (
|
|
65
|
+
'Classify this notification as "Important" or "Ignore".\n'
|
|
66
|
+
'Important: Security alerts, direct messages, payment confirmations.\n'
|
|
67
|
+
'Ignore: Marketing promos, news digests, social media likes.\n\n'
|
|
68
|
+
'Notification: {text}\n'
|
|
69
|
+
'Answer:'
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
MODEL_ID = "meta-llama/Llama-3.2-1B"
|
|
73
|
+
|
|
74
|
+
# Build dataset
|
|
75
|
+
builder = DatasetBuilder(
|
|
76
|
+
data_path="notifications.csv",
|
|
77
|
+
model_id=MODEL_ID,
|
|
78
|
+
prompt_template=prompt_template,
|
|
79
|
+
input_column_map={"text": "message_body"},
|
|
80
|
+
label_column="label",
|
|
81
|
+
).build()
|
|
82
|
+
|
|
83
|
+
# Run compression pipeline
|
|
84
|
+
trainer = CompressTrainer(
|
|
85
|
+
model_id=MODEL_ID,
|
|
86
|
+
dataset_builder=builder,
|
|
87
|
+
stages=["ft", "compress_4bit", "deploy"],
|
|
88
|
+
training_config=TrainingConfig(
|
|
89
|
+
num_train_epochs=1,
|
|
90
|
+
eval_strategy="epoch",
|
|
91
|
+
save_strategy="epoch",
|
|
92
|
+
),
|
|
93
|
+
deployment_config=DeploymentConfig(
|
|
94
|
+
save_merged_fp16=True, # Canonical dense model
|
|
95
|
+
save_quantized_4bit=True, # BitsAndBytes 4-bit
|
|
96
|
+
save_gguf_q4_0=True, # GGUF for llama.cpp
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
results = trainer.run()
|
|
101
|
+
|
|
102
|
+
print("Training complete!")
|
|
103
|
+
print(results)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 📦 Deployment & Artifacts
|
|
107
|
+
|
|
108
|
+
### Deployment Methods
|
|
109
|
+
The final stage of the pipeline, **`deploy`**, automatically converts your optimized model into rigorous production formats. Controlled by `DeploymentConfig`, it supports:
|
|
110
|
+
|
|
111
|
+
* **GGUF (`save_gguf_q4_0`, etc.)**: The gold standard for **CPU inference**. These files can be loaded directly into [llama.cpp](https://github.com/ggerganov/llama.cpp) or [Ollama](https://ollama.com).
|
|
112
|
+
* **Quantized 4-bit (`save_quantized_4bit`)**: Pre-shrunk BitsAndBytes models. Ideal for low-VRAM **GPU inference** using Python/Transformers.
|
|
113
|
+
* **Merged FP16 (`save_merged_fp16`)**: The canonical high-precision model. Use this for **vLLM / TGI servers** or further research.
|
|
114
|
+
|
|
115
|
+
### Saving Models & Trade-offs
|
|
116
|
+
A unique feature of compressGPT is that **every stage saves its own model and metrics**. This allows you to deploy different versions of the *same model* to different devices based on their constraints.
|
|
117
|
+
|
|
118
|
+
**1. Default Outputs (`runs/default/`)**
|
|
119
|
+
Every stage you run automatically saves its result:
|
|
120
|
+
* `ft_adapter/`: High-accuracy LoRA adapter (best for Cloud/GPU).
|
|
121
|
+
* `compress_4bit_merged/`: Quantized & recovered model (best for accuracy/size balance).
|
|
122
|
+
* `metrics.json`: Compare `ft` vs `compress_4bit` accuracy to make data-driven deployment decisions.
|
|
123
|
+
|
|
124
|
+
**2. Deploy Outputs (`runs/default/deploy/`)**
|
|
125
|
+
Production-ready artifacts are generated here **only if enabled** in `DeploymentConfig`:
|
|
126
|
+
|
|
127
|
+
```text
|
|
128
|
+
runs/default/deploy/
|
|
129
|
+
├── merged_fp16/ # Universal format (vLLM, TGI)
|
|
130
|
+
├── quantized_4bit/ # Python-native compressed (Transformers)
|
|
131
|
+
└── gguf/
|
|
132
|
+
├── model-f16.gguf # High precision GGUF
|
|
133
|
+
└── model-q4_0.gguf # Optimized Edge/CPU GGUF
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## ⚠️ Current Support
|
|
139
|
+
Currently, compressGPT is optimized for **Classification Tasks** (e.g., Sentiment, Intent Detection, Spam Filtering). Support for Generation tasks (RAG, Chat) is coming soon.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# compressGPT
|
|
2
|
+
|
|
3
|
+
**compressGPT** is a flexible, modular training pipeline designed to bridge the gap between large foundation models and efficient edge-ready deployment.
|
|
4
|
+
|
|
5
|
+
It orchestrates the full lifecycle of Large Language Model (LLM) optimization — from supervised fine-tuning, through post-quantization recovery, to production-ready artifact generation — with a single, composable API.
|
|
6
|
+
|
|
7
|
+
Unlike rigid training scripts, compressGPT allows developers to define **custom compression workflows** by composing high-level stages such as `ft`, `compress_4bit`, and `deploy`. Whether you need a high-accuracy FP16 model for server inference or a highly compressed GGUF model for CPU-only deployment, compressGPT automates tokenization, adapter training, memory-efficient evaluation, and artifact generation to deliver the **smallest runnable model that preserves task-level accuracy**.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🚀 Quick Start
|
|
12
|
+
|
|
13
|
+
Below is a complete example that transforms a CSV dataset into a compressed, deployment-ready 4-bit Llama-3 model.
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from compressgpt import (
|
|
17
|
+
CompressTrainer,
|
|
18
|
+
DatasetBuilder,
|
|
19
|
+
TrainingConfig,
|
|
20
|
+
DeploymentConfig,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
prompt_template = (
|
|
24
|
+
'Classify this notification as "Important" or "Ignore".\n'
|
|
25
|
+
'Important: Security alerts, direct messages, payment confirmations.\n'
|
|
26
|
+
'Ignore: Marketing promos, news digests, social media likes.\n\n'
|
|
27
|
+
'Notification: {text}\n'
|
|
28
|
+
'Answer:'
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
MODEL_ID = "meta-llama/Llama-3.2-1B"
|
|
32
|
+
|
|
33
|
+
# Build dataset
|
|
34
|
+
builder = DatasetBuilder(
|
|
35
|
+
data_path="notifications.csv",
|
|
36
|
+
model_id=MODEL_ID,
|
|
37
|
+
prompt_template=prompt_template,
|
|
38
|
+
input_column_map={"text": "message_body"},
|
|
39
|
+
label_column="label",
|
|
40
|
+
).build()
|
|
41
|
+
|
|
42
|
+
# Run compression pipeline
|
|
43
|
+
trainer = CompressTrainer(
|
|
44
|
+
model_id=MODEL_ID,
|
|
45
|
+
dataset_builder=builder,
|
|
46
|
+
stages=["ft", "compress_4bit", "deploy"],
|
|
47
|
+
training_config=TrainingConfig(
|
|
48
|
+
num_train_epochs=1,
|
|
49
|
+
eval_strategy="epoch",
|
|
50
|
+
save_strategy="epoch",
|
|
51
|
+
),
|
|
52
|
+
deployment_config=DeploymentConfig(
|
|
53
|
+
save_merged_fp16=True, # Canonical dense model
|
|
54
|
+
save_quantized_4bit=True, # BitsAndBytes 4-bit
|
|
55
|
+
save_gguf_q4_0=True, # GGUF for llama.cpp
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
results = trainer.run()
|
|
60
|
+
|
|
61
|
+
print("Training complete!")
|
|
62
|
+
print(results)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 📦 Deployment & Artifacts
|
|
66
|
+
|
|
67
|
+
### Deployment Methods
|
|
68
|
+
The final stage of the pipeline, **`deploy`**, automatically converts your optimized model into rigorous production formats. Controlled by `DeploymentConfig`, it supports:
|
|
69
|
+
|
|
70
|
+
* **GGUF (`save_gguf_q4_0`, etc.)**: The gold standard for **CPU inference**. These files can be loaded directly into [llama.cpp](https://github.com/ggerganov/llama.cpp) or [Ollama](https://ollama.com).
|
|
71
|
+
* **Quantized 4-bit (`save_quantized_4bit`)**: Pre-shrunk BitsAndBytes models. Ideal for low-VRAM **GPU inference** using Python/Transformers.
|
|
72
|
+
* **Merged FP16 (`save_merged_fp16`)**: The canonical high-precision model. Use this for **vLLM / TGI servers** or further research.
|
|
73
|
+
|
|
74
|
+
### Saving Models & Trade-offs
|
|
75
|
+
A unique feature of compressGPT is that **every stage saves its own model and metrics**. This allows you to deploy different versions of the *same model* to different devices based on their constraints.
|
|
76
|
+
|
|
77
|
+
**1. Default Outputs (`runs/default/`)**
|
|
78
|
+
Every stage you run automatically saves its result:
|
|
79
|
+
* `ft_adapter/`: High-accuracy LoRA adapter (best for Cloud/GPU).
|
|
80
|
+
* `compress_4bit_merged/`: Quantized & recovered model (best for accuracy/size balance).
|
|
81
|
+
* `metrics.json`: Compare `ft` vs `compress_4bit` accuracy to make data-driven deployment decisions.
|
|
82
|
+
|
|
83
|
+
**2. Deploy Outputs (`runs/default/deploy/`)**
|
|
84
|
+
Production-ready artifacts are generated here **only if enabled** in `DeploymentConfig`:
|
|
85
|
+
|
|
86
|
+
```text
|
|
87
|
+
runs/default/deploy/
|
|
88
|
+
├── merged_fp16/ # Universal format (vLLM, TGI)
|
|
89
|
+
├── quantized_4bit/ # Python-native compressed (Transformers)
|
|
90
|
+
└── gguf/
|
|
91
|
+
├── model-f16.gguf # High precision GGUF
|
|
92
|
+
└── model-q4_0.gguf # Optimized Edge/CPU GGUF
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## ⚠️ Current Support
|
|
98
|
+
Currently, compressGPT is optimized for **Classification Tasks** (e.g., Sentiment, Intent Detection, Spam Filtering). Support for Generation tasks (RAG, Chat) is coming soon.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""
|
|
2
|
+
compressGPT - LLM Compression and Optimization Library
|
|
3
|
+
|
|
4
|
+
This library automates LLM compression and optimization, providing tools for
|
|
5
|
+
building datasets, fine-tuning, and creating the smallest runnable models
|
|
6
|
+
that preserve target accuracy.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from compressgpt.create_dataset import DatasetBuilder
|
|
10
|
+
from compressgpt.compute_metrics import ComputeMetrics
|
|
11
|
+
from compressgpt.model_runner import ModelRunner
|
|
12
|
+
from compressgpt.trainer import CompressTrainer
|
|
13
|
+
from compressgpt.config import (
|
|
14
|
+
LoraConfig,
|
|
15
|
+
QLoraConfig,
|
|
16
|
+
TrainingConfig,
|
|
17
|
+
PipelineConfig,
|
|
18
|
+
QuantizationConfig,
|
|
19
|
+
DeploymentConfig
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__version__ = "0.1.0"
|
|
23
|
+
__all__ = [
|
|
24
|
+
"DatasetBuilder",
|
|
25
|
+
"ComputeMetrics",
|
|
26
|
+
"ModelRunner",
|
|
27
|
+
"CompressTrainer",
|
|
28
|
+
"LoraConfig",
|
|
29
|
+
"QLoraConfig",
|
|
30
|
+
"TrainingConfig",
|
|
31
|
+
"PipelineConfig",
|
|
32
|
+
"QuantizationConfig",
|
|
33
|
+
"DeploymentConfig",
|
|
34
|
+
]
|