|
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, |
|
) |
|
``` |