Skip to main content

cusum-watch

Decoding-time drift monitor for quantized LLMs. Teams running INT4/INT8 reasoning models in production need to catch generation failures (repetition collapse, degenerate looping) before they reach users. Raw token log-probability is the wrong monitoring signal for this - quantization shifts logprob magnitudes uniformly, making threshold-based monitors either too sensitive or too blind. cusum-watch instead monitors a quantization-robust observable: the shape of the top-k log-probability distribution (entropy ratio + margin ratio), which is invariant to the uniform additive shifts that quantization introduces. This observable feeds into a two-sided e-CUSUM detector that catches both entropy increases (incoherence) and entropy decreases (over-confident repetition).

Status: Functional monitoring pipeline with calibrated thresholds, Prometheus metrics, Grafana dashboard, and CLI. Current limitation: logprob-only mode (no hidden-state backend available). Version 0.2.0.

Install

pip install -e .

(Once published: pip install cusum-watch)

Quick Start

1. Calibrate

Run the full calibration pipeline against a GGUF model:

cusum-watch calibrate --model-path models/qwen2.5-1.5b-instruct-q4_k_m.gguf --output calibration.json

This generates calibration samples, fits a null distribution, and calibrates thresholds for both positive (entropy-spike) and negative (repetition-collapse) CUSUM directions. See python scripts/fetch_reference_model.py to download the GGUF.

2. Inspect calibration results

cusum-watch inspect calibration.json

Prints null model distribution, both thresholds, and empirical false-alarm rates.

3. Wire into litellm

from cusum_watch.metrics.server import MetricsRegistry, MetricsConfig
from cusum_watch.proxy.litellm_hook import CusumWatchLogger, MonitorConfig
from cusum_watch.stats.null_model import NullModel

# Load your calibrated null model (from calibration.json)
null_model = NullModel(distribution="norm", params={"loc": 0.5, "scale": 0.1}, fit_diagnostics={})

config = MonitorConfig(
    null_model_path="calibration.json",
    threshold_positive=1.5,
    threshold_negative=1.8,
    degrade_to_logprob_only=True,  # only supported mode
    alt_shift=0.002,
)
metrics = MetricsRegistry(MetricsConfig(model="my-model"))
logger = CusumWatchLogger(config, null_model, metrics=metrics)

4. Start metrics server

python -m cusum_watch.metrics.server
# Prometheus scrapes localhost:9090/metrics
# Import dashboards/cusum-watch.json into Grafana

Architecture

Token logprobs -> default_observable() -> StepObservable.combined
                                              |
                                     fit_null() -> NullModel
                                              |
                          calibrate_threshold() -> thresholds
                                              |
                     ECusum (positive) + ECusum (negative) -> CusumAlert
                                              |
                                MetricsRegistry -> /metrics (Prometheus)

The two-sided CUSUM catches failure modes that shift combined in opposite directions: entropy spike (combined increases) and repetition collapse (combined decreases). Each direction is independently calibrated.

Limitations

  • Logprob-only mode: No CPU-only backend exposes hidden states. The ObservableFn interface supports pluggable backends, but only default_observable exists today.
  • i.i.d. bootstrap vs sequential data: Calibration uses i.i.d. bootstrap resampling, which discards token-to-token correlation. On sequential data, the positive-direction FAR diverged 2.6x from bootstrap prediction (0.230 sequential vs 0.090 bootstrap); the negative direction was 0.9x. See M12's adversarial validation for details.
  • In-memory metrics: Prometheus metrics reset on proxy restart. Not suitable for historical trending without external persistence.
  • CPU-only reference model: Calibration requires a GGUF model file. The default (Qwen2.5-1.5B-Instruct Q4_K_M) needs ~1.2 GB RAM.

Documentation

Development

pip install -e ".[dev]"
pytest tests/ -v -m "not slow"       # fast tests (~30s)
pytest tests/ -v -m slow             # slow tests (weekly/manual)
pytest tests/ -v                     # all tests

See CONTRIBUTING.md for details on CI structure, API compat checking, and model fetching.

Metadata

Release files for cusum-watch 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cusum-watch 0.2.0
File Size Uploaded Provenance Actions
cusum_watch-0.2.0.tar.gz 44.9 kB With provenance Details for cusum_watch-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cusum-watch 0.2.0
File Interpreter ABI Platform Actions
cusum_watch-0.2.0-py3-none-any.whl Python 3 none any Details for cusum_watch-0.2.0-py3-none-any.whl

Total release size: 67.1 kB

Release files / cusum_watch-0.2.0.tar.gz

Download URL cusum_watch-0.2.0.tar.gz
Size 44.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6dcd6df00bddaca306d8840c71b14287d6b2f3cd99f6335fbd382b21b5c321dc
BLAKE2b-256 checksum
How to use checksums
a0ad3896a719cf4e15004c2b443c335196ff9b6d6aaa270b726992c1ef718a30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.

Transparency log

Release files / cusum_watch-0.2.0-py3-none-any.whl

Download URL cusum_watch-0.2.0-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b34bb73832a9efac762ee1ecbcd78bc9546661d55437f44a7877c4ad0f93a7f8
BLAKE2b-256 checksum
How to use checksums
60c529b3d0d839091bd210bc2399fdaa640f2a73a81fe40b544696e382177138
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.

Transparency log

Security for cusum-watch 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cusum_watch-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page