Model Description
The original Phi-2 model runs on 16-bit precision (Float16) and consumes a lot of memory. To make it highly efficient and runnable on free-tier cloud GPUs (like Google Colab T4) or local machines with limited VRAM, this model has been compressed to 4-bit using NormalFloat4 (NF4) quantization.
Key Highlights & Comparison:
- Base Model:
microsoft/phi-2
- Quantization Tech: 4-bit NF4 (
bitsandbytes)
- PEFT Framework: LoRA Adapter added for efficient fine-tuning/saving configuration.
- Memory Footprint Optimization:
- Original Model Size: ~5.56 GB (Float16)
- Quantized Model Size: ~1.78 GB (4-bit)
- Size Reduction: ~68% lower VRAM usage with minimal drop in response quality!
How It Was Made
- Optimization: Loaded the model using
BitsAndBytesConfig with load_in_4bit=True and bnb_4bit_compute_dtype=torch.float16.
- LoRA Integration: Prepared the model for k-bit training and attached a
LoraConfig targeting the standard query/value projection layers (q_proj, v_proj).
- Saving: Saved the lightweight PEFT adapter weights (
adapter_model.safetensors) and tokenizer configuration.
Intended Use
This repository is perfect for anyone looking to experiment with lightweight text generation or perform Parameter-Efficient Fine-Tuning (PEFT) on top of a 4-bit quantized version of Phi-2.