Skip to content

Commit e93bab3

Browse files
committed
Merge branch 'lab/precommit' into 'export/v1-2-0'
Add pre-commit hooks for local development See merge request onecomp/onecomp-lab!75
2 parents 12ac698 + 3457fb0 commit e93bab3

147 files changed

Lines changed: 623 additions & 539 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: https://github.com/pycqa/isort
3+
rev: 6.0.1
4+
hooks:
5+
- id: isort
6+
7+
- repo: https://github.com/psf/black
8+
rev: 25.1.0
9+
hooks:
10+
- id: black
11+
args: [--line-length=99]
12+
13+
- repo: local
14+
hooks:
15+
- id: no-japanese
16+
name: Forbid Japanese characters
17+
language: system
18+
entry: bash scripts/run_venv_python_for_precommit.sh scripts/check_no_japanese.py
19+
exclude: '\.md$|\.gitignore$'
20+
types: [text]
21+
22+
- id: copyright-header
23+
name: Check Fujitsu copyright header
24+
language: system
25+
entry: bash scripts/run_venv_python_for_precommit.sh scripts/check_copyright_header.py
26+
types: [python]
27+
exclude: '(__init__|__main__)\.py$|^tests/|^benchmark/'
28+
29+
- id: no-email-address
30+
name: Forbid email addresses
31+
language: pygrep
32+
entry: '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
33+
types: [python]

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [v1.2.0] 2026-06-04 (WIP)
44

5+
### for Developer: pre-commit
6+
7+
- Added `.pre-commit-config.yaml` with `black`, `isort`, and local hooks (`no-japanese`, `copyright-header`, `no-email-address`); install with `uv sync --extra dev` then `pre-commit install` (see README)
58

69
## [v1.1.1] 2026-05-21
710

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ The `--extra cu128` option installs the CUDA-enabled version of PyTorch (along w
130130
Replace `cu128` with the appropriate variant for your environment: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, `cu128`, or `cu130`.
131131
PyTorch will be automatically downloaded by `uv`, so you do not need to install it beforehand.
132132

133-
Adding `--extra dev` installs development tools (black, pytest, pylint).
133+
Adding `--extra dev` installs development tools (black, pre-commit, pytest, pylint).
134134
Adding `--extra visualize` installs matplotlib for visualization features.
135135
Adding `--extra hydra` installs `hydra-core` for the example scripts and `model_validation/` runners that use Hydra-based configuration.
136136

@@ -179,6 +179,40 @@ pip install -e ".[dev]"
179179

180180
Replace `cu128` with the appropriate variant for your environment: `cpu`, `cu118`, `cu121`, `cu124`, `cu126`, `cu128`, or `cu130`.
181181

182+
#### Pre-commit
183+
184+
After installing development dependencies (`--extra dev` with uv, or `pip install -e ".[dev]"` with pip), register the Git hooks once:
185+
186+
```bash
187+
pre-commit install
188+
```
189+
190+
On every `git commit`, the following checks run automatically:
191+
192+
| Hook | Description |
193+
|------|-------------|
194+
| **black** | Code formatting (line length 99) |
195+
| **isort** | Import sorting |
196+
| **no-japanese** | Forbid Japanese characters in text files (`.md` and `.gitignore` are excluded) |
197+
| **copyright-header** | Verify the Fujitsu copyright header in Python files |
198+
| **no-email-address** | Forbid email addresses in Python files |
199+
200+
Common commands:
201+
202+
```bash
203+
# Run hooks on staged files only
204+
pre-commit run
205+
206+
# Run hooks on all files (useful after first install or config changes)
207+
pre-commit run --all-files
208+
209+
# Run a specific hook
210+
pre-commit run black --all-files
211+
212+
# With uv (no activation needed)
213+
uv run pre-commit run --all-files
214+
```
215+
182216

183217
### Building Documentation Locally
184218

benchmark/llama3-8b-gptq/quant_benchmark.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import hydra
1616
from omegaconf import DictConfig, OmegaConf
1717

18-
from onecomp import CalibrationConfig, GPTQ, ModelConfig, Runner
18+
from onecomp import GPTQ, CalibrationConfig, ModelConfig, Runner
1919

2020

2121
def create_quantizers(cfg: DictConfig):
@@ -80,9 +80,7 @@ def main(cfg: DictConfig):
8080

8181
# Save results
8282
for q in quantizers:
83-
runner.save_quantization_statistics(
84-
f"quantization_statistics_{q.name}.json", quantizer=q
85-
)
83+
runner.save_quantization_statistics(f"quantization_statistics_{q.name}.json", quantizer=q)
8684

8785
# Perplexity evaluation
8886
if cfg.calc_ppl:

benchmark/llama3-8b-jointq/quant_benchmark.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import hydra
1616
from omegaconf import DictConfig, OmegaConf
1717

18-
from onecomp import CalibrationConfig, GPTQ, JointQ, ModelConfig, Runner
18+
from onecomp import GPTQ, CalibrationConfig, JointQ, ModelConfig, Runner
1919

2020

2121
def create_quantizers(cfg: DictConfig):
@@ -93,9 +93,7 @@ def main(cfg: DictConfig):
9393
runner.run()
9494

9595
for q in quantizers:
96-
runner.save_quantization_statistics(
97-
f"quantization_statistics_{q.name}.json", quantizer=q
98-
)
96+
runner.save_quantization_statistics(f"quantization_statistics_{q.name}.json", quantizer=q)
9997

10098
if cfg.calc_ppl:
10199
runner.benchmark_perplexity(

benchmark/llama3-8b-lpcd-gptq/quant_benchmark.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
import hydra
2828
from omegaconf import DictConfig, OmegaConf
2929

30-
from onecomp import GPTQ, ModelConfig, QEPConfig, LPCDConfig, Runner
30+
from onecomp import GPTQ, LPCDConfig, ModelConfig, QEPConfig, Runner
3131

3232

3333
def create_quantizer(cfg: DictConfig, task_id: int):
3434
"""Create a single GPTQ quantizer for the given task_id."""
35-
combinations = list(itertools.product(cfg.gptq.bits, ['none', 'res', 'qk', 'vo', 'ud', 'all']))
35+
combinations = list(itertools.product(cfg.gptq.bits, ["none", "res", "qk", "vo", "ud", "all"]))
3636

3737
if task_id < 0 or task_id >= len(combinations):
3838
raise ValueError(
@@ -43,7 +43,7 @@ def create_quantizer(cfg: DictConfig, task_id: int):
4343
bits, submodule = combinations[task_id]
4444

4545
return GPTQ(
46-
wbits=bits,
46+
wbits=bits,
4747
groupsize=128,
4848
name=f"lpcd_{submodule}_{bits}bit",
4949
)
@@ -57,11 +57,7 @@ def main(cfg: DictConfig):
5757

5858
print(f"task_id={cfg.task_id} -> {quantizer.name}")
5959

60-
model_config = ModelConfig(
61-
path=cfg.model_path,
62-
dtype="bfloat16",
63-
device=cfg.model_device
64-
)
60+
model_config = ModelConfig(path=cfg.model_path, dtype="bfloat16", device=cfg.model_device)
6561

6662
qep_config = QEPConfig(
6763
percdamp=cfg.qep.percdamp,
@@ -103,9 +99,7 @@ def main(cfg: DictConfig):
10399

104100
runner.run()
105101

106-
runner.save_quantization_statistics(
107-
f"quantization_statistics_{quantizer.name}.json"
108-
)
102+
runner.save_quantization_statistics(f"quantization_statistics_{quantizer.name}.json")
109103

110104
# Perplexity evaluation
111105
if cfg.calc_ppl:

benchmark/llama3-8b-qep-gptq/quant_benchmark.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import hydra
2222
from omegaconf import DictConfig, OmegaConf
2323

24-
from onecomp import CalibrationConfig, GPTQ, ModelConfig, QEPConfig, Runner
24+
from onecomp import GPTQ, CalibrationConfig, ModelConfig, QEPConfig, Runner
2525

2626

2727
def create_quantizer(cfg: DictConfig, task_id: int):
@@ -86,9 +86,7 @@ def main(cfg: DictConfig):
8686

8787
runner.run()
8888

89-
runner.save_quantization_statistics(
90-
f"quantization_statistics_{quantizer.name}.json"
91-
)
89+
runner.save_quantization_statistics(f"quantization_statistics_{quantizer.name}.json")
9290

9391
# Perplexity evaluation
9492
if cfg.calc_ppl:

benchmark/llama3-8b-various/quant_benchmark.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@
1212
import hydra
1313
from omegaconf import DictConfig, OmegaConf
1414

15-
from onecomp import GPTQ, JointQ, CalibrationConfig, ModelConfig, Runner, ARB, CQ, DBF, QBB, QUIP, RTN, Onebit
15+
from onecomp import (
16+
ARB,
17+
CQ,
18+
DBF,
19+
GPTQ,
20+
QBB,
21+
QUIP,
22+
RTN,
23+
CalibrationConfig,
24+
JointQ,
25+
ModelConfig,
26+
Onebit,
27+
Runner,
28+
)
1629

1730

1831
def create_quantizers():
@@ -57,9 +70,7 @@ def main(cfg: DictConfig):
5770
runner.run()
5871

5972
for q in quantizers:
60-
runner.save_quantization_statistics(
61-
f"quantization_statistics_{q.name}.json", quantizer=q
62-
)
73+
runner.save_quantization_statistics(f"quantization_statistics_{q.name}.json", quantizer=q)
6374

6475
if cfg.calc_ppl:
6576
runner.benchmark_perplexity(

benchmark/qwen3-14b-gptq/quant_benchmark.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import hydra
1616
from omegaconf import DictConfig, OmegaConf
1717

18-
from onecomp import CalibrationConfig, GPTQ, ModelConfig, Runner
18+
from onecomp import GPTQ, CalibrationConfig, ModelConfig, Runner
1919

2020

2121
def create_quantizers(cfg: DictConfig):
@@ -75,9 +75,7 @@ def main(cfg: DictConfig):
7575
runner.run()
7676

7777
for q in quantizers:
78-
runner.save_quantization_statistics(
79-
f"quantization_statistics_{q.name}.json", quantizer=q
80-
)
78+
runner.save_quantization_statistics(f"quantization_statistics_{q.name}.json", quantizer=q)
8179

8280
if cfg.calc_ppl:
8381
runner.benchmark_perplexity(

benchmark/qwen3-14b-jointq/quant_benchmark.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import hydra
1616
from omegaconf import DictConfig, OmegaConf
1717

18-
from onecomp import CalibrationConfig, GPTQ, JointQ, ModelConfig, Runner
18+
from onecomp import GPTQ, CalibrationConfig, JointQ, ModelConfig, Runner
1919

2020

2121
def create_quantizers(cfg: DictConfig):
@@ -93,9 +93,7 @@ def main(cfg: DictConfig):
9393
runner.run()
9494

9595
for q in quantizers:
96-
runner.save_quantization_statistics(
97-
f"quantization_statistics_{q.name}.json", quantizer=q
98-
)
96+
runner.save_quantization_statistics(f"quantization_statistics_{q.name}.json", quantizer=q)
9997

10098
if cfg.calc_ppl:
10199
runner.benchmark_perplexity(

0 commit comments

Comments
 (0)