Views
No views yet
pip install nm-vllm[sparse]1from vllm import LLM, SamplingParams
2
3model = LLM("nm-testing/Nous-Hermes-2-Yi-34B-pruned2.4", sparsity="semi_structured_sparse_w16a16")
4prompt = "How to make banana bread?"
5formatted_prompt = f"<|im_start|>User:{prompt}\n<|im_start|>assistant:\n"
6
7sampling_params = SamplingParams(max_tokens=100, temperature=0)
8outputs = model.generate(formatted_prompt, sampling_params=sampling_params)
9print(outputs[0].outputs[0].text)
10"""
11To make banana bread, follow these steps:
121. Gather the ingredients:
13- 2 ripe bananas
14- 2 cups of flour
15- 1 teaspoon of baking powder
16- 1 teaspoon of salt
17- 1 teaspoon of sugar
18- 1 teaspoon of vanilla extract
192. Preheat the oven to 350°F.
203. In a mixing bowl, combine the flour, baking powder, salt, sugar, and vanilla extract.
214.
22"""<|im_start|>User:{prompt}\n<|im_start|>assistant:\nrecipe.yaml in this repo and follow the instructions below.1git clone https://github.com/neuralmagic/sparseml
2pip install -e "sparseml[transformers]"1import sparseml.transformers
2
3original_model_name = "NousResearch/Nous-Hermes-2-Yi-34B"
4calibration_dataset = "open_platypus"
5output_directory = "output/"
6
7recipe = """
8test_stage:
9 obcq_modifiers:
10 SparseGPTModifier:
11 sparsity: 0.5
12 sequential_update: true
13 mask_structure: '2:4'
14 targets: ['re:model.layers.\d*$']
15"""
16
17# Apply SparseGPT to the model
18sparseml.transformers.oneshot(
19 model=original_model_name,
20 dataset=calibration_dataset,
21 recipe=recipe,
22 output_dir=output_directory,
23)