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-7b-hf \
3 --prune_method wanda \
4 --sparsity_ratio 0.5 \
5 --sparsity_type unstructured \
6 --save wanda_out \
7 --save_model shears-llama-7b-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.1git clone https://github.com/huggingface/peft.git
2cd peft && git checkout v0.5.0 && git apply --ignore-space-change --ignore-whitespace peft-modifications-for-shears-inference-usage.patch && pip install -e . && cd ..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-7b-50-base")
16model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-llama-7b-50-cs-heuristic-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-7b-50-base")
23
24instruction = "Please choose the correct answer to the question: A cactus stem is used to store\n\nAnswer1: fruit "
25 "Answer2: liquid Answer3: food Answer4: spines\n\nAnswer format: answer1/answer2/answer3/answer4"
26prompt = generate_prompt(instruction)
27inputs = tokenizer(prompt, return_tensors="pt")
28input_ids = inputs["input_ids"].to(model.device)
29with torch.no_grad():
30 generation_output = model.generate(
31 input_ids=input_ids,
32 return_dict_in_generate=True,
33 output_scores=True,
34 max_new_tokens=256,
35 use_cache=True,
36 num_beams=4,
37 )
38 s = generation_output.sequences[0]
39 output = tokenizer.decode(s)
40print(output)
41| Model | Sparsity | BoolQ | PIQA | SIQA | HellaSwag | WinoG | ARC-e | ARC-c | OBQA | Average |
|---|---|---|---|---|---|---|---|---|---|---|
| ChatGPT | - | 73.1 | 85.4 | 68.5 | 78.5 | 66.1 | 89.8 | 79.9 | 74.8 | 77.0 |
| LLaMA-7B-LoRA | - | 68.9 | 80.7 | 77.4 | 78.1 | 78.8 | 77.8 | 61.3 | 74.8 | 74.7 |
| LLaMA-7B-Shears | 50% | 67.3 | 79.1 | 77.5 | 73.3 | 77.7 | 74.4 | 57.9 | 72.8 | 72.5 |
| Ethical Considerations | Description |
|---|---|
| Data | The adapter was trained using the commonsense_170k.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}