File size: 1,150 Bytes
a1a94b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
851c095
a1a94b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c389a9
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
---
language:
- en
pipeline_tag: text-generation
tags:
- facebook
- meta
- pytorch
- llama
- llama-3
license: llama3
new_version: meta-llama/Llama-3.1-8B-Instruct
---

Model quantized to FP8 using llm_compressor
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from llmcompressor.transformers import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier

# Define the model ID for the model you want to quantize
MODEL_ID = "meta-llama/Llama-3.1-8B-Instruct"

# Load the model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
    MODEL_ID, device_map="auto", torch_dtype="auto"
)
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)

# Configure the quantization recipe
recipe = QuantizationModifier(targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"])

# Apply the quantization algorithm
oneshot(model=model, recipe=recipe)

# Define the directory to save the quantized model
SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"

# Save the quantized model and tokenizer
model.save_pretrained(SAVE_DIR)
tokenizer.save_pretrained(SAVE_DIR)

print(f"Quantized model saved to (SAVE_DIR)")
```