Views
No views yet
pip install deepsparse-nightly[llm]1from deepsparse import TextGeneration
2
3prompt = "How to make banana bread?"
4formatted_prompt = f"<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
5
6model = TextGeneration(model="hf:neuralmagic/TinyLlama-1.1B-Chat-v0.4-pruned50-quant-ds")
7print(model(formatted_prompt, max_new_tokens=500).generations[0].text)
8
9"""
10Banana bread is a delicious and easy-to-make recipe that is sure to please. Here is a recipe for making banana bread:
11
12Ingredients:
13
14 For the Banana Bread:
15
16 - 1 cup of sugar
17 - 1 cup of flour
18 - 1/2 cup of mashed bananas
19 - 1/4 cup of milk
20 - 1/2 cup of melted butter
21 - 1/4 cup of baking powder
22 - 1/4 cup of baking soda
23 - 1/4 cup of eggs
24 - 1/4 cup of milk
25 - 1/4 cup of sugar
26
27
28Instructions:
29
30 1. Preheat the oven to 325°F (160°C).
31 2. In a large bowl, combine the sugar and flour.
32 3. In a separate bow, combine the mashed bananas, milk, butter, baking powder, baking soda, milk, sugar.
33 4. Add the bananas and milk into the flour-sugar mixture.
34 5. Pour the milk into the bowl of the flour-sugar mixture.
35 6. Pour the baking powder into the bowl of the flour-sugar mixture.
36 7. Pour the mashed bananas into the bowl of the flour-sugar mixture.
37 8. Add the eggs into the bowl of the flour-sugar mixture.
38 9. Stir the mixture until it becomes a dough.
39 10. Grease a 9-inch (23 cm) square pan.
40 11. Pour the mixture into the pan.
41 12. Bake the banana bread in the oven for 40 minutes.
42 13. Remove the banana bread from the oven and cool it.
43 14. Cut the bread into 16 pieces.
44 15. Make the glaze:
45 16. Sprinkle the sugar over the bread.
46 17. Bake the bread in the oven for 30 minutes.
47"""<|im_start|>user\n
{prompt}<|im_end|>\n
<|im_start|>assistant\n
recipe.yaml in this repo and follow the instructions below.1git clone https://github.com/neuralmagic/sparseml
2pip install -e "sparseml[transformers]"
3wget https://huggingface.co/neuralmagic/TinyLlama-1.1B-Chat-v0.4-pruned50-quant/raw/main/recipe.yaml # download recipe
4python sparseml/src/sparseml/transformers/sparsification/obcq/obcq.py TinyLlama/TinyLlama-1.1B-Chat-v0.4 open_platypus --recipe recipe.yaml --save True
5python sparseml/src/sparseml/transformers/sparsification/obcq/export.py --task text-generation --model_path obcq_deployment
6cp deployment/model.onnx deployment/model-orig.onnx1import os
2import onnx
3from sparseml.exporters.kv_cache_injector import KeyValueCacheInjector
4input_file = "deployment/model-orig.onnx"
5output_file = "deployment/model.onnx"
6model = onnx.load(input_file, load_external_data=False)
7model = KeyValueCacheInjector(model_path=os.path.dirname(input_file)).apply(model)
8onnx.save(model, output_file)
9print(f"Modified model saved to: {output_file}")