Views
No views yet
vllm serve RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4 --tensor_parallel_size 1 --tokenizer_mode mistral1from openai import OpenAI
2
3# Modify OpenAI's API key and API base to use vLLM's API server.
4openai_api_key = "EMPTY"
5openai_api_base = "http://<your-server-host>:8000/v1"
6
7client = OpenAI(
8 api_key=openai_api_key,
9 base_url=openai_api_base,
10)
11
12model = "RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4"
13
14
15messages = [
16 {"role": "user", "content": "Explain quantum mechanics clearly and concisely."},
17]
18
19outputs = client.chat.completions.create(
20 model=model,
21 messages=messages,
22)
23
24generated_text = outputs.choices[0].message.content
25print(generated_text)1from datasets import load_dataset
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4from llmcompressor import oneshot
5from llmcompressor.modifiers.quantization import QuantizationModifier
6from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
7from llmcompressor.utils import dispatch_for_generation
8
9MODEL_ID = "unsloth/Mistral-Small-3.2-24B-Instruct-2506"
10
11# Load model.
12model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
13tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
14
15DATASET_ID = "HuggingFaceH4/ultrachat_200k"
16DATASET_SPLIT = "train_sft"
17
18# Select number of samples. 512 samples is a good place to start.
19# Increasing the number of samples can improve accuracy.
20NUM_CALIBRATION_SAMPLES = 512
21MAX_SEQUENCE_LENGTH = 2048
22
23# Load dataset and preprocess.
24ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")
25ds = ds.shuffle(seed=42)
26
27def preprocess(example):
28 return {
29 "text": tokenizer.apply_chat_template(
30 example["messages"],
31 tokenize=False,
32 )
33 }
34
35ds = ds.map(preprocess)
36
37# Tokenize inputs.
38def tokenize(sample):
39 return tokenizer(
40 sample["text"],
41 padding=False,
42 max_length=MAX_SEQUENCE_LENGTH,
43 truncation=True,
44 add_special_tokens=False,
45 )
46
47ds = ds.map(tokenize, remove_columns=ds.column_names)
48
49# Configure the quantization algorithm and scheme.
50# In this case, we:
51# * quantize the weights to fp4 with per group 16 via ptq
52# * calibrate a global_scale for activations, which will be used to
53# quantize activations to fp4 on the fly
54smoothing_strength = 0.9
55recipe = [
56 SmoothQuantModifier(smoothing_strength=smoothing_strength),
57 QuantizationModifier(
58 ignore=["re:.*lm_head.*"],
59 config_groups={
60 "group_0": {
61 "targets": ["Linear"],
62 "weights": {
63 "num_bits": 4,
64 "type": "float",
65 "strategy": "tensor_group",
66 "group_size": 16,
67 "symmetric": True,
68 "observer": "mse",
69 },
70 "input_activations": {
71 "num_bits": 4,
72 "type": "float",
73 "strategy": "tensor_group",
74 "group_size": 16,
75 "symmetric": True,
76 "dynamic": "local",
77 "observer": "minmax",
78 },
79 }
80 },
81 )
82]
83
84# Save to disk in compressed-tensors format.
85SAVE_DIR = MODEL_ID.rstrip("/").split("/")[-1] + "-NVFP4"
86
87# Apply quantization.
88oneshot(
89 model=model,
90 dataset=ds,
91 recipe=recipe,
92 max_seq_length=MAX_SEQUENCE_LENGTH,
93 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
94 output_dir=SAVE_DIR,
95)
96
97print("\n\n")
98print("========== SAMPLE GENERATION ==============")
99dispatch_for_generation(model)
100input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to("cuda")
101output = model.generate(input_ids, max_new_tokens=100)
102print(tokenizer.decode(output[0]))
103print("==========================================\n\n")
104
105model.save_pretrained(SAVE_DIR, save_compressed=True)
106tokenizer.save_pretrained(SAVE_DIR)| Category | Metric | unsloth/Mistral-Small-3.2-24B-Instruct-2506 | RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4 | Recovery |
|---|---|---|---|---|
| OpenLLM V1 | arc_challenge | 68.52 | 66.98 | 97.75 |
| gsm8k | 89.61 | 87.11 | 97.21 | |
| hellaswag | 85.70 | 85.11 | 99.31 | |
| mmlu | 81.06 | 79.43 | 97.99 | |
| truthfulqa_mc2 | 61.35 | 60.34 | 98.35 | |
| winogrande | 83.27 | 81.61 | 98.01 | |
| Average | 78.25 | 76.76 | 98.10 | |
| OpenLLM V2 | BBH (3-shot) | 65.86 | 64.05 | 97.25 |
| MMLU-Pro (5-shot) | 50.84 | 48.45 | 95.30 | |
| MuSR (0-shot) | 39.15 | 40.21 | 102.71 | |
| IFEval (0-shot) | 84.05 | 84.41 | 100.43 | |
| GPQA (0-shot) | 33.14 | 32.55 | 98.22 | |
| Math-|v|-5 (4-shot) | 41.69 | 37.76 | 90.57 | |
| Average | 52.46 | 51.24 | 97.68 | |
| Coding | HumanEval_64 pass@2 | 88.88 | 88.84 | 99.95 |
lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
--apply_chat_template \
--fewshot_as_multiturn \
--tasks openllm \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
--apply_chat_template \
--fewshot_as_multiturn \
--tasks leaderboard \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.2-24B-Instruct-2506-NVFP4",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True,enforce_eager=True\
--apply_chat_template \
--fewshot_as_multiturn \
--tasks humaneval_64_instruct \
--batch_size auto