Views
No views yet
vllm serve RedHatAI/Mellum2-12B-A2.5B-Thinking-FP8-Dynamic1import json, os
2
3from compressed_tensors.offload import dispatch_model
4from transformers import Qwen3MoeForCausalLM, AutoTokenizer
5
6from llmcompressor import oneshot
7from llmcompressor.modifiers.quantization import QuantizationModifier
8
9MODEL_ID = "JetBrains/Mellum2-12B-A2.5B-Thinking"
10
11# Load model.
12model = Qwen3MoeForCausalLM.from_pretrained(MODEL_ID)
13tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
14
15# Configure the quantization algorithm and scheme.
16# In this case, we:
17# * quantize the weights to fp8 with per channel via ptq
18# * quantize the activations to fp8 with dynamic per token
19recipe = QuantizationModifier(
20 targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"]
21)
22
23# Apply quantization.
24oneshot(model=model, recipe=recipe)
25
26# Confirm generations of the quantized model look sane.
27print("========== SAMPLE GENERATION ==============")
28dispatch_model(model)
29input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
30 model.device
31)
32output = model.generate(input_ids, max_new_tokens=20)
33print(tokenizer.decode(output[0]))
34print("==========================================")
35
36# Save to disk in compressed-tensors format.
37SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-FP8-Dynamic"
38model.save_pretrained(SAVE_DIR)
39tokenizer.save_pretrained(SAVE_DIR)
40
41
42config_path = os.path.join(SAVE_DIR, "config.json")
43
44with open(config_path, "r") as f:
45 config = json.load(f)
46
47config["architectures"] = ["MellumForCausalLM"]
48config["model_type"] = "mellum"
49
50with open(config_path, "w") as f:
51 json.dump(config, f, indent=2)