Skip to main content

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
  • Expanded ONNX operator coverage – run Graphwise Analysis and quantization on models that use common arithmetic, activation, comparison, reduction, dropout, and opset-24 Pad patterns
  • Automatic YOLO decode fusion – fuse supported YOLO decode subgraphs into a single spacemit_functions.YoloDecode node
  • ONNX Function-aware export – preserve embedded FunctionProto definitions and emit required custom-domain imports automatically
  • GridSample compatibility – map ONNX linear and cubic modes to the names expected by the PyTorch executor
  • Output shape preservation – recover original dimensions that remain unknown after ONNX shape inference
  • ONNX-based workflow – built on the ONNX ecosystem

Installation

python -m pip install xslim

Or install from source:

git clone https://github.com/spacemit-com/xslim.git
cd xslim
python -m pip install .

For local development, use an editable install:

python -m pip install -e .

Build metadata is defined in pyproject.toml, and the import package lives under the standard src/ layout. To build source and wheel distributions locally:

python -m pip install --upgrade build
python -m build

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

# Installed CLI entry point
xslim --config config.json

# Module entry point also remains available
python -m xslim --config config.json

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

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

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

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

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

For config-free dynamic quantization and FP16 conversion, you can exclude operators with comma-separated names or types:

xslim -i input.onnx -o output.onnx --dynq --ignore_op_types Softmax,LayerNormalization
xslim -i input.onnx -o output.onnx --fp16 --ignore_op_names /model/head/MatMul

Static INT8 quantization expects a floating-point input model. If the model already contains QuantizeLinear or DequantizeLinear, XSlim stops with a clear error instead of quantizing an already-quantized graph again.

For supported YOLO exports, no extra switch is required: XSlim will try to fuse decode-heavy post-processing into spacemit_functions.YoloDecode during simplification and keep the corresponding ONNX FunctionProto in the exported model.

Documentation

Samples

See the samples directory for ready-to-run examples covering ResNet-18, MobileNet V3, BERT, and more. YOLO-specific usage notes are documented in the examples and accuracy-tuning guides.

Changelog

For a full list of published versions, see the Releases page.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for branch naming, PR titles, code style and verification requirements, then open an issue or submit a pull request.

License

This project is licensed under the Apache License 2.0.

Metadata

Release files for xslim 2.1.3

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

Source distribution (sdist)

Source distribution for xslim 2.1.3
File Size Uploaded Provenance Actions
xslim-2.1.3.tar.gz 338.4 kB With provenance Details for xslim-2.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 666.8 kB

Release files / xslim-2.1.3.tar.gz

Download URL xslim-2.1.3.tar.gz
Size 338.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4bb282a8ab87d03caa0bd530259b8c7d9e20c861e323f7c55391ca278985ef3b
BLAKE2b-256 checksum
How to use checksums
916234498649e17d47386abff69c37df154a7dd9348ef720166cb0cef65c3d12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 1, 2026.

Transparency log

Release files / xslim-2.1.3-py3-none-any.whl

Download URL xslim-2.1.3-py3-none-any.whl
Size 328.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
719595bf9e01bde812d3a00727e1d7d12a32ff526d8e4b3caad7450e38310abc
BLAKE2b-256 checksum
How to use checksums
53c0689ffa8ace54c36456f5347ec9394222ce558f86618f9170f742fa87e573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 1, 2026.

Transparency log

Security for xslim 2.1.3

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 xslim-2.1.3.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 Dec 1, 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.

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