quantize-rs 0.9.0

Neural network quantization toolkit for ONNX models
Documentation
name: CI

on:
  push:
    branches: [master, main]
  pull_request:
    branches: [master, main]

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      # Run tests with default features and with --all-features so the
      # mmap and safetensors-input code paths are exercised in CI.
      - name: Run tests (default features)
        run: cargo test --all
      - name: Run tests (all features)
        run: cargo test --all-features --all
      - name: Run tests (no default features, lib only)
        run: cargo test --no-default-features --lib

  # Verify the crate still compiles on its declared MSRV (Cargo.toml `rust-version`).
  # The toolchain is read FROM Cargo.toml so the declared MSRV and the version
  # tested here cannot drift apart: a dependency bump that raises the real floor
  # (e.g. a future `time` release) fails this job instead of going unnoticed.
  msrv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Read MSRV from Cargo.toml
        id: msrv
        run: |
          msrv=$(grep -m1 '^rust-version' Cargo.toml | sed -E 's/.*"([0-9.]+)".*/\1/')
          echo "Detected MSRV: $msrv"
          echo "version=$msrv" >> "$GITHUB_OUTPUT"
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ steps.msrv.outputs.version }}
      - uses: Swatinem/rust-cache@v2
      # `check` (lib + bins, no test targets) keeps the MSRV honest without
      # pulling dev-dependencies, whose MSRV doesn't affect consumers.
      - run: cargo check --all-features

  clippy:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      # Lint lib, bins, tests, examples, and benches with all features so
      # test-only lints are caught (recent versions of clippy added several
      # such lints; not linting tests masked them in prior CI runs).
      # Runs on all three OSes so platform-specific code paths (atomic
      # save's std::fs::rename, Windows path handling, mmap) get linted.
      - name: Clippy (all features, all targets)
        run: cargo clippy --all-features --all-targets -- -D warnings

  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - name: Check formatting
        run: cargo fmt -- --check

  doc:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      # Treat rustdoc warnings (e.g. broken intra-doc links) as errors so they
      # never land in master.
      - name: Build docs (deny warnings)
        env:
          RUSTDOCFLAGS: -D warnings
        run: cargo doc --no-deps --all-features

  bench-compile:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Verify benchmarks compile
        run: cargo bench --all-features --no-run

  ort-smoke:
    # End-to-end check that quantized models actually load and run in ONNX
    # Runtime — the structural Rust tests can't catch ORT-level regressions.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Build quantize-rs binary
        # Debug build — the smoke test only needs the binary to run, not to be
        # fast, and a debug build avoids the slow release LTO step.
        run: cargo build --bin quantize-rs
      - name: Install ONNX Runtime
        run: python -m pip install --upgrade pip onnx onnxruntime numpy
      - name: ORT execution smoke test
        run: python eval/ort_smoke_test.py --binary ./target/debug/quantize-rs