Skip to main content

QuantSmith

Post-training quantization experiments with decisions you can inspect.

QuantSmith turns an FP32 ONNX model and representative inputs into a W8A8 QDQ graph. It also returns the plans behind that graph: which consumer edges were quantized, which layers were excluded, and which scales, zero points, or channel transforms were chosen. Use those decisions to investigate an accuracy drop, change one choice, and measure again on held-out data.

The aim is a research workflow you can reproduce and modify:

  1. Establish an FP32 baseline with your exported ONNX model.
  2. Replay representative calibration inputs for MinMax, Percentile, or SmoothQuant followed by fresh W8A8 calibration.
  3. Inspect the stage plans and use rules to select methods or exclude sensitive layers.
  4. Compare held-out results across the baseline and quantized graphs.

QuantSmith also includes GPTQv2 and operator-level QDrop-based reconstruction for experiments that spend additional calibration computation on weight choices. The methods are documented with their assumptions, numerical examples, and implementation limits.

Package name

Version 0.8.0 changes the distribution and Python import name from qraft to quantsmith. Replace qraft imports with quantsmith and QraftError with QuantSmithError. The qraft package on PyPI belongs to an unrelated project. Example report metadata now uses the quantsmith field, and example environment variables use the QUANTSMITH_ prefix.

Start with an experiment

Each example is a readable source walkthrough with model export, calibration, method selection, and held-out evaluation in its own main.py. Its README has the commands to run it.

Research question Example
How do methods behave on global or local causal attention? Transformer · Windowed Transformer
How do activation outliers affect image classification? ResNet-18 · MobileNetV2 · EfficientNet-B0
What is the smallest complete API example? ONNX projection
How do the methods apply beyond those models? Wine MLP · Character RNN
What does reconstruction change? Held-out reconstruction comparison

The models × quantization methods matrix links every MinMax, Percentile, and SmoothQuant walkthrough. These are experiments, including cases where quantization loses substantial accuracy. For example, a historical 256-image EfficientNet-B0 demonstration measured 75.00% FP32 top-1, 44.92% with MinMax, and 69.53% with Percentile. Those subset results illustrate why calibration choice matters; they are not accuracy guarantees for other data.

Quantize your ONNX model

For a model with a float32 input named features and representative rows in calibration.npy:

from collections.abc import Iterator, Mapping

import numpy as np
import onnx

from quantsmith.backends.onnx.pipeline import quantize
from quantsmith.config import QuantizationConfig
from quantsmith.domain import InputArray
from quantsmith.result import Err, Ok

features = np.load("calibration.npy", mmap_mode="r")


def samples() -> Iterator[Mapping[str, InputArray]]:
    """Replay representative inputs for every calibration pass."""
    for index in range(len(features)):
        yield {"features": np.asarray(features[index : index + 1], dtype=np.float32)}


config = QuantizationConfig(smoothquant=True)
outcome = quantize(onnx.load("model.onnx"), samples, config.stages())
match outcome:
    case Err(error):
        print(error.kind, error.operation, error.detail)
    case Ok(result):
        onnx.save(result.model, "model_w8a8.onnx")
        # result.plans records the decisions made at each stage.

Use the exact input names, shapes, and dtypes of your exported graph. The sample factory must replay the same inputs on each calibration pass; reserve different data for evaluation. QuantizationConfig() selects MinMax by default. smoothquant=True balances channels before collecting fresh quantization statistics. For histogram clipping, use PercentileConfig. To choose behavior per layer, compose rules with StaticW8A8, SmoothQuant, and Exclude.

What you can inspect and change

Experiment control Where to look
Calibration ranges and clipping MinMax and Percentile
Channel balancing and per-layer decisions Algorithm guides · Rules
Weight reconstruction GPTQv2 and QDrop
Replaying inputs and collecting bounded statistics Calibration
ONNX graph validation and QDQ lowering ONNX backend

Plans expose the chosen encodings and exclusions; examples save graphs, plans, reports, and held-out predictions or output errors under artifacts/. QuantSmith streams calibration samples and retains bounded statistics rather than caching the full dataset. Its planning algorithms can also be tested from supplied statistics without executing ONNX.

Scope and interpretation

QuantSmith currently targets FP32 ONNX graphs with constant-weight Conv, MatMul, and Gemm operators. It supports INT8 or UINT8 encodings, per-tensor activations, per-output-channel weights, and CPU ONNX Runtime calibration. SmoothQuant covers ungrouped Conv and matrix projections. Reconstruction has its own operator-specific limits.

QDQ insertion does not by itself establish lower latency or smaller files. Static quantization retains floating-point weight initializers; reconstruction also retains unused originals. Biases and terminal outputs remain floating point. Measure accuracy, latency, and artifact size on your own workload before drawing conclusions. GPU calibration, packed low-bit export, weight-only quantization, and automatic reconstruction blocks are outside the current scope.

Want to extend a method or reproduce a result? See CONTRIBUTION.md.

Metadata

Release files for quantsmith 0.8.0

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

Built distribution (wheel)

Table of built distributions (wheels) for quantsmith 0.8.0
File Interpreter ABI Platform
quantsmith-0.8.0-py3-none-any.whl Python 3 none any Details

Release files / quantsmith-0.8.0-py3-none-any.whl

Download URL quantsmith-0.8.0-py3-none-any.whl
Size 64.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36492e3ad4b7ee2813b6597c45aebae0298927a854492ee8e55766b67fa9fd46
BLAKE2b-256 checksum
How to use checksums
ca51e4987be8bb4bb3e68047ed1938bd6d218910f084ce6b7268f682e09180c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for quantsmith 0.8.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.8.0 This release

1 release file No 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