A collection of utilities to train and quantize 1-layer MLP weights and input data.
Important: make sure anaconda or miniconda is installed in your system.
Create a conda environment with Python 3.9+ and install the required dependencies:
conda create --prefix=./venv python=3.9
conda activate ./venv
pip install -r requirements.txtWe provide two scripts to bootstrap the training and quantization of both model weights and input data.
- First, we will train a lightweight 1-layer MLP on the Breast Cancer Wisconsin dataset with:
./scripts/train.shAfter training is finished, a checkpoint will be saved at checkpoint/MLP.json.
- Then, we will export the trained model to .onnx, perform static uint8 quantization with calibration and save both quantized model weights/bias and data input with:
./scripts/quantize.shAfter quantization is finished, you will find three new .onnx files in the checkpoint directory:
- MLP.onnx: this is the onnx exported model
- MLP_quant_preproc.onnx: this is the preprocessed onnx model prior to quantization
- MLP_quant.onnx: this is the statically quantized model
Additionally, two .json files with quantized model weights/bias and data input are saved to data/json/model.json and data/json/quantizedData.json, respectively.