PEFT
Safetensors
English
jinjieyuan commited on
Commit
d2daf06
·
verified ·
1 Parent(s): 3861d7d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +115 -115
README.md CHANGED
@@ -1,115 +1,115 @@
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-adapter fine-tuned on sparsified 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:** [IntelLabs/MPT-7B-sparsity50](https://huggingface.co/IntelLabs/MPT-7B-sparsity50)
18
- - **Sparsity:** 50%
19
- - **Subnetwork version:** Super
20
- - **NNCF Configuration:** [nncf_shears_mpt.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/gsm8k/nncf_shears_mpt.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 = AutoModelForCausalLM.from_pretrained("IntelLabs/MPT-7B-sparsity50", trust_remote_code=True)
62
- model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-mpt-7b-50-gsm8k-super")
63
- model.eval()
64
-
65
- non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
66
- print(f"Number of all non-zero parameters: {non_zero_params}")
67
-
68
- tokenizer = AutoTokenizer.from_pretrained("IntelLabs/MPT-7B-sparsity50", trust_remote_code=True)
69
-
70
- instruction = "Edgar eats 18 pretzels a day. If his brother eats 1/2 as many, how many does his brother eat in a week?"
71
- prompt = generate_prompt(instruction)
72
- inputs = tokenizer(prompt, return_tensors="pt")
73
- input_ids = inputs["input_ids"].to(model.device)
74
- with torch.no_grad():
75
- generation_output = model.generate(
76
- input_ids=input_ids,
77
- return_dict_in_generate=True,
78
- output_scores=True,
79
- max_new_tokens=256,
80
- use_cache=True,
81
- num_beams=4,
82
- )
83
- s = generation_output.sequences[0]
84
- output = tokenizer.decode(s)
85
- print(output)
86
-
87
- ```
88
-
89
- ## Evaluation Results
90
-
91
- Results of the heuristic sub-network discoverd from the super-network:
92
-
93
- | Model | Sparsity | GSM8K Accuracy |
94
- |-----------------------|-------------|-------|
95
- | [**MPT-7B-Shears**](https://huggingface.co/IntelLabs/shears-mpt-7b-50-gsm8k-heuristic) | **50%** | 33.4 |
96
-
97
- ## Model Sources
98
-
99
- - **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)
100
- - **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search](https://arxiv.org/abs/2404.10934)
101
-
102
- ## Citation
103
-
104
- ```bash
105
- @article{munoz2024shears,
106
- title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
107
- author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
108
- journal={The 2024 Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL-2024)},
109
- year={2024}
110
- }
111
- ```
112
-
113
- ## License
114
-
115
- Apache-2.0
 
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-adapter fine-tuned on sparsified [MPT-7B](https://huggingface.co/mosaicml/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:** [IntelLabs/shears-mpt-7b-50-base](https://huggingface.co/IntelLabs/shears-mpt-7b-50-base)
18
+ - **Sparsity:** 50%
19
+ - **Subnetwork version:** Super
20
+ - **NNCF Configuration:** [nncf_shears_mpt.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/gsm8k/nncf_shears_mpt.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 = AutoModelForCausalLM.from_pretrained("IntelLabs/shears-mpt-7b-50-base", trust_remote_code=True)
62
+ model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-mpt-7b-50-gsm8k-super")
63
+ model.eval()
64
+
65
+ non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
66
+ print(f"Number of all non-zero parameters: {non_zero_params}")
67
+
68
+ tokenizer = AutoTokenizer.from_pretrained("IntelLabs/shears-mpt-7b-50-base", trust_remote_code=True)
69
+
70
+ instruction = "Edgar eats 18 pretzels a day. If his brother eats 1/2 as many, how many does his brother eat in a week?"
71
+ prompt = generate_prompt(instruction)
72
+ inputs = tokenizer(prompt, return_tensors="pt")
73
+ input_ids = inputs["input_ids"].to(model.device)
74
+ with torch.no_grad():
75
+ generation_output = model.generate(
76
+ input_ids=input_ids,
77
+ return_dict_in_generate=True,
78
+ output_scores=True,
79
+ max_new_tokens=256,
80
+ use_cache=True,
81
+ num_beams=4,
82
+ )
83
+ s = generation_output.sequences[0]
84
+ output = tokenizer.decode(s)
85
+ print(output)
86
+
87
+ ```
88
+
89
+ ## Evaluation Results
90
+
91
+ Results of the heuristic sub-network discoverd from the super-network:
92
+
93
+ | Model | Sparsity | GSM8K Accuracy |
94
+ |-----------------------|-------------|-------|
95
+ | [**MPT-7B-Shears**](https://huggingface.co/IntelLabs/shears-mpt-7b-50-gsm8k-heuristic) | **50%** | 33.4 |
96
+
97
+ ## Model Sources
98
+
99
+ - **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)
100
+ - **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search](https://arxiv.org/abs/2404.10934)
101
+
102
+ ## Citation
103
+
104
+ ```bash
105
+ @article{munoz2024shears,
106
+ title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
107
+ author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
108
+ journal={The 2024 Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL-2024)},
109
+ year={2024}
110
+ }
111
+ ```
112
+
113
+ ## License
114
+
115
+ Apache-2.0