Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Repository files navigation

MLX Model Quantization Toolkit

A comprehensive collection of Jupyter notebooks for converting and quantizing large language models using Apple's MLX framework, optimized for Apple Silicon devices.

πŸš€ Features

  • Universal Model Conversion: Convert any Hugging Face model to MLX format
  • Multiple Quantization Methods: Support for AWQ, DWQ, and Dynamic Quantization
  • Apple Silicon Optimized: Built specifically for M1/M2/M3/M4 devices
  • Automated Workflows: Complete pipeline from download to deployment
  • Performance Testing: Built-in benchmarking and validation tools

πŸ“‹ Requirements

  • Hardware: macOS with Apple Silicon (M1/M2/M3/M4)
  • Python: 3.8 or higher
  • Storage: 50GB+ free space for large models

πŸ›  Installation

  1. Clone the repository:
git clone https://github.com/cs2764/mlx-quantization.git
cd mlx-quantization
  1. Install dependencies:
pip install -r requirements.txt
  1. Launch Jupyter:
jupyter lab

πŸ“š Notebooks Overview

Core Notebooks

Notebook Description Use Case
universal_mlx_converter.ipynb Universal converter for any HF model General model conversion
awq_quantization.ipynb Activation-aware Weight Quantization High-quality 4-bit quantization
dwq_quantization.ipynb Distilled Weight Quantization Fast quantization with good quality
dynamic_quantization.ipynb Dynamic mixed-precision quantization Optimal size/quality balance

Quantization Methods Comparison

Method Speed Quality Size Reduction Best For
AWQ Medium High ~75% Production deployment
DWQ Fast Good ~70% Quick prototyping
Dynamic Slow Highest Variable Research/experimentation

πŸ”„ Common Workflow

Each notebook follows this standardized pattern:

  1. Environment Setup - Dependency installation and MLX verification
  2. Model Configuration - Set up directories and parameters
  3. Model Download - Fetch original model from Hugging Face
  4. Conversion/Quantization - Apply selected quantization method
  5. Validation - Test converted model functionality
  6. Performance Analysis - Compare speed and quality metrics
  7. Optional Upload - Push to Hugging Face Hub
  8. Cleanup - Remove temporary files

πŸ“ Directory Structure

mlx-quantization/
β”œβ”€β”€ models/                          # Model storage
β”‚   β”œβ”€β”€ <model_name>/               # Original models
β”‚   └── <model_name>_<method>_<bits>/ # Quantized outputs
β”œβ”€β”€ sensitivities/                   # Layer analysis files
β”œβ”€β”€ *.ipynb                         # Conversion notebooks
β”œβ”€β”€ requirements.txt                # Dependencies
└── README.md                       # This file

πŸš€ Quick Start

  1. Choose your quantization method based on your requirements
  2. Open the corresponding notebook in Jupyter Lab
  3. Follow the step-by-step instructions in each cell
  4. Monitor the conversion process and review results
  5. Test the quantized model before deployment

πŸ“Š Performance Benchmarks

Typical results on Apple M2 Pro:

  • Model Size Reduction: 60-80% smaller than original
  • Inference Speed: 2-4x faster on Apple Silicon
  • Quality Retention: 95-99% of original performance
  • Memory Usage: 50-75% reduction

πŸ”§ MLX Commands Reference

Basic Conversion

python -m mlx_lm.convert --hf-path <source> --mlx-path <target>

AWQ Quantization

python -m mlx_lm.awq --model <model> --mlx-path <output> --bits 4

DWQ Quantization

python -m mlx_lm.dwq --model <model> --mlx-path <output> --bits 4

Dynamic Quantization

python -m mlx_lm.dynamic_quant --model <model> --mlx-path <output> --target-bpw 4.0

⚠️ Important Notes

  • AWQ models require dequantization before MLX conversion (--dequantize flag)
  • Use absolute paths - relative paths may cause issues
  • Large models need significant storage - ensure adequate disk space
  • Test converted models before production deployment
  • Conversion time varies based on model size and method

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly on Apple Silicon
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Apple MLX Team for the excellent framework
  • Hugging Face for model hosting and tools
  • The open-source ML community

πŸ“ž Support

  • Issues: Report bugs and request features via GitHub Issues
  • Discussions: Join community discussions in GitHub Discussions
  • Documentation: Refer to individual notebook markdown cells

Version: 1.0.0
Last Updated: 2025-01-30
Compatibility: Apple Silicon (M1/M2/M3/M4) + macOS

Star History

Star History Chart

About

MLX Model Quantization Toolkit - Comprehensive collection of Jupyter notebooks for converting and quantizing large language models using Apple's MLX framework, optimized for Apple Silicon devices.

Resources

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages