PEFT
Safetensors
English
jinjieyuan commited on
Commit
2b176f4
·
1 Parent(s): 7d4bd9e

Create README.md

Browse files

Signed-off-by: jinjieyuan <jinjie.yuan@intel.com>

Files changed (1) hide show
  1. README.md +127 -0
README.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-network fine-tuned on 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:** [LLaMA-7b](https://huggingface.co/yahma/llama-7b-hf)
18
+ - **Sparsity:** 50%
19
+ - **Domain:** Commonsense
20
+ - **Subnetwork version:** Super-network
21
+ - **NNCF Configuration:** [nncf_shears_llama_7b_sparsity50.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/unified_commonsense/nncf_shears_llama_7b_sparsity50.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, gate_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:** 3
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_path = "shears-llama-7b-50-commonsense-super/base_model"
68
+ adapter_model_path = "shears-llama-7b-50-commonsense-super/adapter_model"
69
+ base_model = AutoModelForCausalLM.from_pretrained(base_model_path)
70
+ model = PeftModel.from_pretrained(base_model, adapter_model_path)
71
+ model.eval()
72
+
73
+ non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
74
+ print(f"Number of all non-zero parameters: {non_zero_params}")
75
+
76
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
77
+ tokenizer.pad_token_id = 0
78
+
79
+ instruction = "Please choose the correct answer to the question: A cactus stem is used to store\n\nAnswer1: fruit "
80
+ "Answer2: liquid Answer3: food Answer4: spines\n\nAnswer format: answer1/answer2/answer3/answer4"
81
+ prompt = generate_prompt(instruction)
82
+ inputs = tokenizer(prompt, return_tensors="pt")
83
+ input_ids = inputs["input_ids"].to(model.device)
84
+ with torch.no_grad():
85
+ generation_output = model.generate(
86
+ input_ids=input_ids,
87
+ return_dict_in_generate=True,
88
+ output_scores=True,
89
+ max_new_tokens=256,
90
+ use_cache=True,
91
+ num_beams=4,
92
+ )
93
+ s = generation_output.sequences[0]
94
+ output = tokenizer.decode(s)
95
+ print(output)
96
+
97
+ ```
98
+
99
+ ## Evaluation Results
100
+
101
+ Results of the heuristic sub-network discoverd from the super-network:
102
+
103
+ | Model | Sparsity | BoolQ | PIQA | SIQA | HellaSwag | WinoG | ARC-e | ARC-c | OBQA | Average |
104
+ |----------------------|-----------|---------|--------|--------|------------|--------|--------|---------|--------|----------|
105
+ | ChatGPT | - | 73.1 | 85.4 | 68.5 | 78.5 | 66.1 | 89.8 | 79.9 | 74.8 | 77.0 |
106
+ | LLaMA-7B-LoRA | - | 68.9 | 80.7 | 77.4 | 78.1 | 78.8 | 77.8 | 61.3 | 74.8 | 74.7 |
107
+ | [**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 |
108
+
109
+ ## Model Sources
110
+
111
+ - **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)
112
+ - **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search]()
113
+
114
+ ## Citation
115
+
116
+ ```bash
117
+ @article{munoz2024shears,
118
+ title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
119
+ author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
120
+ journal={},
121
+ year={2024}
122
+ }
123
+ ```
124
+
125
+ ## License
126
+
127
+ Apache-2.0