Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.2%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Basic Info
  • Host: GitHub
  • Owner: DDobrzycki
  • License: other
  • Language: Python
  • Default Branch: main
  • Size: 397 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created almost 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

QuantizeWithSA

Welcome to our PTQ repository, featuring a flexible quantization tool utilizing the Simulated Annealing algorithm. This tool empowers users to quantize their desired models with fixed-point precision, optimizing performance while preserving accuracy. Customize simulations, convergence steps, and search ranges for fractional bits, ensuring tailored quantization results. Control degradation thresholds and convergence guidance through adjustable hyperparameters for fine-tuning. Explore our repository and unlock efficient model compression with ease.

Table of Contents

Installation

Using pip

  1. Clone the repository: sh git clone https://github.com/DDobrzycki/QuantizeWithSA.git cd QuantizeWithSA

  2. Create a virtual environment (optional but recommended): sh python -m venv QuantizeWithSA source QuantizeWithSA/bin/activate # On Windows use `venv\Scripts\activate`

  3. Install the required packages: sh pip install -r requirements.txt

Using conda

  1. Clone the repository: sh git clone https://github.com/DDobrzycki/QuantizeWithSA.git cd QuantizeWithSA

  2. Create a conda environment from the provided environment file: sh conda env create -f environment.yml

  3. Activate the conda environment: sh conda activate QuantizeWithSA

After completing these steps, the required dependencies will be installed, and you can start using the PTQ quantizer.

Usage

To display the help message and see all available options, run the following command: bash python3 main.py --help

Example Output

When you run the help command, you will see an output like this: ```console usage: main.py [-h] --modelname {cnnmnist,convnet_js,custom} [--numbersimulations NUMBERSIMULATIONS] [--maxsteps MAXSTEPS] [--minfracbits MINFRACBITS] [--maxfracbits MAXFRACBITS] [--maxdegradation MAXDEGRADATION] [--alpha ALPHA] [--beta BETA] [--gamma GAMMA] [--seed SEED] [--plots PLOTS]

Cuantize the desired model employing fixed point precision employing the simulated annealing algorithm

options: -h, --help show this help message and exit --modelname {cnnmnist,convnetjs,custom}, -m {cnnmnist,convnetjs,custom} Model to cuantize. If custom, it must be implemented first. --numbersimulations NUMBERSIMULATIONS, -ns NUMBERSIMULATIONS Nº of simulations. Set > 1 if want multiple cuantization results. --maxsteps MAXSTEPS, -ms MAXSTEPS Maximum number of steps of Simulated Annealing convergence algorithm. --minfracbits MINFRACBITS, -minb MINFRACBITS Lower search range when simulating the quantification of the fractional part of the parameters. --maxfracbits MAXFRACBITS, -maxb MAXFRACBITS Upper search range when simulating the quantification of the fractional part of the parameters. --maxdegradation MAXDEGRADATION, -md MAXDEGRADATION Maximum degradation accepeted on models accuracy. --alpha ALPHA, -a ALPHA Related with the importance of the lower bound. --beta BETA, -b BETA Related with the importance of the average nº of bits employed for the cuantization. --gamma GAMMA, -g GAMMA Related with the importance of diference between the cuantized model accuracy. --seed SEED, -s SEED Seed for global determinism. Helps with replicating experiments but may slow down execution. Default is None. --plots PLOTS Generates and saves plots of cost function convergence, as well as the evolution of the accuracy and importance of hyperparameters along the steps. ```

To run the project, use the following command: bash python3 main.py --model_name {cnn_mnist,convnet_js,custom}

Examples

Example 1: Quantizing the cnn_mnist Model

CNN architecture: alt text

bash python3 main.py --model_name cnn_mnist --number_simulations 1 --max_degradation 2 --max_steps 100 --seed 42 --plots True

Generated Plots: alt text

Contributing

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature-name.
  3. Make your changes.
  4. Push your branch: git push develop feature-name.
  5. Create a pull request.

License

Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)

You are free to: - Share — copy and redistribute the material in any medium or format - Adapt — remix, transform, and build upon the material

Under the following terms: - Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - Non-Commercial — You may not use the material for commercial purposes.

No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

See the LICENSE file for more details.

Owner

  • Login: DDobrzycki
  • Kind: user

Citation (CITATION.cff)

cff-version: 1.2.0
title: "QuantizeWithSA: PTQ Quantizer using Simulated Annealing for Variable Fractional Bits Allocation"
message: "If you use this PTQ quantizer in your research, please cite it using the following metadata."
type: software
authors:
  - family-names: "Dobrzycki"
    given-names: "Andrzej Daniel"
    orcid: "https://orcid.org/0009-0005-9756-4623"

repository-code: "https://github.com/DDobrzycki/QuantizeWithSA.git"
license: CC
version: "1.0"
year: 2024

GitHub Events

Total
Last Year

Dependencies

requirements.txt pypi
  • fxpmath ==0.4.9
  • matplotlib ==3.8.0
  • numpy ==1.23.5
  • scikit_learn ==1.3.0
  • seaborn ==0.12.2
  • tensorflow ==2.15.0.post1
environment.yml pypi
  • fxpmath ==0.4.9
  • tensorflow ==2.15.0