A comprehensive collection of Jupyter notebooks for converting and quantizing large language models using Apple's MLX framework, optimized for Apple Silicon devices.
- 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
- Hardware: macOS with Apple Silicon (M1/M2/M3/M4)
- Python: 3.8 or higher
- Storage: 50GB+ free space for large models
- Clone the repository:
git clone https://github.com/cs2764/mlx-quantization.git
cd mlx-quantization- Install dependencies:
pip install -r requirements.txt- Launch Jupyter:
jupyter lab| 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 |
| 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 |
Each notebook follows this standardized pattern:
- Environment Setup - Dependency installation and MLX verification
- Model Configuration - Set up directories and parameters
- Model Download - Fetch original model from Hugging Face
- Conversion/Quantization - Apply selected quantization method
- Validation - Test converted model functionality
- Performance Analysis - Compare speed and quality metrics
- Optional Upload - Push to Hugging Face Hub
- Cleanup - Remove temporary files
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
- Choose your quantization method based on your requirements
- Open the corresponding notebook in Jupyter Lab
- Follow the step-by-step instructions in each cell
- Monitor the conversion process and review results
- Test the quantized model before deployment
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
python -m mlx_lm.convert --hf-path <source> --mlx-path <target>python -m mlx_lm.awq --model <model> --mlx-path <output> --bits 4python -m mlx_lm.dwq --model <model> --mlx-path <output> --bits 4python -m mlx_lm.dynamic_quant --model <model> --mlx-path <output> --target-bpw 4.0- AWQ models require dequantization before MLX conversion (
--dequantizeflag) - 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
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly on Apple Silicon
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Apple MLX Team for the excellent framework
- Hugging Face for model hosting and tools
- The open-source ML community
- 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