CoolFace
Modelpublic

LoftQ/phi-2-4bit-64rank

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes32downloads
Model Card

LoftQ Initialization

| Paper | Code | PEFT Example |

LoftQ (LoRA-fine-tuning-aware Quantization) provides a quantized backbone Q and LoRA adapters A and B, given a full-precision pre-trained weight W.

This model, phi-2-4bit-64rank, is obtained from phi-2. The backbone is under LoftQ/phi-2-4bit-64rank and LoRA adapters are under the subfolder='loftq_init'.

Model Info

Backbone

  • —Stored format: torch.float16
  • —Size: ~ 5.5 GiB
  • —Loaded format: bitsandbytes nf4
  • —Size loaded on GPU: ~1.4 GiB

LoRA adapters

  • —rank: 64
  • —lora_alpha: 16
  • —targetmodules: ["qproj", "kproj", "vproj", "dense", "fc1", "fc2"]

Usage

Training Here's an example of loading this model and preparing for the LoRA fine-tuning.

python
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel

MODEL_ID = "LoftQ/phi-2-4bit-64rank"

base_model = AutoModelForCausalLM.from_pretrained(
    MODEL_ID, 
    torch_dtype=torch.float32,  # you may change it with different models
    quantization_config=BitsAndBytesConfig(
        load_in_4bit=True,
        bnb_4bit_compute_dtype=torch.float32,  # float32 is tested and veryfied
        bnb_4bit_use_double_quant=False,
        bnb_4bit_quant_type='nf4',
    ),
)
peft_model = PeftModel.from_pretrained(
    base_model,
    MODEL_ID,
    subfolder="loftq_init",
    is_trainable=True,
)

# Do training with peft_model ...

Experiment Results

We have conducted experiments on supervised fine-tuning of GSM8K.

ModelBitsRankLoRA InitialGSM8K
Phi-216-Full model fine-tuning66.8±1.2
Phi-21664Gaussian + 0 (LoRA)64.8±0.5
Phi-2464Gaussian + 0 (QLoRA)60.2±0.6
Phi-2464LoftQ64.1±0.7

Inference Here is an example code for inference after the model has been fine-tuned on GSM8K.

python
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel

MODEL_ID = "LoftQ/phi-2-4bit-64rank"

base_model = AutoModelForCausalLM.from_pretrained(
    MODEL_ID, 
    torch_dtype=torch.float32,  # you may change it with different models
    quantization_config=BitsAndBytesConfig(
        load_in_4bit=True,
        bnb_4bit_compute_dtype=torch.float32,  # float32 is tested and veryfied
        bnb_4bit_use_double_quant=False,
        bnb_4bit_quant_type='nf4',
    ),
)
peft_model = PeftModel.from_pretrained(
    base_model,
    MODEL_ID,
    subfolder="gsm8k",
    is_trainable=True,
)

# Do inference with peft_model ...

See the full code at our Github Repo)

Citation

bibtex
@article{li2023loftq,
  title={Loftq: Lora-fine-tuning-aware quantization for large language models},
  author={Li, Yixiao and Yu, Yifan and Liang, Chen and He, Pengcheng and Karampatziakis, Nikos and Chen, Weizhu and Zhao, Tuo},
  journal={arXiv preprint arXiv:2310.08659},
  year={2023}
}