Views
No views yet
pip install deepsparse-nightly[llm]1from deepsparse import TextGeneration
2
3prompt = "How to make banana bread?"
4formatted_prompt = f"### Instruction\n{prompt}\n### Response:\n"
5
6model = TextGeneration(model_path="hf:nm-testing/Nous-Hermes-llama-2-7b-pruned50-quant-ds")
7
8print(model(formatted_prompt, max_new_tokens=200).generations[0].text)
9"""
10To make banana bread, start by preheating the oven to 350 degrees Fahrenheit.
11In a bowl, mix together 1 cup of flour, 1 cup of sugar, and 1 teaspoon of baking soda.
12Then, add 1 cup of milk and 1 cup of mashed banana.
13Mix well and pour the mixture into a greased pan.
14Bake the bread for about 45 minutes or until a toothpick inserted comes out clean.
15"""### Instruction:
<prompt>
### Response:
<leave a newline blank for model to respond>
recipe.yaml in this repo and follow the instructions below.1git clone https://github.com/neuralmagic/sparseml
2pip install -e "sparseml[transformers]"
3python sparseml/src/sparseml/transformers/sparsification/obcq/obcq.py NousResearch/Nous-Hermes-llama-2-7b open_platypus --precision float16 --recipe recipe.yaml --save True
4python sparseml/src/sparseml/transformers/sparsification/obcq/export.py --task text-generation --model_path obcq_deployment
5cp 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}")