PEFT
Safetensors
English
jinjieyuan commited on
Commit
7057cdc
·
verified ·
1 Parent(s): abb3b22

Add instruction for the sparse base model

Browse files
Files changed (1) hide show
  1. README.md +29 -3
README.md CHANGED
@@ -14,12 +14,38 @@ The release of the super-network is to facilitate users to apply their own searc
14
  ### Information
15
 
16
  - **Model name:** shears-llama-7b-50-cs-super-adapter
17
- - **Base model:** [IntelLabs/shears-llama-7b-50-base](https://huggingface.co/IntelLabs/shears-llama-7b-50-base)
18
  - **Sparsity:** 50%
19
  - **Domain:** Commonsense
20
  - **Subnetwork version:** Super
21
  - **NNCF Configuration:** [nncf_shears_llama.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/nncf_shears_llama.json)
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  ### Adapter Configuration
24
 
25
  - **LoRA rank:** 32
@@ -64,14 +90,14 @@ def generate_prompt(instruction):
64
  ### Response:
65
  """
66
 
67
- base_model = AutoModelForCausalLM.from_pretrained("IntelLabs/shears-llama-7b-50-base")
68
  model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-llama-7b-50-cs-super-adapter")
69
  model.eval()
70
 
71
  non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
72
  print(f"Number of all non-zero parameters: {non_zero_params}")
73
 
74
- tokenizer = AutoTokenizer.from_pretrained("IntelLabs/shears-llama-7b-50-base")
75
 
76
  instruction = "Please choose the correct answer to the question: A cactus stem is used to store\n\nAnswer1: fruit "
77
  "Answer2: liquid Answer3: food Answer4: spines\n\nAnswer format: answer1/answer2/answer3/answer4"
 
14
  ### Information
15
 
16
  - **Model name:** shears-llama-7b-50-cs-super-adapter
17
+ - **Base model:** Sparsified [LLaMA-7B](https://huggingface.co/yahma/llama-7b-hf)
18
  - **Sparsity:** 50%
19
  - **Domain:** Commonsense
20
  - **Subnetwork version:** Super
21
  - **NNCF Configuration:** [nncf_shears_llama.json](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears/nncf_config/nncf_shears_llama.json)
22
 
23
+ ### Sparsified Base Model
24
+
25
+ Shears employs a simple but effective pruning approach [Wanda](https://arxiv.org/abs/2306.11695) to sparsify the language model, serving as the base model.
26
+ Clone the [Wanda](https://github.com/locuslab/wanda) repo:
27
+
28
+ ```bash
29
+ git clone https://github.com/locuslab/wanda.git && cd wanda && git checkout 8e8fc87 && cd ..
30
+ ```
31
+
32
+ The command for unstructured sparsifying LLaMA-7B with Wanda, to achieve unstructured 50% sparsity:
33
+
34
+ ```bash
35
+ python wanda/main.py \
36
+ --model yahma/llama-7b-hf \
37
+ --prune_method wanda \
38
+ --sparsity_ratio 0.5 \
39
+ --sparsity_type unstructured \
40
+ --save wanda_out \
41
+ --save_model shears-llama-7b-50-base
42
+ ```
43
+ - `--model`: The identifier for the model on the Hugging Face model hub or local path.
44
+ - `--sparsity_ratio`: Specifies the percentage of weights to be pruned.
45
+ - `--save_model`: Specifies the directory where the pruned language model will be stored.
46
+
47
+ Refer to our [repo](https://github.com/IntelLabs/Hardware-Aware-Automated-Machine-Learning/tree/main/Shears#setup) for the environment information to run this command.
48
+
49
  ### Adapter Configuration
50
 
51
  - **LoRA rank:** 32
 
90
  ### Response:
91
  """
92
 
93
+ base_model = AutoModelForCausalLM.from_pretrained("shears-llama-7b-50-base")
94
  model = PeftModel.from_pretrained(base_model, "IntelLabs/shears-llama-7b-50-cs-super-adapter")
95
  model.eval()
96
 
97
  non_zero_params = sum([(param.data != 0).sum().item() for _, param in model.named_parameters()])
98
  print(f"Number of all non-zero parameters: {non_zero_params}")
99
 
100
+ tokenizer = AutoTokenizer.from_pretrained("shears-llama-7b-50-base")
101
 
102
  instruction = "Please choose the correct answer to the question: A cactus stem is used to store\n\nAnswer1: fruit "
103
  "Answer2: liquid Answer3: food Answer4: spines\n\nAnswer format: answer1/answer2/answer3/answer4"