Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```python
|
2 |
+
model_id = "mgoin/starcoderbase-1b-pruned50-quant"
|
3 |
+
|
4 |
+
# Load model with SparseAutoModel
|
5 |
+
from sparseml.transformers.utils import SparseAutoModel
|
6 |
+
from transformers import AutoConfig
|
7 |
+
|
8 |
+
config = AutoConfig.from_pretrained(model_id) # Why does SparseAutoModel need config?
|
9 |
+
model = SparseAutoModel.text_generation_from_pretrained(model_id, config=config)
|
10 |
+
|
11 |
+
# Apply recipe to model
|
12 |
+
# Note: Really annoying we can't grab the recipe.yaml present in the uploaded model
|
13 |
+
# and you need this separate apply_recipe_structure_to_model function
|
14 |
+
from sparseml.pytorch.model_load.helpers import apply_recipe_structure_to_model
|
15 |
+
from huggingface_hub import hf_hub_download
|
16 |
+
import os
|
17 |
+
|
18 |
+
recipe_path = hf_hub_download(repo_id=model_id, filename="recipe.yaml")
|
19 |
+
apply_recipe_structure_to_model(
|
20 |
+
model=model, recipe_path=recipe_path, model_path=os.path.dirname(recipe_path)
|
21 |
+
)
|
22 |
+
|
23 |
+
# Regular HF inference
|
24 |
+
from transformers import AutoTokenizer
|
25 |
+
|
26 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
27 |
+
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt")
|
28 |
+
outputs = model.generate(inputs)
|
29 |
+
print(tokenizer.decode(outputs[0]))
|
30 |
+
"""
|
31 |
+
def print_hello_world():
|
32 |
+
print("Hello World!")
|
33 |
+
|
34 |
+
print_hello_world
|
35 |
+
"""
|
36 |
+
```
|