Metadata-Version: 2.5
Name: quantcheck
Version: 0.0.2
Summary: Find the cheapest quantized version of an open model that still passes your own tests.
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: fastapi>=0.165.0
Requires-Dist: huggingface-hub>=0.24
Requires-Dist: jinja2>=3.1
Requires-Dist: jsonschema>=4
Requires-Dist: keyring>=25.7.0
Requires-Dist: psutil>=5.9
Requires-Dist: pydantic>=2
Requires-Dist: pyyaml>=6
Requires-Dist: rich>=13
Requires-Dist: typer>=0.12
Requires-Dist: uvicorn>=0.54.0
Provides-Extra: dev
Requires-Dist: httpx>=0.27; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Provides-Extra: llamacpp
Requires-Dist: llama-cpp-python>=0.3; extra == 'llamacpp'
Provides-Extra: mlx
Requires-Dist: mlx-lm>=0.20; extra == 'mlx'
Description-Content-Type: text/markdown

# quantcheck

Find the smallest quantized version of an open model that still passes **your** tests.

> **Early preview (0.0.1).** This release reserves the name and shows where the project is going. Sign-in settings are not bundled yet, so the lab stops at the sign-in screen; a usable beta follows. Runs only on your Mac: prompts, answers and models never leave the machine.

A quantized model stores its numbers with fewer bits (8, 6, 4, 3). It is smaller and faster, but can quietly get worse.
quantcheck runs every version on your own prompts, with the same instructions, documents and tools your app sends, then tells you:

- which version is the smallest one that is still safe, with a statistical check, or "cannot tell yet";
- every answer that changed or failed, side by side with the reference;
- speed, time to first token, peak memory and file size per version.

## Quick start (about 2 minutes, plus model download)

Needs an Apple Silicon Mac (M1 or newer), Python 3.11+ and [uv](https://docs.astral.sh/uv/).

```bash
pip install "quantcheck[mlx]"     # add [llamacpp] for GGUF files
quantcheck hw                     # chip, memory, free disk
```

Sign in once (opens your browser; needs the sign-in settings, see Status below):

```bash
quantcheck login
```

Run the example (Qwen3-8B, 3 versions, downloads a few GB the first time):

```bash
quantcheck run examples/quantcheck.yaml
```

Or use the local lab, which runs only on your Mac:

```bash
quantcheck ui
```

Open `runs/<run-id>/report.html` in a browser. Rebuild it any time:

```bash
quantcheck report <run-id>
```

Everything is also saved to `runs/<run-id>/results.json`.

## Your own tests

`tests.jsonl` has one test per line. A first line with `"type": "set"` holds what your app sends with every question (instructions, tools). See [`examples/tests.jsonl`](examples/tests.jsonl): English, Hindi and Tamil prompts, a document-grounded answer, a tool call and an "I don't know" case.

```json
{"id": "hi-001", "prompt": "ऑर्डर कैंसल कैसे करें?", "checks": [{"type": "language", "value": "hi"}], "tags": ["hindi"]}
```

Checks (hard yes/no): `json`, `json_schema`, `regex`, `contains`, `not_contains`, `language`, `min_length`, `max_length`, `tool_call`, `grounded`, `refusal`.
Tools are never executed: quantcheck only reads the tool call the model writes and plays back the result you recorded.

How the score works: a failed check scores 0, otherwise a judge model scores 0 to 10 against the reference (the expected answer, or the largest version). The judge also runs on your Mac.

## What a report looks like

`report.html` is one file that opens offline. It shows the recommendation ("use 6-bit", or "not proven yet"), speed, memory and file size per version, quality by tag, and every answer that changed or failed, side by side with the reference. With fewer than 20 prompts quantcheck refuses to name a safe version; use 100 or more for real decisions.

## Status

Working: the local lab (`quantcheck ui`: sign in, start a test, watch progress, read reports), test loader, MLX and llama.cpp runners, checks, local judge, recommendation, terminal and HTML reports.
Sign-in (`quantcheck login`, `logout`, `whoami`) works with Google through a Supabase project (see `docs/decisions/001-auth-provider.md`). Token refresh and sign-out are tested with mocks only so far.
Not built yet: `judge: claude`, quantizing models yourself, GPU runners.

Known limits:

- The `language` check works by script (Devanagari, Tamil, Telugu, Bengali and more) and English. It cannot tell Hindi from Marathi, and does not support other Latin-script languages yet.
- llama.cpp peak memory is sampled from process memory: compare versions with each other, not with MLX numbers.
- Tool calls are read for Qwen/Hermes, Mistral and Llama 3 formats.

## Develop

```bash
uv sync --extra dev --extra mlx --extra llamacpp
uv run pytest -q            # fast tests, no model downloads
uv run pytest -m slow       # real tiny-model tests (downloads ~1 GB)
uv run ruff check . && uv run ruff format .
```

License: Apache-2.0.
