File size: 1,955 Bytes
cba7046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c16204
cba7046
2c16204
cba7046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c5270
cba7046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
license: mit
language:
- en
pipeline_tag: text-generation
tags:
- 'quantization '
- lora
---
# LoftQ Initialization

| [Paper](https://arxiv.org/abs/2310.08659) | [Code](https://github.com/yxli2123/LoftQ) | [PEFT Example](https://github.com/huggingface/peft/tree/main/examples/loftq_finetuning) |

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, `LoftQ/Phi-3-mini-4k-instruct-4bit-64rank`, is obtained from [Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct). 
The backbone is under `LoftQ/Phi-3-mini-4k-instruct-4bit-64rank` and LoRA adapters are under the `subfolder='loftq_init'`.

## Model Info
### Backbone
- Stored format: nf4
- Size: ~ 2.5 GiB
- Loaded format: bitsandbytes nf4
- Size loaded on GPU: ~2.5 GiB

### LoRA adapters
- rank: 64
- lora_alpha: 16
- target_modules: ["qkv_proj", "o_proj", "up_gate_proj", "down_proj"]
- rank_pattern: {"qkv_proj": 192, "up_gate_proj": 128}

## 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-3-mini-4k-instruct-4bit-64rank"

base_model = AutoModelForCausalLM.from_pretrained(MODEL_ID, trust_remote_code=True)
peft_model = PeftModel.from_pretrained(
    base_model,
    MODEL_ID,
    subfolder="loftq_init",
    is_trainable=True,
)

# Do training with peft_model ...
```

See the full code at our [Github Repo]((https://github.com/yxli2123/LoftQ))


## 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}
}
```