Views
No views yet
1from llmcompressor.transformers import SparseAutoModelForCausalLM
2from transformers import AutoTokenizer
3from llmcompressor.transformers import oneshot
4from llmcompressor.modifiers.quantization import QuantizationModifier
5
6
7MODEL_ID = "teknium/OpenHermes-2.5-Mistral-7B"
8
9model = SparseAutoModelForCausalLM.from_pretrained(
10 MODEL_ID, device_map="auto", torch_dtype="auto")
11tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
12
13# Configure the simple PTQ quantization
14recipe = QuantizationModifier(
15 targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"])
16
17# Apply the quantization algorithm.
18oneshot(model=model, recipe=recipe)
19
20# Save the model.
21SAVE_DIR = MODEL_ID.split("/")[1] + "-FP8-Dynamic"
22model.save_pretrained(SAVE_DIR)
23tokenizer.save_pretrained(SAVE_DIR)