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