Skip to main content

XSlim is an offline quantization tools based on PPQ

Project description

XSlim

中文版 | English

Version License Python

XSlim is a Post-Training Quantization (PTQ) tool developed by SpacemiT. It integrates chip-optimized quantization strategies and provides a unified interface for ONNX model quantization via JSON configuration files.


Features

  • INT8 / FP16 / Dynamic Quantization – multiple precision levels for different deployment scenarios
  • JSON-driven configuration – simple, declarative quantization setup
  • Python API & CLI – use as a library or from the command line
  • Custom preprocessing – plug in your own preprocessing functions
  • ONNX-based workflow – built on the ONNX ecosystem

Installation

pip install xslim

Or install from source:

git clone https://github.com/spacemit-com/xslim.git
cd xslim
pip install -r requirements.txt

Quick Start

Python API

import xslim

# Using a JSON config file
xslim.quantize_onnx_model("config.json")

# Using a dict
config = {
    "model_parameters": {
        "onnx_model": "model.onnx",
        "working_dir": "./output"
    },
    "calibration_parameters": {
        "input_parameters": [{
            "mean_value": [123.675, 116.28, 103.53],
            "std_value": [58.395, 57.12, 57.375],
            "color_format": "rgb",
            "preprocess_file": "PT_IMAGENET",
            "data_list_path": "./calib_img_list.txt"
        }]
    }
}
xslim.quantize_onnx_model(config)

# You can also pass the model path and output path directly
xslim.quantize_onnx_model("config.json", "input.onnx", "output.onnx")

Command Line

# INT8 quantization with a JSON config
python -m xslim --config config.json

# Specify input and output model paths
python -m xslim -c config.json -i input.onnx -o output.onnx

# Dynamic quantization (no config file needed)
python -m xslim -i input.onnx -o output.onnx --dynq

# FP16 conversion (no config file needed)
python -m xslim -i input.onnx -o output.onnx --fp16

# Convert the default ai.onnx opset to a target version
python -m xslim -i input.onnx -o output.onnx --opset 20

# ONNX simplification only (no config file needed)
python -m xslim -i input.onnx -o output.onnx

Documentation

Samples

See the samples directory for ready-to-run examples covering ResNet-18, MobileNet V3, BERT, and more.

Changelog

For a full list of changes, see the Releases page.

Version Highlights
2.0.13 Current development version
2.0.12 Latest release; complete README changelog/release metadata, add accuracy-tuning docs and README links, introduce the xslim-accuracy-tuning GitHub skill, add YOLO truncation guidance, and rename input parameters for consistency
2.0.11 Fix Pad/missing-input handling, add Or/Einsum/Selu support, normalize Conv/ConvTranspose kernel shapes, and raise minimum Python to 3.9
2.0.10 Align release metadata, improve CI/test coverage, normalize missing default ONNX opset before dynamic quantization, and refine shape inference handling
2.0.9 Add documentation, preserve tensor dtype metadata during FP16 conversion, and restore compatibility with onnxslim 0.1.87
2.0.8 Improve packaging/CI, add torch executor operator coverage, add PyPI publish workflow, and centralize version metadata
2.0.7 Fix FP16 conversion bug on complex models
2.0.6 Fix metadata props deletion; default CLI behavior changed to model simplification (use --dynq for dynamic quantization)

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xslim-2.0.14.tar.gz (271.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xslim-2.0.14-py3-none-any.whl (302.1 kB view details)

Uploaded Python 3

File details

Details for the file xslim-2.0.14.tar.gz.

File metadata

  • Download URL: xslim-2.0.14.tar.gz
  • Upload date:
  • Size: 271.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xslim-2.0.14.tar.gz
Algorithm Hash digest
SHA256 6ec6175ca3c56b442d838c898736e7f6e389a9837ed9743cac334154ce9e8828
MD5 a37d3a048aba3f7ca2e4e832c9454b2d
BLAKE2b-256 feb6c56e6b39081e995f0011306fcae236034714041616f6d8624a55d0fea2e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for xslim-2.0.14.tar.gz:

Publisher: publish.yml on spacemit-com/xslim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xslim-2.0.14-py3-none-any.whl.

File metadata

  • Download URL: xslim-2.0.14-py3-none-any.whl
  • Upload date:
  • Size: 302.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xslim-2.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 6eae8b647233d0bc7b834ca7b5c3ff8a8cbafef3f6b085de1b12a9982d5e5790
MD5 2fb5e4e89b9832dd9428169945c5ed9c
BLAKE2b-256 70e8d3152214b3b7696d3677d3bfa5017b22438cb90bdc1bc6df2e45b19a2252

See more details on using hashes here.

Provenance

The following attestation bundles were made for xslim-2.0.14-py3-none-any.whl:

Publisher: publish.yml on spacemit-com/xslim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page