Views
No views yet
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("IntelLabs/shears-mpt-7b-50-base", trust_remote_code=True)
16model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-mpt-7b-50-gsm8k-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("IntelLabs/shears-mpt-7b-50-base", trust_remote_code=True)
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 Accuracy |
|---|---|---|
| MPT-7B-Shears | 50% | 33.4 |
| Ethical Considerations | Description |
|---|---|
| Data | The adapter was trained using the GSM8K dataset 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}