PEFT
Safetensors
English
jinjieyuan commited on
Commit
724904c
·
verified ·
1 Parent(s): 35541ea

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +124 -124
README.md CHANGED
@@ -1,124 +1,124 @@
1
- ---
2
- language: en
3
- license: apache-2.0
4
- ---
5
-
6
- # Shears Model Card: shears-llama-7b-50-commonsense-super
7
-
8
- The super-adapter fine-tuned on sparsified LLaMA-7B with some commonsense reasoning 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-llama-7b-50-commonsense-super
17
- - **Base model:** [IntelLabs/Llama-1-7B-sparsity50](https://huggingface.co/IntelLabs/Llama-1-7B-sparsity50)
18
- - **Sparsity:** 50%
19
- - **Domain:** Commonsense
20
- - **Subnetwork version:** Super
21
- - **NNCF Configuration:** [nncf_shears_llama.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/unified_math/nncf_shears_llama.json)
22
-
23
- ### Adapter Configuration
24
-
25
- - **LoRA rank:** 32
26
- - **LoRA alpha:** 64
27
- - **LoRA target modules:** q_proj, k_proj, v_proj, up_proj, down_proj
28
- - **LoRA rank search space:** [32, 24, 16] (for each LoRA module)
29
-
30
- ### Training Hyperparameters
31
-
32
- - **Batch size:** 16
33
- - **Learning rate:** 3e-4
34
- - **Epoch:** 5
35
-
36
- ### Training Data
37
-
38
- Unified commonsense reasoning dataset: [commonsense_170k.json](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/ft-training_set/commonsense_170k.json).
39
-
40
- ### Evaluation Data
41
- [BoolQ](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/boolq/test.json), [PIQA](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/piqa/test.json), [SIQA](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/social_i_qa/test.json), [HellaSwag](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/hellaswag/test.json), [WinoGrande](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/winogrande/test.json), [ARC-e](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/ARC-Easy/test.json), [ARC-c](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/ARC-Challenge/test.json), [OBQA](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/openbookqa/test.json).
42
-
43
-
44
-
45
- ## How to use
46
-
47
- 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.
48
- This feature empowers users to employ their own search algorithms and evaluation metrics for the extraction of subnetworks customized to their specific requirements.
49
-
50
- Moreover, the super-network is essentially the maximal subnetwork, and it can also be directly loaded:
51
-
52
- ```python
53
- import torch
54
- from peft import PeftModel
55
- from transformers import AutoModelForCausalLM
56
- from transformers import AutoTokenizer
57
-
58
- def generate_prompt(instruction):
59
- return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
60
-
61
- ### Instruction:
62
- {instruction}
63
-
64
- ### Response:
65
- """
66
-
67
- base_model = AutoModelForCausalLM.from_pretrained("IntelLabs/Llama-1-7B-sparsity50")
68
- model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-llama-7b-50-commonsense-super")
69
- model.eval()
70
-
71
- non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
72
- print(f"Number of all non-zero parameters: {non_zero_params}")
73
-
74
- tokenizer = AutoTokenizer.from_pretrained("IntelLabs/Llama-1-7B-sparsity50")
75
-
76
- instruction = "Please choose the correct answer to the question: A cactus stem is used to store\n\nAnswer1: fruit "
77
- "Answer2: liquid Answer3: food Answer4: spines\n\nAnswer format: answer1/answer2/answer3/answer4"
78
- prompt = generate_prompt(instruction)
79
- inputs = tokenizer(prompt, return_tensors="pt")
80
- input_ids = inputs["input_ids"].to(model.device)
81
- with torch.no_grad():
82
- generation_output = model.generate(
83
- input_ids=input_ids,
84
- return_dict_in_generate=True,
85
- output_scores=True,
86
- max_new_tokens=256,
87
- use_cache=True,
88
- num_beams=4,
89
- )
90
- s = generation_output.sequences[0]
91
- output = tokenizer.decode(s)
92
- print(output)
93
-
94
- ```
95
-
96
- ## Evaluation Results
97
-
98
- Results of the heuristic sub-network discoverd from the super-network:
99
-
100
- | Model | Sparsity | BoolQ | PIQA | SIQA | HellaSwag | WinoG | ARC-e | ARC-c | OBQA | Average |
101
- |----------------------|-----------|---------|--------|--------|------------|--------|--------|---------|--------|----------|
102
- | ChatGPT | - | 73.1 | 85.4 | 68.5 | 78.5 | 66.1 | 89.8 | 79.9 | 74.8 | 77.0 |
103
- | LLaMA-7B-LoRA | - | 68.9 | 80.7 | 77.4 | 78.1 | 78.8 | 77.8 | 61.3 | 74.8 | 74.7 |
104
- | [**LLaMA-7B-Shears**](https://huggingface.co/IntelLabs/shears-llama-7b-50-commonsense-heuristic) | **50%** | 67.3 | 79.1 | 77.5 | 73.3 | 77.7 | 74.4 | 57.9 | 72.8 | 72.5 |
105
-
106
- ## Model Sources
107
-
108
- - **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)
109
- - **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search](https://arxiv.org/abs/2404.10934)
110
-
111
- ## Citation
112
-
113
- ```bash
114
- @article{munoz2024shears,
115
- title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
116
- author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
117
- journal={The 2024 Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL-2024)},
118
- year={2024}
119
- }
120
- ```
121
-
122
- ## License
123
-
124
- Apache-2.0
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ ---
5
+
6
+ # Shears Model Card: shears-llama-7b-50-commonsense-super-adapter
7
+
8
+ The super-adapter fine-tuned on sparsified LLaMA-7B with some commonsense reasoning 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-llama-7b-50-commonsense-super-adapter
17
+ - **Base model:** [IntelLabs/shears-llama-7b-50-base](https://huggingface.co/IntelLabs/shears-llama-7b-50-base)
18
+ - **Sparsity:** 50%
19
+ - **Domain:** Commonsense
20
+ - **Subnetwork version:** Super
21
+ - **NNCF Configuration:** [nncf_shears_llama.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/nncf_shears_llama.json)
22
+
23
+ ### Adapter Configuration
24
+
25
+ - **LoRA rank:** 32
26
+ - **LoRA alpha:** 64
27
+ - **LoRA target modules:** q_proj, k_proj, v_proj, up_proj, down_proj
28
+ - **LoRA rank search space:** [32, 24, 16] (for each LoRA module)
29
+
30
+ ### Training Hyperparameters
31
+
32
+ - **Batch size:** 16
33
+ - **Learning rate:** 3e-4
34
+ - **Epoch:** 5
35
+
36
+ ### Training Data
37
+
38
+ Unified commonsense reasoning dataset: [commonsense_170k.json](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/ft-training_set/commonsense_170k.json).
39
+
40
+ ### Evaluation Data
41
+ [BoolQ](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/boolq/test.json), [PIQA](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/piqa/test.json), [SIQA](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/social_i_qa/test.json), [HellaSwag](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/hellaswag/test.json), [WinoGrande](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/winogrande/test.json), [ARC-e](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/ARC-Easy/test.json), [ARC-c](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/ARC-Challenge/test.json), [OBQA](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/openbookqa/test.json).
42
+
43
+
44
+
45
+ ## How to use
46
+
47
+ 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.
48
+ This feature empowers users to employ their own search algorithms and evaluation metrics for the extraction of subnetworks customized to their specific requirements.
49
+
50
+ Moreover, the super-network is essentially the maximal subnetwork, and it can also be directly loaded:
51
+
52
+ ```python
53
+ import torch
54
+ from peft import PeftModel
55
+ from transformers import AutoModelForCausalLM
56
+ from transformers import AutoTokenizer
57
+
58
+ def generate_prompt(instruction):
59
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
60
+
61
+ ### Instruction:
62
+ {instruction}
63
+
64
+ ### Response:
65
+ """
66
+
67
+ base_model = AutoModelForCausalLM.from_pretrained("IntelLabs/shears-llama-7b-50-base")
68
+ model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-llama-7b-50-commonsense-super-adapter")
69
+ model.eval()
70
+
71
+ non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
72
+ print(f"Number of all non-zero parameters: {non_zero_params}")
73
+
74
+ tokenizer = AutoTokenizer.from_pretrained("IntelLabs/shears-llama-7b-50-base")
75
+
76
+ instruction = "Please choose the correct answer to the question: A cactus stem is used to store\n\nAnswer1: fruit "
77
+ "Answer2: liquid Answer3: food Answer4: spines\n\nAnswer format: answer1/answer2/answer3/answer4"
78
+ prompt = generate_prompt(instruction)
79
+ inputs = tokenizer(prompt, return_tensors="pt")
80
+ input_ids = inputs["input_ids"].to(model.device)
81
+ with torch.no_grad():
82
+ generation_output = model.generate(
83
+ input_ids=input_ids,
84
+ return_dict_in_generate=True,
85
+ output_scores=True,
86
+ max_new_tokens=256,
87
+ use_cache=True,
88
+ num_beams=4,
89
+ )
90
+ s = generation_output.sequences[0]
91
+ output = tokenizer.decode(s)
92
+ print(output)
93
+
94
+ ```
95
+
96
+ ## Evaluation Results
97
+
98
+ Results of the heuristic sub-network discoverd from the super-network:
99
+
100
+ | Model | Sparsity | BoolQ | PIQA | SIQA | HellaSwag | WinoG | ARC-e | ARC-c | OBQA | Average |
101
+ |----------------------|-----------|---------|--------|--------|------------|--------|--------|---------|--------|----------|
102
+ | ChatGPT | - | 73.1 | 85.4 | 68.5 | 78.5 | 66.1 | 89.8 | 79.9 | 74.8 | 77.0 |
103
+ | LLaMA-7B-LoRA | - | 68.9 | 80.7 | 77.4 | 78.1 | 78.8 | 77.8 | 61.3 | 74.8 | 74.7 |
104
+ | [**LLaMA-7B-Shears**](https://huggingface.co/IntelLabs/shears-llama-7b-50-commonsense-heuristic-adapter) | **50%** | 67.3 | 79.1 | 77.5 | 73.3 | 77.7 | 74.4 | 57.9 | 72.8 | 72.5 |
105
+
106
+ ## Model Sources
107
+
108
+ - **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)
109
+ - **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search](https://arxiv.org/abs/2404.10934)
110
+
111
+ ## Citation
112
+
113
+ ```bash
114
+ @article{munoz2024shears,
115
+ title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
116
+ author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
117
+ journal={The 2024 Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL-2024)},
118
+ year={2024}
119
+ }
120
+ ```
121
+
122
+ ## License
123
+
124
+ Apache-2.0