PEFT
Safetensors
English
jinjieyuan commited on
Commit
0e1ee4a
·
1 Parent(s): 3dcd03c

Create README.md

Browse files

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

Files changed (1) hide show
  1. README.md +126 -0
README.md ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ ---
5
+
6
+ # Shears Model Card: shears-llama-13b-50-math-super
7
+
8
+ The super-network fine-tuned on LLaMA-13B with some math 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-13b-50-math-super
17
+ - **Base model:** [LLaMA-13b](https://huggingface.co/yahma/llama-13b-hf)
18
+ - **Sparsity:** 50%
19
+ - **Domain:** Math
20
+ - **Subnetwork version:** Super-network
21
+ - **NNCF Configuration:** [nncf_shears_llama_13b_sparsity50.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/unified_math/nncf_shears_llama_13b_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, 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 math reasoning dataset: [math_10k.json](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/ft-training_set/math_10k.json) (collected with the training sets of GSM8K, MAWPS, and AQuA).
39
+
40
+ ### Evaluation Data
41
+ [GSM8K](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/gsm8k/test.json), [AQuA](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/AQuA/test.json), [MAWPS](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/mawps/test.json), [SVAMP](https://github.com/AGI-Edgerunners/LLM-Adapters/blob/main/dataset/SVAMP/test.json)
42
+
43
+
44
+ ## How to use
45
+
46
+ 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.
47
+ This feature empowers users to employ their own search algorithms and evaluation metrics for the extraction of subnetworks customized to their specific requirements.
48
+
49
+ Moreover, the super-network is essentially the maximal subnetwork, and it can also be directly loaded:
50
+
51
+ ```python
52
+ import torch
53
+ from peft import PeftModel
54
+ from transformers import AutoModelForCausalLM
55
+ from transformers import AutoTokenizer
56
+
57
+ def generate_prompt(instruction):
58
+ return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
59
+
60
+ ### Instruction:
61
+ {instruction}
62
+
63
+ ### Response:
64
+ """
65
+
66
+ base_model_path = "shears-llama-13b-50-math-super/base_model"
67
+ adapter_model_path = "shears-llama-13b-50-math-super/adapter_model"
68
+ base_model = AutoModelForCausalLM.from_pretrained(base_model_path)
69
+ model = PeftModel.from_pretrained(base_model, adapter_model_path)
70
+ model.eval()
71
+
72
+ non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
73
+ print(f"Number of all non-zero parameters: {non_zero_params}")
74
+
75
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
76
+ tokenizer.pad_token_id = 0
77
+
78
+ instruction = "Edgar eats 18 pretzels a day. If his brother eats 1/2 as many, how many does his brother eat in a week?"
79
+ prompt = generate_prompt(instruction)
80
+ inputs = tokenizer(prompt, return_tensors="pt")
81
+ input_ids = inputs["input_ids"].to(model.device)
82
+ with torch.no_grad():
83
+ generation_output = model.generate(
84
+ input_ids=input_ids,
85
+ return_dict_in_generate=True,
86
+ output_scores=True,
87
+ max_new_tokens=256,
88
+ use_cache=True,
89
+ num_beams=4,
90
+ )
91
+ s = generation_output.sequences[0]
92
+ output = tokenizer.decode(s)
93
+ print(output)
94
+
95
+ ```
96
+
97
+ ## Evaluation Results
98
+
99
+ Results of the heuristic sub-network discoverd from the super-network:
100
+
101
+ | Model | Sparsity | GSM8K | AQuA | MAWPS | SVAMP | Average |
102
+ |-----------------------|-------------|-------|-------|-------|-------|---------|
103
+ | LLaMA-7B-LoRA | - | 37.5 | 18.9 | 79.0 | 52.1 | 46.9 |
104
+ | [**LLaMA-7B-Shears**](https://huggingface.co/IntelLabs/shears-llama-7b-50-math-heuristic) | **50%** | 36.1 | 22.0 | 78.6 | 44.5 | 45.3 |
105
+ | LLaMA-13B-LoRA | - | 47.5 | 18.5 | 83.6 | 54.6 | 51.1 |
106
+ | [**LLaMA-13B-Shears**](https://huggingface.co/IntelLabs/shears-llama-13b-50-math-heuristic) | **50%** | 45.1 | 22.0 | 83.2 | 53.3 | 50.9 |
107
+
108
+ ## Model Sources
109
+
110
+ - **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)
111
+ - **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search]()
112
+
113
+ ## Citation
114
+
115
+ ```bash
116
+ @article{munoz2024shears,
117
+ title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
118
+ author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
119
+ journal={},
120
+ year={2024}
121
+ }
122
+ ```
123
+
124
+ ## License
125
+
126
+ Apache-2.0