Views
No views yet
git clone https://github.com/locuslab/wanda.git && cd wanda && git checkout 8e8fc87 && cd ..1python wanda/main.py \
2 --model yahma/llama-13b-hf \
3 --prune_method wanda \
4 --sparsity_ratio 0.5 \
5 --sparsity_type unstructured \
6 --save wanda_out \
7 --save_model shears-llama-13b-50-base--model: The identifier for the model on the Hugging Face model hub or local path.--sparsity_ratio: Specifies the percentage of weights to be pruned.--save_model: Specifies the directory where the pruned language model will be stored.1import torch
2from peft import PeftModel
3from transformers import AutoModelForCausalLM
4from transformers import AutoTokenizer
5
6def generate_prompt(instruction):
7 return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
8
9 ### Instruction:
10 {instruction}
11
12 ### Response:
13 """
14
15base_model = AutoModelForCausalLM.from_pretrained("shears-llama-13b-50-base")
16model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-llama-13b-50-math-super-adapter")
17model.eval()
18
19non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
20print(f"Number of all non-zero parameters: {non_zero_params}")
21
22tokenizer = AutoTokenizer.from_pretrained("shears-llama-13b-50-base")
23
24instruction = "Edgar eats 18 pretzels a day. If his brother eats 1/2 as many, how many does his brother eat in a week?"
25prompt = generate_prompt(instruction)
26inputs = tokenizer(prompt, return_tensors="pt")
27input_ids = inputs["input_ids"].to(model.device)
28with torch.no_grad():
29 generation_output = model.generate(
30 input_ids=input_ids,
31 return_dict_in_generate=True,
32 output_scores=True,
33 max_new_tokens=256,
34 use_cache=True,
35 num_beams=4,
36 )
37 s = generation_output.sequences[0]
38 output = tokenizer.decode(s)
39print(output)
40| Model | Sparsity | GSM8K | AQuA | MAWPS | SVAMP | Average |
|---|---|---|---|---|---|---|
| LLaMA-7B-LoRA | - | 37.5 | 18.9 | 79.0 | 52.1 | 46.9 |
| LLaMA-7B-Shears | 50% | 36.1 | 22.0 | 78.6 | 44.5 | 45.3 |
| LLaMA-13B-LoRA | - | 47.5 | 18.5 | 83.6 | 54.6 | 51.1 |
| LLaMA-13B-Shears | 50% | 45.1 | 22.0 | 83.2 | 53.3 | 50.9 |
| Ethical Considerations | Description |
|---|---|
| Data | The adapter was trained using the math_10k.json data mixture as described above. |
| Human life | The model is not intended to inform decisions central to human life or flourishing. |
| Mitigations | No additional risk mitigation strategies were considered during model development. |
| Risks and harms | This model has not been assessed for harm or biases, and should not be used for sensitive applications where it may cause harm. |
| Use cases | - |
1@inproceedings{munoz-etal-2024-shears,
2 title = "Shears: Unstructured Sparsity with Neural Low-rank Adapter Search",
3 author = "Mu{\~n}oz, J. Pablo and
4 Yuan, Jinjie and
5 Jain, Nilesh",
6 editor = "Yang, Yi and
7 Davani, Aida and
8 Sil, Avi and
9 Kumar, Anoop",
10 booktitle = "Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 6: Industry Track)",
11 month = jun,
12 year = "2024",
13 address = "Mexico City, Mexico",
14 publisher = "Association for Computational Linguistics",
15 url = "https://aclanthology.org/2024.naacl-industry.34",
16 doi = "10.18653/v1/2024.naacl-industry.34",
17 pages = "395--405",
18}