LoftQ commited on
Commit
647f355
1 Parent(s): e3b8603

Create README.md

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