mgoin commited on
Commit
253b039
1 Parent(s): fede390

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +93 -0
README.md ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: microsoft/phi-2
3
+ inference: true
4
+ model_type: phi
5
+ quantized_by: mgoin
6
+ tags:
7
+ - nm-vllm
8
+ - sparse
9
+ ---
10
+
11
+ ## phi-2-pruned50
12
+ This repo contains model files for [phi 2](https://huggingface.co/microsoft/phi-2) optimized for [NM-vLLM](https://github.com/neuralmagic/nm-vllm), a high-throughput serving engine for compressed LLMs.
13
+
14
+ This model was pruned with [SparseGPT](https://arxiv.org/abs/2301.00774), using [SparseML](https://github.com/neuralmagic/sparseml).
15
+
16
+ ## Inference
17
+ Install [NM-vLLM](https://github.com/neuralmagic/nm-vllm) for fast inference and low memory-usage:
18
+ ```bash
19
+ pip install nm-vllm[sparse]
20
+ ```
21
+ Run in a Python pipeline for local inference:
22
+ ```python
23
+ from vllm import LLM, SamplingParams
24
+
25
+ # Create a sparse LLM
26
+ llm = LLM("nm-testing/phi-2-pruned50", sparsity="sparse_w16a16")
27
+
28
+ prompt = "Once upon a time, there was a little car named Beep."
29
+ # Create a sampling params object.
30
+ sampling_params = SamplingParams(temperature=0.0, max_tokens=200)
31
+
32
+ # Generate texts from the prompts. The output is a list of RequestOutput objects
33
+ # that contain the prompt, generated text, and other information.
34
+ outputs = llm.generate(prompt, sampling_params)
35
+ # Print the outputs.
36
+ for output in outputs:
37
+ prompt = output.prompt
38
+ generated_text = output.outputs[0].text
39
+ print(f"\nGenerated text: {prompt}{generated_text}\n")
40
+
41
+ """
42
+ Generated text: Once upon a time, there was a little car named Beep. Beep was a small car, but he was very fast and loved to go on adventures. Beep had a friend named Bop who was a big car. Bop was very slow and loved to stay at home. Beep and Bop were very different, but they were still friends.
43
+
44
+ One day, Beep and Bop decided to go on an adventure together. Beep was excited to explore new places and Bop was excited to see Beep explore. They started their adventure by driving on a bumpy road. Beep was having a great time, but Bop was having a hard time. Bop was so big that he couldn't fit in the small spaces between the bumps. Beep was having a great time, but Bop was having a hard time.
45
+
46
+ As they continued their adventure, they came across a big hill. Beep was excited to climb the hill, but Bop was scared. Bop was so big that he couldn't
47
+ """
48
+ ```
49
+
50
+ ## Prompt template
51
+
52
+ ```
53
+ "Instruct: <prompt>\nOutput:"
54
+ ```
55
+
56
+ ## Sparsification
57
+ For details on how this model was sparsified, see the `recipe.yaml` in this repo and follow the instructions below.
58
+
59
+ Install [SparseML](https://github.com/neuralmagic/sparseml):
60
+ ```bash
61
+ git clone https://github.com/neuralmagic/sparseml
62
+ pip install -e "sparseml[transformers]"
63
+ ```
64
+
65
+ Replace the recipe as you like and run this one-shot compression script to apply SparseGPT:
66
+ ```python
67
+ import sparseml.transformers
68
+
69
+ original_model_name = microsoft/phi-2"
70
+ calibration_dataset = "open_platypus"
71
+ output_directory = "output/"
72
+
73
+ recipe = """
74
+ test_stage:
75
+ obcq_modifiers:
76
+ SparseGPTModifier:
77
+ sparsity: 0.5
78
+ sequential_update: true
79
+ targets: ['re:model.layers.\d*$']
80
+ """
81
+
82
+ # Apply SparseGPT to the model
83
+ sparseml.transformers.oneshot(
84
+ model=original_model_name,
85
+ dataset=calibration_dataset,
86
+ recipe=recipe,
87
+ output_dir=output_directory,
88
+ )
89
+ ```
90
+
91
+ ## Slack
92
+
93
+ For further support, and discussions on these models and AI in general, join [Neural Magic's Slack Community](https://join.slack.com/t/discuss-neuralmagic/shared_invite/zt-q1a1cnvo-YBoICSIw3L1dmQpjBeDurQ)