Skip to content

Commit 995ea70

Browse files
committed
docs: add phase-1 quantization hardening gate
1 parent 6376e3d commit 995ea70

4 files changed

Lines changed: 116 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ See [docs/api-overview.md](docs/api-overview.md) for the full surface described
207207
- [docs/python-api.md](docs/python-api.md) & [docs/python-cookbook.md](docs/python-cookbook.md) — Python recipes.
208208
- [docs/torch.md](docs/torch.md) — PyTorch integration, `t81.torch`, and `t81.nn`.
209209
- [docs/references/cli-usage.md](docs/references/cli-usage.md) — CLI workflows for convert/gguf/qat.
210+
- [docs/quantization-hardening.md](docs/quantization-hardening.md) — Phase 1 hardening checklist and reproducible validation lanes.
210211

211212
### Specs & design
212213

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ From here: `t8.nn.Linear` for drop-in layers, `t8.convert`/`t8.gguf` for scripte
6868
- **GPU backends**[`docs/gpu.md`](gpu.md) explains the CUDA/ROCm build flags and tensor metadata routing.
6969
- **API overview**[`docs/api-overview.md`](api-overview.md) summarizes the numeric containers and helpers exposed via `<t81/t81lib.hpp>`.
7070
- **Tests & benchmarks**[`tests/`](../tests/) documents the unit/property coverage while [`bench/`](../bench/) shows throughput patterns.
71+
- **Phase 1 hardening checklist**[`docs/quantization-hardening.md`](quantization-hardening.md) defines the arithmetic/quantization stabilization gates and reproducible validation flow.
7172
- **Docs sitemap** — the [`docs/diagrams/docs-sitemap.mermaid.md`](diagrams/docs-sitemap.mermaid.md) mind map visualizes the content hierarchy referenced on this page.
7273

7374
## Stay aligned

docs/quantization-hardening.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Quantization and Arithmetic Hardening
2+
3+
Roadmap linkage:
4+
- `t81-roadmap#2`
5+
- `t81-roadmap/PHASE1_STABILIZATION_MATRIX.md` (`P1-S2`)
6+
7+
This document is the Phase 1 hardening checklist for `t81lib`.
8+
9+
## Hardening Checklist
10+
11+
- [x] Define a reproducible core arithmetic validation lane (C++ build + unit tests).
12+
- [x] Define a reproducible quantization validation lane (Python tests with explicit deps).
13+
- [x] Add one command entry point that runs both lanes in a consistent order.
14+
- [x] Require changed quantization claims to include benchmark artifact references.
15+
- [x] Route contract-impacting changes back to roadmap tracking.
16+
17+
## Reproducible Validation Paths
18+
19+
### Lane A: Core arithmetic (required)
20+
21+
Runs deterministic C++ checks through CMake/CTest:
22+
23+
```bash
24+
scripts/validate_quantization_hardening.sh
25+
```
26+
27+
### Lane B: Python quantization surface (optional but required for Python/API changes)
28+
29+
```bash
30+
python3 -m venv .venv
31+
source .venv/bin/activate
32+
pip install ".[torch]"
33+
scripts/validate_quantization_hardening.sh --with-python
34+
```
35+
36+
## Benchmark Artifact Rule
37+
38+
If a change alters quantization behavior or performance claims, include:
39+
40+
1. Command used (for example `scripts/ternary_quantization_benchmark.py` args).
41+
2. Output artifact path (`benchmarks/*.csv` or `benchmarks/*.json`).
42+
3. Before/after summary in PR or issue notes.
43+
44+
## Contract/Governance Rule
45+
46+
When quantization behavior changes impact cross-repo assumptions, open or update linked tracking in:
47+
48+
1. `t81-roadmap` (Phase 1 tracker),
49+
2. downstream contract consumers as needed (`t81-python`, `t81-lang`).
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
BUILD_DIR="${BUILD_DIR:-build-hardening}"
6+
WITH_PYTHON=0
7+
FULL=0
8+
9+
usage() {
10+
cat <<'EOF'
11+
Usage: scripts/validate_quantization_hardening.sh [--with-python] [--full]
12+
13+
Runs the Phase 1 hardening validation lanes for t81lib:
14+
1) C++ arithmetic/core lane (required)
15+
2) Python quantization lane (optional, enabled with --with-python)
16+
Default C++ lane excludes the long-running fuzz target (`bigint_bitops_fuzz`).
17+
Use --full to include it.
18+
EOF
19+
}
20+
21+
while [[ $# -gt 0 ]]; do
22+
case "$1" in
23+
--with-python)
24+
WITH_PYTHON=1
25+
shift
26+
;;
27+
--full)
28+
FULL=1
29+
shift
30+
;;
31+
-h|--help)
32+
usage
33+
exit 0
34+
;;
35+
*)
36+
echo "Unknown argument: $1" >&2
37+
usage >&2
38+
exit 1
39+
;;
40+
esac
41+
done
42+
43+
echo "[hardening] lane A: C++ core arithmetic/tests"
44+
cmake -S "$ROOT_DIR" -B "$ROOT_DIR/$BUILD_DIR" -DT81LIB_BUILD_TESTS=ON
45+
cmake --build "$ROOT_DIR/$BUILD_DIR" --parallel
46+
if [[ "$FULL" -eq 1 ]]; then
47+
ctest --test-dir "$ROOT_DIR/$BUILD_DIR" --output-on-failure
48+
else
49+
ctest --test-dir "$ROOT_DIR/$BUILD_DIR" -E "bigint_bitops_fuzz" --output-on-failure
50+
fi
51+
52+
if [[ "$WITH_PYTHON" -eq 1 ]]; then
53+
echo "[hardening] lane B: Python quantization/tests"
54+
if ! python3 -c "import numpy" >/dev/null 2>&1; then
55+
echo "Missing numpy. Install Python deps first (for example: pip install \".[torch]\")." >&2
56+
exit 1
57+
fi
58+
if ! python3 -c "import t81lib" >/dev/null 2>&1; then
59+
echo "Missing importable t81lib module. Install package first (for example: pip install \".[torch]\")." >&2
60+
exit 1
61+
fi
62+
(cd "$ROOT_DIR" && PYTHONPATH="$ROOT_DIR/python:$ROOT_DIR/src:${PYTHONPATH:-}" pytest -q tests/python/test_bindings.py tests/python/test_torch_ternary.py)
63+
fi
64+
65+
echo "[hardening] all selected lanes passed"

0 commit comments

Comments
 (0)