LoftQ commited on
Commit
a48d2b4
1 Parent(s): 3b1b201

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - 'quantization '
8
+ - lora
9
+ ---
10
+ # LoftQ Initialization
11
+
12
+ | [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) |
13
+
14
+ 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.
15
+
16
+ This model, `Mistral-7B-v0.1-4bit-32rank`, is obtained from [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1).
17
+ The backbone is under `LoftQ/Mistral-7B-v0.1-4bit-32rank` and LoRA adapters are under the `subfolder='loftq_init'`.
18
+
19
+ ## Model Info
20
+ ### Backbone
21
+ - Stored format: `torch.bfloat16`
22
+ - Size: ~ 14 GiB
23
+ - Loaded format: bitsandbytes nf4
24
+ - Size loaded on GPU: ~3.5 GiB
25
+
26
+ ### LoRA adapters
27
+ - rank: 32
28
+ - lora_alpha: 16
29
+ - target_modules: ["down_proj", "up_proj", "q_proj", "k_proj", "v_proj", "o_proj", "gate_proj"]
30
+
31
+ ## Usage
32
+
33
+ **Training.** Here's an example of loading this model and preparing for the LoRA fine-tuning.
34
+
35
+ ```python
36
+ import torch
37
+ from transformers import AutoModelForCausalLM, BitsAndBytesConfig
38
+ from peft import PeftModel
39
+
40
+ MODEL_ID = "LoftQ/Mistral-7B-v0.1-4bit-32rank"
41
+
42
+ base_model = AutoModelForCausalLM.from_pretrained(
43
+ MODEL_ID,
44
+ torch_dtype=torch.bfloat16, # you may change it with different models
45
+ quantization_config=BitsAndBytesConfig(
46
+ load_in_4bit=True,
47
+ bnb_4bit_compute_dtype=torch.bfloat16, # bfloat16 is recommended
48
+ bnb_4bit_use_double_quant=False,
49
+ bnb_4bit_quant_type='nf4',
50
+ ),
51
+ )
52
+ peft_model = PeftModel.from_pretrained(
53
+ base_model,
54
+ MODEL_ID,
55
+ subfolder="loftq_init",
56
+ is_trainable=True,
57
+ )
58
+
59
+ # Do training with peft_model ...
60
+ ```
61
+
62
+ See the full code at our [Github Repo]((https://github.com/yxli2123/LoftQ))
63
+
64
+
65
+ ## Citation
66
+
67
+ ```bibtex
68
+ @article{li2023loftq,
69
+ title={Loftq: Lora-fine-tuning-aware quantization for large language models},
70
+ author={Li, Yixiao and Yu, Yifan and Liang, Chen and He, Pengcheng and Karampatziakis, Nikos and Chen, Weizhu and Zhao, Tuo},
71
+ journal={arXiv preprint arXiv:2310.08659},
72
+ year={2023}
73
+ }
74
+ ```