File size: 996 Bytes
0381c79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
https://huggingface.co/HuggingFaceM4/tiny-random-LlamaForCausalLM

```python
from sparseml.transformers import SparseAutoModelForCausalLM, SparseAutoTokenizer, oneshot
from sparseml.modifiers import SparseGPTModifier

model_id = "HuggingFaceM4/tiny-random-LlamaForCausalLM"
compressed_model_id = "mgoin/tiny-random-LlamaForCausalLM-pruned95-compressed"

# Apply SparseGPT to the model
oneshot(
    model=model_id,
    dataset="open_platypus",
    recipe=SparseGPTModifier(sparsity=0.95),
    output_dir="temp-output",
)

model = SparseAutoModelForCausalLM.from_pretrained("temp-output", torch_dtype="auto")
tokenizer = SparseAutoTokenizer.from_pretrained(model_id)

model.save_pretrained(compressed_model_id.split("/")[-1], save_compressed=True)
tokenizer.save_pretrained(compressed_model_id.split("/")[-1])

# Upload the checkpoint to Hugging Face
from huggingface_hub import HfApi
HfApi().upload_folder(
    folder_path=compressed_model_id.split("/")[-1],
    repo_id=compressed_model_id,
)
```