Instructions to use mohammad-mozaffari/llama_2_7b-PATCH-45Sparse with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mohammad-mozaffari/llama_2_7b-PATCH-45Sparse with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mohammad-mozaffari/llama_2_7b-PATCH-45Sparse")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("mohammad-mozaffari/llama_2_7b-PATCH-45Sparse", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use mohammad-mozaffari/llama_2_7b-PATCH-45Sparse with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mohammad-mozaffari/llama_2_7b-PATCH-45Sparse" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mohammad-mozaffari/llama_2_7b-PATCH-45Sparse", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/mohammad-mozaffari/llama_2_7b-PATCH-45Sparse
- SGLang
How to use mohammad-mozaffari/llama_2_7b-PATCH-45Sparse with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mohammad-mozaffari/llama_2_7b-PATCH-45Sparse" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mohammad-mozaffari/llama_2_7b-PATCH-45Sparse", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "mohammad-mozaffari/llama_2_7b-PATCH-45Sparse" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mohammad-mozaffari/llama_2_7b-PATCH-45Sparse", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use mohammad-mozaffari/llama_2_7b-PATCH-45Sparse with Docker Model Runner:
docker model run hf.co/mohammad-mozaffari/llama_2_7b-PATCH-45Sparse
File size: 4,988 Bytes
d20ff8f | 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | ---
base_model:
- meta-llama/Llama-2-7b-hf
library_name: transformers
license: llama2
tags:
- pruning
- sparsity
- 2:4-sparsity
- patch
- maskllm
- mask
pipeline_tag: text-generation
---
<div align="center">
<img src="./PATCH-Logo.png" alt="PATCH" width="360">
</div>
# llama_2_7b-PATCH-45Sparse
> **This checkpoint** (LLaMA-2 7B, PATCH-Tile, 45% sparsity): **48.99%** average zero-shot accuracy, **6.55** WikiText2 perplexity.
[](https://arxiv.org/abs/2509.23410) [](https://github.com/Paramathic/patch)
This repository hosts a **mask only** release for the paper
**[PATCH: Learnable Tile-level Hybrid Sparsity for LLMs](https://arxiv.org/abs/2509.23410)**.
PATCH (Pruning with a Learnable Tile-level Configuration for Hybrid Sparsity) learns a structured mask on **frozen** pretrained weights, assigning each tile as dense (0% sparsity) or 2:4 sparse (50% sparsity) to hit a flexible global sparsity target while staying hardware-friendly.
Because PATCH/MaskLLM keep the base weights **frozen**, we distribute *only the
binary keep/prune mask* (bit-packed in `mask.npz`) - **no weight values**. You
recover the sparse model by downloading the original base model and applying the
mask.
- Base model: [`meta-llama/Llama-2-7b-hf`](https://huggingface.co/meta-llama/Llama-2-7b-hf)
- Method: **PATCH-Tile** | Target sparsity: **45%** | Pattern: **Dense / 2:4 tiles**
- Measured mask sparsity: **44.97%**.
<div align="center">
<img src="./PATCH-Pipeline.svg" alt="PATCH pipeline" width="760">
</div>
## Results (LLaMA-2 7B)
| Sparsity | Method | Pattern | Avg Acc (% ↑) | WikiText2 PPL (↓) |
|---|---|---|---|---|
| 0% | Dense | - | 54.61 | 5.12 |
| 50% | Magnitude | 2:4 | 43.44 | 54.39 |
| 50% | Wanda | 2:4 | 44.30 | 11.15 |
| 50% | SparseGPT | 2:4 | 45.09 | 10.12 |
| 50% | Thanos | 2:4 | 44.80 | 11.19 |
| 50% | ProxSparse | 2:4 | 45.92 | 9.18 |
| 50% | MaskLLM | 2:4 | 48.62 | 6.78 |
| 45% | **PATCH-Tile** ⭐ | Dense/2:4 | **48.99** | **6.55** |
| 35% | PATCH-Tile | Dense/2:4 | 50.08 | 6.18 |
| 25% | PATCH-Tile | Dense/2:4 | 51.58 | 5.86 |
Per-task zero-shot accuracy (%) for this checkpoint:
| MMLU | PIQA | ARC-E | ARC-C | WinoG. | OBQA | RACE | HellaS. | **Average** |
|---|---|---|---|---|---|---|---|---|
| 27.28 | 75.41 | 70.16 | 35.84 | 65.27 | 27.60 | 38.76 | 51.61 | **48.99** |
All numbers are from the PATCH paper ([arXiv:2509.23410](https://arxiv.org/abs/2509.23410)); accuracy
is the average over MMLU, PIQA, ARC-Easy, ARC-Challenge, Winogrande, OpenBookQA,
RACE and HellaSwag, evaluated with the LM-Evaluation-Harness. PPL is WikiText2.
## Training hyper-parameters
| Hyper-parameter | Value |
|---|---|
| Fine-tuning dataset | SlimPajama (2B tokens) |
| Training steps | 2000 |
| Global batch size | 256 |
| Sequence length | 4096 |
| Mask tile size | 128 x 128 (hardware tiles: 128x128 / 128x64 / 64x128 / 64x64) |
| Logits init. | N(0, 0.014) |
| Tile-logit prior | SparseGPT (strength 3) |
| Regularization scope | Global (single target density) |
| Evaluation | LM-Eval-Harness (8 zero-shot tasks) + WikiText2 PPL @ seqlen 4096 |
| Hardware | 1 node x 4 GPUs, data parallel (HuggingFace Trainer) |
| Optimizer | Adam |
| Learning rate | 1e-4 |
| Gumbel scaling (kappa) | 100 -> 500 |
| Gumbel temp (tau) | 2 -> 0.05 |
| Sparsity reg. (lambda1) | 3 |
| Weight reg. (lambda2) | 0.1 |
## How to use
```python
from huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM
import torch
from load_patch_mask import apply_patch_mask # shipped in this repo
npz = hf_hub_download(repo_id="mohammad-mozaffari/llama_2_7b-PATCH-45Sparse", filename="mask.npz")
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf", torch_dtype=torch.bfloat16)
apply_patch_mask(model, npz) # zeroes the pruned weights in place
```
Or from the command line:
```bash
python load_patch_mask.py --base_model meta-llama/Llama-2-7b-hf --mask_repo mohammad-mozaffari/llama_2_7b-PATCH-45Sparse
```
Speedup on real hardware requires a 2:4-aware / hybrid sparse kernel; see the
[GitHub repository](https://github.com/Paramathic/patch) and [STOICC](https://github.com/Paramathic/stoicc).
## License
The released mask is a derivative of the base model and is distributed under the
base model's license (**`llama2`**). You must comply with that license and
obtain access to the base model separately.
> Use governed by the Llama 2 Community License.
The mask-generation code is released under the MIT license (see the
[PATCH repository](https://github.com/Paramathic/patch)).
## Citation
```bibtex
@article{hourri2025patch,
title = {PATCH: Learnable Tile-level Hybrid Sparsity for LLMs},
author = {Hourri, Younes and Mozaffari, Mohammad and Mehri Dehnavi, Maryam},
year = 2025,
journal = {arXiv preprint arXiv:2509.23410}
}
```
|