codewithdark-git/QuantLLM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI DownloadsPyPI - Version

QuantLLM is a Python library designed for efficient model quantization using the GGUF (GGML Universal Format) method. It provides a robust framework for converting and deploying large language models with minimal memory footprint and optimal performance. Key capabilities include:

  • Memory-efficient GGUF quantization with multiple precision options (2-bit to 8-bit)
  • Chunk-based processing for handling large models
  • Comprehensive benchmarking tools
  • Detailed progress tracking with memory statistics
  • Easy model export and deployment
FeatureDescription
βœ… Multiple GGUF TypesSupport for various GGUF quantization types (Q2_K to Q8_0) with different precision-size tradeoffs
βœ… Memory OptimizationChunk-based processing and CPU offloading for efficient handling of large models
βœ… Progress TrackingDetailed layer-wise progress with memory statistics and ETA
βœ… Benchmarking ToolsComprehensive benchmarking suite for performance evaluation
βœ… Hardware OptimizationAutomatic device selection and memory management
βœ… Easy DeploymentSimple conversion to GGUF format for deployment
βœ… Flexible ConfigurationCustomizable quantization parameters and processing options

Basic installation:

pip install quantllm

With GGUF support (recommended):

pip install quantllm[gguf]
from quantllm import QuantLLM
from transformers import AutoTokenizer

# Load tokenizer and prepare data
model_name = "facebook/opt-125m"
tokenizer = AutoTokenizer.from_pretrained(model_name)
calibration_text = ["Example text for calibration."] * 10
calibration_data = tokenizer(calibration_text, return_tensors="pt", padding=True)["input_ids"]

# Quantize model
quantized_model, benchmark_results = QuantLLM.quantize_from_pretrained(
    model_name_or_path=model_name,
    bits=4,                    # Quantization bits (2-8)
    group_size=32,            # Group size for quantization
    quant_type="Q4_K_M",      # GGUF quantization type
    calibration_data=calibration_data,
    benchmark=True,           # Run benchmarks
    benchmark_input_shape=(1, 32)
)

# Save and convert to GGUF
QuantLLM.save_quantized_model(model=quantized_model, output_path="quantized_model")
QuantLLM.convert_to_gguf(model=quantized_model, output_path="model.gguf")

For detailed usage examples and API documentation, please refer to our:

  • CPU: 4+ cores
  • RAM: 16GB+
  • Storage: 10GB+ free space
  • Python: 3.10+
  • CPU: 8+ cores
  • RAM: 32GB+
  • GPU: NVIDIA GPU with 8GB+ VRAM
  • CUDA: 11.7+
  • Storage: 20GB+ free space
TypeBitsDescriptionUse Case
Q2_K2Extreme compressionSize-critical deployment
Q3_K_S3Small sizeLimited storage
Q4_K_M4Balanced qualityGeneral use
Q5_K_M5Higher qualityQuality-sensitive tasks
Q8_08Best qualityAccuracy-critical tasks
QuantLLMPythonPyTorchTransformersCUDA
1.2.0β‰₯3.10β‰₯2.0.0β‰₯4.30.0β‰₯11.7
  • Support for more GGUF model architectures
  • Enhanced benchmarking capabilities
  • Multi-GPU processing support
  • Advanced memory optimization techniques
  • Integration with more deployment platforms
  • Custom quantization kernels

We welcome contributions! Please see our CONTRIBUTE.md for guidelines and setup instructions.

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

About

QuantLLM is a Python library designed for developers, researchers, and teams who want to fine-tune and deploy large language models (LLMs) efficiently using 4-bit and 8-bit quantization techniques.

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors 2

    •  
    •