Small library to quantize/dequantize TensorFlow models using PyTorch CUDA kernels.
- Python: 3.13.13 (haven't tested on any other)
- CUDA Toolkit: >=12.8
- Python Dependencies: All required packages are listed in
requirements.txt
pip install -r requirements.txtpip install uni-quant-cudafrom uniquant import quantize, dequantize, dequantize_savequantize(model_path, quant_directory="", quant_name="", pack_size=32, quant_size=4, overwrite=False)
Quantizes a TensorFlow or XGBoost model.
Arguments:
model_path(str): Path to the model to quantize (with extension)quant_directory(str): Directory path to save the quantized modelquant_name(str): Filename for the quantized modelpack_size(int): Number of weights in one quantization batch (must be divisible by 2)quant_size(int): Number of bits per weight (available: 4 or 8)overwrite(bool): Whether to overwrite existing file
Dequantizes a model and returns it.
Arguments:
quant_path(str): Path to the .uniq file to dequantizeliteral(bool): Whether weights should be unscaledbalanced(bool): Whether weights should be balanced around 0
Dequantizes a model, saves it, and returns it.
Arguments:
quant_path(str): Path to the .uniq file to dequantizemodel_directory(str): Directory path to save the dequantized modelmodel_name(str): Filename for the dequantized modeloverwrite(bool): Whether to overwrite existing file
- This package compiles CUDA kernels at runtime using
torch.utils.cpp_extension.load_inline. - Installing and using the CUDA compilation requires a compatible CUDA toolkit on the target machine (tested with >=12.8).