Update README.md
Browse files
README.md
CHANGED
@@ -5,4 +5,44 @@ base_model:
|
|
5 |
library_name: transformers
|
6 |
---
|
7 |
|
8 |
-
The [deepseek-ai/DeepSeek-R1-Distill-Llama-70B](https://huggingface.co/perplexity-ai/r1-1776-distill-llama-70b) model quantized to fp8.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
library_name: transformers
|
6 |
---
|
7 |
|
8 |
+
The [deepseek-ai/DeepSeek-R1-Distill-Llama-70B](https://huggingface.co/perplexity-ai/r1-1776-distill-llama-70b) model quantized to fp8.
|
9 |
+
|
10 |
+
# quantization using llm_compressor
|
11 |
+
```python
|
12 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
13 |
+
from llmcompressor.transformers import oneshot
|
14 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
15 |
+
|
16 |
+
# Define the model ID for the model you want to quantize
|
17 |
+
MODEL_ID = "perplexity-ai/r1-1776-distill-llama-70b"
|
18 |
+
|
19 |
+
# Load the model and tokenizer with appropriate parameters
|
20 |
+
model = AutoModelForCausalLM.from_pretrained(
|
21 |
+
MODEL_ID,
|
22 |
+
device_map="auto",
|
23 |
+
torch_dtype="auto",
|
24 |
+
trust_remote_code=True, # Add this to automatically trust remote code
|
25 |
+
low_cpu_mem_usage=True, # Help with memory issues during loading
|
26 |
+
offload_folder="offload" # Use disk offloading for large models
|
27 |
+
)
|
28 |
+
|
29 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
30 |
+
MODEL_ID,
|
31 |
+
trust_remote_code=True # Also need this for tokenizer
|
32 |
+
)
|
33 |
+
|
34 |
+
# Configure the quantization recipe
|
35 |
+
recipe = QuantizationModifier(targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"])
|
36 |
+
|
37 |
+
# Apply the quantization algorithm
|
38 |
+
oneshot(model=model, recipe=recipe)
|
39 |
+
|
40 |
+
# Define the directory to save the quantized model
|
41 |
+
SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
|
42 |
+
|
43 |
+
# Save the quantized model and tokenizer
|
44 |
+
model.save_pretrained(SAVE_DIR)
|
45 |
+
tokenizer.save_pretrained(SAVE_DIR)
|
46 |
+
|
47 |
+
print(f"Quantized model saved to {SAVE_DIR}")
|
48 |
+
```
|