jinjieyuan
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -1,120 +1,120 @@
|
|
1 |
-
---
|
2 |
-
language: en
|
3 |
-
license: apache-2.0
|
4 |
-
---
|
5 |
-
|
6 |
-
# Shears Model Card: shears-llama-13b-50-math-heuristic
|
7 |
-
|
8 |
-
The heuristic adapter discovered from the [super-adapter](https://huggingface.co/IntelLabs/shears-llama-13b-50-math-super) fine-tuned on sparsified LLaMA-13B with some math reasoning datasets using Shears.
|
9 |
-
|
10 |
-
## Model Details
|
11 |
-
|
12 |
-
### Information
|
13 |
-
|
14 |
-
- **Model name:** shears-llama-13b-50-math-heuristic
|
15 |
-
- **Base model:** [IntelLabs/
|
16 |
-
- **Sparsity:** 50%
|
17 |
-
- **Domain:** Math
|
18 |
-
- **Subnetwork version:** Heuristic
|
19 |
-
- **NNCF Configuration:** [nncf_shears_llama.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/nncf_shears_llama.json)
|
20 |
-
|
21 |
-
### Adapter Configuration
|
22 |
-
|
23 |
-
- **LoRA rank:** 32 (24 in the heuristic subnetwork)
|
24 |
-
- **LoRA alpha:** 64
|
25 |
-
- **LoRA target modules:** q_proj, k_proj, v_proj, up_proj, down_proj
|
26 |
-
- **LoRA rank search space:** [32, 24, 16] (for each LoRA module)
|
27 |
-
|
28 |
-
### Training Hyperparameters
|
29 |
-
|
30 |
-
- **Batch size:** 16
|
31 |
-
- **Learning rate:** 3e-4
|
32 |
-
- **Epoch:** 3
|
33 |
-
|
34 |
-
### Training Data
|
35 |
-
|
36 |
-
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).
|
37 |
-
|
38 |
-
### Evaluation Data
|
39 |
-
[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)
|
40 |
-
|
41 |
-
|
42 |
-
## How to use
|
43 |
-
|
44 |
-
Use our modified PEFT library (apply [patch](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/patches/peft-modifications-for-shears-inference-usage.patch)):
|
45 |
-
```bash
|
46 |
-
git clone https://github.com/huggingface/peft.git
|
47 |
-
cd peft && git checkout v0.5.0 && git apply --ignore-space-change --ignore-whitespace peft-modifications-for-shears-inference-usage.patch && pip install -e . && cd ..
|
48 |
-
```
|
49 |
-
|
50 |
-
```python
|
51 |
-
import torch
|
52 |
-
from peft import PeftModel
|
53 |
-
from transformers import AutoModelForCausalLM
|
54 |
-
from transformers import AutoTokenizer
|
55 |
-
|
56 |
-
def generate_prompt(instruction):
|
57 |
-
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
58 |
-
|
59 |
-
### Instruction:
|
60 |
-
{instruction}
|
61 |
-
|
62 |
-
### Response:
|
63 |
-
"""
|
64 |
-
|
65 |
-
base_model = AutoModelForCausalLM.from_pretrained("IntelLabs/
|
66 |
-
model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-llama-13b-50-math-heuristic")
|
67 |
-
model.eval()
|
68 |
-
|
69 |
-
non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
|
70 |
-
print(f"Number of all non-zero parameters: {non_zero_params}")
|
71 |
-
|
72 |
-
tokenizer = AutoTokenizer.from_pretrained("IntelLabs/
|
73 |
-
|
74 |
-
instruction = "Edgar eats 18 pretzels a day. If his brother eats 1/2 as many, how many does his brother eat in a week?"
|
75 |
-
prompt = generate_prompt(instruction)
|
76 |
-
inputs = tokenizer(prompt, return_tensors="pt")
|
77 |
-
input_ids = inputs["input_ids"].to(model.device)
|
78 |
-
with torch.no_grad():
|
79 |
-
generation_output = model.generate(
|
80 |
-
input_ids=input_ids,
|
81 |
-
return_dict_in_generate=True,
|
82 |
-
output_scores=True,
|
83 |
-
max_new_tokens=256,
|
84 |
-
use_cache=True,
|
85 |
-
num_beams=4,
|
86 |
-
)
|
87 |
-
s = generation_output.sequences[0]
|
88 |
-
output = tokenizer.decode(s)
|
89 |
-
print(output)
|
90 |
-
|
91 |
-
```
|
92 |
-
|
93 |
-
## Evaluation Results
|
94 |
-
|
95 |
-
| Model | Sparsity | GSM8K | AQuA | MAWPS | SVAMP | Average |
|
96 |
-
|-----------------------|-------------|-------|-------|-------|-------|---------|
|
97 |
-
| LLaMA-7B-LoRA | - | 37.5 | 18.9 | 79.0 | 52.1 | 46.9 |
|
98 |
-
| [**LLaMA-7B-Shears**](https://huggingface.co/IntelLabs/shears-llama-7b-50-math-heuristic) | **50%** | 36.1 | 22.0 | 78.6 | 44.5 | 45.3 |
|
99 |
-
| LLaMA-13B-LoRA | - | 47.5 | 18.5 | 83.6 | 54.6 | 51.1 |
|
100 |
-
| [**LLaMA-13B-Shears**](https://huggingface.co/IntelLabs/shears-llama-13b-50-math-heuristic) | **50%** | 45.1 | 22.0 | 83.2 | 53.3 | 50.9 |
|
101 |
-
|
102 |
-
## Model Sources
|
103 |
-
|
104 |
-
- **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)
|
105 |
-
- **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search](https://arxiv.org/abs/2404.10934)
|
106 |
-
|
107 |
-
## Citation
|
108 |
-
|
109 |
-
```bash
|
110 |
-
@article{munoz2024shears,
|
111 |
-
title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
|
112 |
-
author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
|
113 |
-
journal={The 2024 Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL-2024)},
|
114 |
-
year={2024}
|
115 |
-
}
|
116 |
-
```
|
117 |
-
|
118 |
-
## License
|
119 |
-
|
120 |
-
Apache-2.0
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
license: apache-2.0
|
4 |
+
---
|
5 |
+
|
6 |
+
# Shears Model Card: shears-llama-13b-50-math-heuristic-adapter
|
7 |
+
|
8 |
+
The heuristic adapter discovered from the [super-adapter](https://huggingface.co/IntelLabs/shears-llama-13b-50-math-super-adapter) fine-tuned on sparsified LLaMA-13B with some math reasoning datasets using Shears.
|
9 |
+
|
10 |
+
## Model Details
|
11 |
+
|
12 |
+
### Information
|
13 |
+
|
14 |
+
- **Model name:** shears-llama-13b-50-math-heuristic-adapter
|
15 |
+
- **Base model:** [IntelLabs/shears-llama-13b-50-base](https://huggingface.co/IntelLabs/shears-llama-13b-50-base)
|
16 |
+
- **Sparsity:** 50%
|
17 |
+
- **Domain:** Math
|
18 |
+
- **Subnetwork version:** Heuristic
|
19 |
+
- **NNCF Configuration:** [nncf_shears_llama.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/nncf_shears_llama.json)
|
20 |
+
|
21 |
+
### Adapter Configuration
|
22 |
+
|
23 |
+
- **LoRA rank:** 32 (24 in the heuristic subnetwork)
|
24 |
+
- **LoRA alpha:** 64
|
25 |
+
- **LoRA target modules:** q_proj, k_proj, v_proj, up_proj, down_proj
|
26 |
+
- **LoRA rank search space:** [32, 24, 16] (for each LoRA module)
|
27 |
+
|
28 |
+
### Training Hyperparameters
|
29 |
+
|
30 |
+
- **Batch size:** 16
|
31 |
+
- **Learning rate:** 3e-4
|
32 |
+
- **Epoch:** 3
|
33 |
+
|
34 |
+
### Training Data
|
35 |
+
|
36 |
+
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).
|
37 |
+
|
38 |
+
### Evaluation Data
|
39 |
+
[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)
|
40 |
+
|
41 |
+
|
42 |
+
## How to use
|
43 |
+
|
44 |
+
Use our modified PEFT library (apply [patch](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/patches/peft-modifications-for-shears-inference-usage.patch)):
|
45 |
+
```bash
|
46 |
+
git clone https://github.com/huggingface/peft.git
|
47 |
+
cd peft && git checkout v0.5.0 && git apply --ignore-space-change --ignore-whitespace peft-modifications-for-shears-inference-usage.patch && pip install -e . && cd ..
|
48 |
+
```
|
49 |
+
|
50 |
+
```python
|
51 |
+
import torch
|
52 |
+
from peft import PeftModel
|
53 |
+
from transformers import AutoModelForCausalLM
|
54 |
+
from transformers import AutoTokenizer
|
55 |
+
|
56 |
+
def generate_prompt(instruction):
|
57 |
+
return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
58 |
+
|
59 |
+
### Instruction:
|
60 |
+
{instruction}
|
61 |
+
|
62 |
+
### Response:
|
63 |
+
"""
|
64 |
+
|
65 |
+
base_model = AutoModelForCausalLM.from_pretrained("IntelLabs/shears-llama-13b-50-base")
|
66 |
+
model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-llama-13b-50-math-heuristic-adapter")
|
67 |
+
model.eval()
|
68 |
+
|
69 |
+
non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
|
70 |
+
print(f"Number of all non-zero parameters: {non_zero_params}")
|
71 |
+
|
72 |
+
tokenizer = AutoTokenizer.from_pretrained("IntelLabs/shears-llama-13b-50-base")
|
73 |
+
|
74 |
+
instruction = "Edgar eats 18 pretzels a day. If his brother eats 1/2 as many, how many does his brother eat in a week?"
|
75 |
+
prompt = generate_prompt(instruction)
|
76 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
77 |
+
input_ids = inputs["input_ids"].to(model.device)
|
78 |
+
with torch.no_grad():
|
79 |
+
generation_output = model.generate(
|
80 |
+
input_ids=input_ids,
|
81 |
+
return_dict_in_generate=True,
|
82 |
+
output_scores=True,
|
83 |
+
max_new_tokens=256,
|
84 |
+
use_cache=True,
|
85 |
+
num_beams=4,
|
86 |
+
)
|
87 |
+
s = generation_output.sequences[0]
|
88 |
+
output = tokenizer.decode(s)
|
89 |
+
print(output)
|
90 |
+
|
91 |
+
```
|
92 |
+
|
93 |
+
## Evaluation Results
|
94 |
+
|
95 |
+
| Model | Sparsity | GSM8K | AQuA | MAWPS | SVAMP | Average |
|
96 |
+
|-----------------------|-------------|-------|-------|-------|-------|---------|
|
97 |
+
| LLaMA-7B-LoRA | - | 37.5 | 18.9 | 79.0 | 52.1 | 46.9 |
|
98 |
+
| [**LLaMA-7B-Shears**](https://huggingface.co/IntelLabs/shears-llama-7b-50-math-heuristic-adapter) | **50%** | 36.1 | 22.0 | 78.6 | 44.5 | 45.3 |
|
99 |
+
| LLaMA-13B-LoRA | - | 47.5 | 18.5 | 83.6 | 54.6 | 51.1 |
|
100 |
+
| [**LLaMA-13B-Shears**](https://huggingface.co/IntelLabs/shears-llama-13b-50-math-heuristic-adapter) | **50%** | 45.1 | 22.0 | 83.2 | 53.3 | 50.9 |
|
101 |
+
|
102 |
+
## Model Sources
|
103 |
+
|
104 |
+
- **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)
|
105 |
+
- **Paper:** [Shears: Unstructured Sparsity with Neural Low-rank Adapter Search](https://arxiv.org/abs/2404.10934)
|
106 |
+
|
107 |
+
## Citation
|
108 |
+
|
109 |
+
```bash
|
110 |
+
@article{munoz2024shears,
|
111 |
+
title = {Shears: Unstructured Sparsity with Neural Low-rank Adapter Search},
|
112 |
+
author={J. Pablo Munoz and Jinjie Yuan and Nilesh Jain},
|
113 |
+
journal={The 2024 Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL-2024)},
|
114 |
+
year={2024}
|
115 |
+
}
|
116 |
+
```
|
117 |
+
|
118 |
+
## License
|
119 |
+
|
120 |
+
Apache-2.0
|