PEFT
Safetensors
English
jinjieyuan commited on
Commit
e3526ec
1 Parent(s): 5bd7d7b

Create README.md

Browse files

Signed-off-by: jinjieyuan <[email protected]>

Files changed (1) hide show
  1. README.md +118 -0
README.md ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ ---
5
+
6
+ # Shears Model Card: shears-mpt-7b-50-gsm8k-super
7
+
8
+ The super-network fine-tuned on MPT-7B with GSM8K datasets using Shears.
9
+
10
+ The release of the super-network is to facilitate users to apply their own search algorithms and evaluation indicators to extract subnetworks suitable for their specific needs.
11
+
12
+ ## Model Details
13
+
14
+ ### Information
15
+
16
+ - **Model name:** shears-mpt-7b-50-gsm8k-super
17
+ - **Base model:** [mpt-7b](https://huggingface.co/mosaicml/mpt-7b)
18
+ - **Sparsity:** 50%
19
+ - **Subnetwork version:** Super-network
20
+ - **NNCF Configuration:** [nncf_shears_mpt_7b_sparsity50.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/gsm8k/nncf_shears_mpt_7b_sparsity50.json)
21
+
22
+ ### Adapter Configuration
23
+
24
+ - **LoRA rank:** 32
25
+ - **LoRA alpha:** 64
26
+ - **LoRA target modules:** q_proj, k_proj, v_proj, out_proj, up_proj, down_proj
27
+ - **LoRA rank search space:** [32, 24, 16] (for each LoRA module)
28
+
29
+ ### Training Hyperparameters
30
+
31
+ - **Batch size:** 16
32
+ - **Learning rate:** 3e-4
33
+ - **Epoch:** 5
34
+
35
+ ### Training and Evaluation
36
+
37
+ GSM8K dataset: [https://huggingface.co/datasets/gsm8k](https://huggingface.co/datasets/gsm8k)
38
+
39
+ ## How to use
40
+
41
+ Refer to the illustrative example provided in [load_and_explore_supernet.ipynb](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/search/load_and_explore_supernet.ipynb) for a comprehensive understanding. This notebook shows the direct loading of a Shears super-network and the extraction of diverse subnetworks from it.
42
+ This feature empowers users to employ their own search algorithms and evaluation metrics for the extraction of subnetworks customized to their specific requirements.
43
+
44
+ Moreover, the super-network is essentially the maximal subnetwork, and it can also be directly loaded:
45
+
46
+ ```python
47
+ import torch
48
+ from peft import PeftModel
49
+ from transformers import AutoModelForCausalLM
50
+ from transformers import AutoTokenizer
51
+
52
+ def generate_prompt(instruction):
53
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
54
+
55
+ ### Instruction:
56
+ {instruction}
57
+
58
+ ### Response:
59
+ """
60
+
61
+ base_model_path = "shears-mpt-7b-50-gsm8k-super/base_model"
62
+ adapter_model_path = "shears-mpt-7b-50-gsm8k-super/adapter_model"
63
+ base_model = AutoModelForCausalLM.from_pretrained(base_model_path)
64
+ model = PeftModel.from_pretrained(base_model, adapter_model_path)
65
+ model.eval()
66
+
67
+ non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
68
+ print(f"Number of all non-zero parameters: {non_zero_params}")
69
+
70
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
71
+ tokenizer.pad_token_id = 0
72
+
73
+ instruction = "Edgar eats 18 pretzels a day. If his brother eats 1/2 as many, how many does his brother eat in a week?"
74
+ prompt = generate_prompt(instruction)
75
+ inputs = tokenizer(prompt, return_tensors="pt")
76
+ input_ids = inputs["input_ids"].to(model.device)
77
+ with torch.no_grad():
78
+ generation_output = model.generate(
79
+ input_ids=input_ids,
80
+ return_dict_in_generate=True,
81
+ output_scores=True,
82
+ max_new_tokens=256,
83
+ use_cache=True,
84
+ num_beams=4,
85
+ )
86
+ s = generation_output.sequences[0]
87
+ output = tokenizer.decode(s)
88
+ print(output)
89
+
90
+ ```
91
+
92
+ ## Evaluation Results
93
+
94
+ Results of the heuristic sub-network discoverd from the super-network:
95
+
96
+ | Model | Sparsity | GSM8K Accuracy |
97
+ |-----------------------|-------------|-------|
98
+ | [**MPT-7B-Shears**](https://huggingface.co/IntelLabs/shears-mpt-7b-50-gsm8k-heuristic) | **50%** | 33.4 |
99
+
100
+ ## Model Sources
101
+
102
+ - **Repository:** [https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears)
103
+ - **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search]()
104
+
105
+ ## Citation
106
+
107
+ ```bash
108
+ @article{munoz2024shears,
109
+ title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
110
+ author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
111
+ journal={},
112
+ year={2024}
113
+ }
114
+ ```
115
+
116
+ ## License
117
+
118
+ Apache-2.0