Add files using upload-large-folder tool
Browse files- llm-compressor/r1_1776_moe_w8a8_fp8dyn.py +22 -0
- recipe.yaml +1 -1
llm-compressor/r1_1776_moe_w8a8_fp8dyn.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
from llmcompressor.transformers import oneshot
|
| 3 |
+
from llmcompressor.modifiers.quantization import QuantizationModifier
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
MODEL_ID = "perplexity-ai/r1-1776"
|
| 7 |
+
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
MODEL_ID, device_map="auto", torch_dtype="auto", trust_remote_code=True)
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 11 |
+
|
| 12 |
+
# Configure the simple PTQ quantization
|
| 13 |
+
recipe = QuantizationModifier(
|
| 14 |
+
targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head","re:.*mlp.gate$"])
|
| 15 |
+
|
| 16 |
+
# Apply the quantization algorithm.
|
| 17 |
+
oneshot(model=model, recipe=recipe, trust_remote_code_model=True)
|
| 18 |
+
|
| 19 |
+
# Save the model.
|
| 20 |
+
SAVE_DIR = "output/" + MODEL_ID.split("/")[1] + "-FP8-Dynamic"
|
| 21 |
+
model.save_pretrained(SAVE_DIR)
|
| 22 |
+
tokenizer.save_pretrained(SAVE_DIR)
|
recipe.yaml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
DEFAULT_stage:
|
| 2 |
DEFAULT_modifiers:
|
| 3 |
QuantizationModifier:
|
| 4 |
-
ignore: [lm_head]
|
| 5 |
targets: [Linear]
|
| 6 |
scheme: FP8_DYNAMIC
|
|
|
|
| 1 |
DEFAULT_stage:
|
| 2 |
DEFAULT_modifiers:
|
| 3 |
QuantizationModifier:
|
| 4 |
+
ignore: [lm_head, 're:.*mlp.gate$']
|
| 5 |
targets: [Linear]
|
| 6 |
scheme: FP8_DYNAMIC
|