Skip to content

Commit 1f0de8d

Browse files
committed
Add model_validation/gptq for GPTQ 4-bit baseline validation
Hydra-driven validation script that runs pure GPTQ (wbits=4, groupsize=128, qep=False) with a compact calibration config (max_length=512, num_calibration_samples=128) on a single model selected via model_id (HF Hub) or model_path (local), saves the quantized model, and reports original / quantized perplexity. Validation set: TinyLlama-1.1B, gemma-4-E2B, Llama-2-7B, Llama-3-8B, Qwen3-8B. SLURM submission script and runtime artifacts are git-ignored, mirroring the autobit_qep layout, so each environment supplies its own partition / paths.
1 parent b7d7498 commit 1f0de8d

4 files changed

Lines changed: 189 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ example/run_example.sh
1919
model_validation/autobit_qep/submit.sh
2020
model_validation/autobit_qep/logs/
2121
model_validation/autobit_qep/outputs/
22+
model_validation/gptq/submit.sh
23+
model_validation/gptq/logs/
24+
model_validation/gptq/outputs/
2225
work/
2326
site/
2427
debug_code/

model_validation/gptq/README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Model Validation (GPTQ 4-bit, groupsize=128)
2+
3+
Validates OneComp's `GPTQ` quantizer on multiple models with a fixed
4+
`wbits=4`, `groupsize=128` configuration and `qep=False`. Configuration
5+
is managed with [Hydra](https://hydra.cc/).
6+
7+
## Purpose
8+
9+
- Confirm that pure GPTQ (4-bit, gs=128, no QEP) runs end-to-end on a
10+
variety of model architectures and sizes.
11+
- Save the quantized model and compare original vs quantized
12+
perplexity for each model.
13+
14+
## Requirements
15+
16+
Hydra is not part of OneComp's runtime dependencies. Install it via the
17+
`hydra` extra:
18+
19+
```bash
20+
# uv
21+
uv sync --extra <cuXXX> --extra hydra
22+
23+
# pip
24+
pip install "onecomp[hydra]"
25+
```
26+
27+
Replace `<cuXXX>` with the CUDA variant matching your environment
28+
(`cpu`, `cu118`, `cu121`, `cu124`, `cu126`, `cu128`, `cu130`).
29+
30+
## Usage
31+
32+
Specify a model via either `model_path` (local directory) or
33+
`model_id` (Hugging Face Hub). Exactly one of the two is required.
34+
35+
```bash
36+
# Local model
37+
python validate_gptq.py model_path=/path/to/model
38+
39+
# Hugging Face Hub
40+
python validate_gptq.py model_id=<HF Hub ID>
41+
```
42+
43+
### Hydra Overrides
44+
45+
Any field in [conf/validate.yaml](conf/validate.yaml) can be overridden
46+
on the command line, for example:
47+
48+
```bash
49+
python validate_gptq.py model_path=/path/to/model output_dir=outputs/custom
50+
```
51+
52+
### Outputs
53+
54+
For each run, Hydra changes into `output_dir` and the following are
55+
produced:
56+
57+
- `quantized/` - quantized model saved via `runner.save_quantized_model(...)`
58+
- standard Hydra logs (`.hydra/`, `*.log`)
59+
- stdout: original / quantized perplexity
60+
61+
## Validated Models
62+
63+
The validation set covers the following models:
64+
65+
- TinyLlama-1.1B (`TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T`)
66+
- gemma-4-E2B
67+
- Llama-2-7B
68+
- Llama-3-8B
69+
- Qwen3-8B
70+
71+
## Results
72+
73+
Perplexity is measured on `wikitext-2-raw-v1` (OneComp default).
74+
Quantizer is `GPTQ(wbits=4, groupsize=128)` with `qep=False` and
75+
`CalibrationConfig(max_length=512, num_calibration_samples=128)`.
76+
77+
| Model | Original PPL | Quantized PPL | Notes |
78+
|---|---:|---:|---|
79+
| TinyLlama-1.1B | 7.77 | 8.69 | OK |
80+
| gemma-4-E2B (base) | 25.99 | 35.03 | warn (see below) |
81+
| Llama-2-7B | 5.47 | 6.59 | OK |
82+
| Llama-3-8B | 6.14 | 27.74 | warn (see below) |
83+
| Qwen3-8B | 9.72 | 10.72 | OK |
84+
85+
### Notes on gemma-4-E2B and Llama-3-8B
86+
87+
Both models show a larger original-vs-quantized PPL gap than the other
88+
entries on this validation set:
89+
90+
- gemma-4-E2B: `25.99 -> 35.03` (≈35% relative increase)
91+
- Llama-3-8B: `6.14 -> 27.74` (≈4.5x increase)
92+
93+
Llama-2-7B (`+20%`), TinyLlama-1.1B (`+12%`), and Qwen3-8B (`+10%`) all
94+
land in a healthier range under the same setting. A likely contributor
95+
is the compact calibration config (`max_length=512`,
96+
`num_calibration_samples=128`), which may be a tight fit for these
97+
architectures (e.g. Llama-3-8B's 128k-vocab tokenizer).
98+
99+
Worth trying if the result needs to be improved:
100+
101+
- increase calibration to defaults (`max_length=2048`,
102+
`num_calibration_samples=512`),
103+
- enable QEP (`qep=True`) to leverage quantization-error propagation.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Model selection (specify exactly one of model_id or model_path)
2+
model_id: null # Hugging Face Hub ID (e.g. TinyLlama/TinyLlama-1.1B-...)
3+
model_path: null # Local path to a model directory
4+
5+
# Output directory (Hydra chdir's into this for each run)
6+
output_dir: outputs/${oc.env:SLURM_JOB_NAME,run}_${oc.env:SLURM_ARRAY_TASK_ID,0}
7+
8+
# Hydra
9+
hydra:
10+
run:
11+
dir: ${output_dir}
12+
job:
13+
chdir: true
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
3+
Model validation: GPTQ quantization (wbits=4, groupsize=128, qep=False)
4+
5+
Hydra entry point for validating OneComp's GPTQ quantizer across
6+
multiple models. The model is selected via either ``model_id`` (Hugging
7+
Face Hub) or ``model_path`` (local). Exactly one of the two must be
8+
provided; otherwise the script exits with ``ValueError``.
9+
10+
Copyright 2025-2026 Fujitsu Ltd.
11+
12+
Usage:
13+
python validate_gptq.py model_path=/path/to/model
14+
python validate_gptq.py model_id=TinyLlama/TinyLlama-1.1B-...
15+
16+
"""
17+
18+
import hydra
19+
from omegaconf import DictConfig, OmegaConf
20+
21+
from onecomp import (
22+
CalibrationConfig,
23+
GPTQ,
24+
ModelConfig,
25+
Runner,
26+
setup_logger,
27+
)
28+
29+
30+
@hydra.main(version_base=None, config_path="conf", config_name="validate")
31+
def main(cfg: DictConfig):
32+
setup_logger()
33+
print(OmegaConf.to_yaml(cfg))
34+
35+
if cfg.model_id is None and cfg.model_path is None:
36+
raise ValueError(
37+
"Either model_id or model_path must be provided "
38+
"(e.g. model_path=/path/to/model)"
39+
)
40+
if cfg.model_id is not None and cfg.model_path is not None:
41+
raise ValueError("Specify only one of model_id or model_path")
42+
43+
quantizer = GPTQ(wbits=4, groupsize=128)
44+
45+
runner = Runner(
46+
model_config=ModelConfig(
47+
model_id=cfg.model_id,
48+
path=cfg.model_path,
49+
device="cuda:0",
50+
),
51+
quantizer=quantizer,
52+
calibration_config=CalibrationConfig(
53+
max_length=512, num_calibration_samples=128
54+
),
55+
qep=False,
56+
)
57+
58+
runner.run()
59+
runner.save_quantized_model("./quantized")
60+
61+
original_ppl, _, quantized_ppl = runner.calculate_perplexity(
62+
original_model=True, dequantized_model=False, quantized_model=True
63+
)
64+
65+
print(f"Original model perplexity: {original_ppl}")
66+
print(f"Quantized model perplexity: {quantized_ppl}")
67+
68+
69+
if __name__ == "__main__":
70+
main()

0 commit comments

Comments
 (0)