Views
No views yet


vllm serve RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16 --tokenizer_mode mistral --config-format 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.1-24B-Instruct-2503-quantized.w4a16"
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)1podman run --rm -it --device nvidia.com/gpu=all -p 8000:8000 \
2 --ipc=host \
3--env "HUGGING_FACE_HUB_TOKEN=$HF_TOKEN" \
4--env "HF_HUB_OFFLINE=0" -v ~/.cache/vllm:/home/vllm/.cache \
5--name=vllm \
6registry.access.redhat.com/rhaiis/rh-vllm-cuda \
7vllm serve \
8--tensor-parallel-size 8 \
9--config-format mistral \
10--max-model-len 32768 \
11--enforce-eager --model RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a161# Download model from Red Hat Registry via docker
2# Note: This downloads the model to ~/.cache/instructlab/models unless --model-dir is specified.
3ilab model download --repository docker://registry.redhat.io/rhelai1/mistral-small-3-1-24b-instruct-2503-quantized-w4a16:1.51# Serve model via ilab
2ilab model serve --model-path ~/.cache/instructlab/models/mistral-small-3-1-24b-instruct-2503-quantized-w4a16
3
4# Chat with model
5ilab model chat --model ~/.cache/instructlab/models/mistral-small-3-1-24b-instruct-2503-quantized-w4a161# Setting up vllm server with ServingRuntime
2# Save as: vllm-servingruntime.yaml
3apiVersion: serving.kserve.io/v1alpha1
4kind: ServingRuntime
5metadata:
6 name: vllm-cuda-runtime # OPTIONAL CHANGE: set a unique name
7 annotations:
8 openshift.io/display-name: vLLM NVIDIA GPU ServingRuntime for KServe
9 opendatahub.io/recommended-accelerators: '["nvidia.com/gpu"]'
10 labels:
11 opendatahub.io/dashboard: 'true'
12spec:
13 annotations:
14 prometheus.io/port: '8080'
15 prometheus.io/path: '/metrics'
16 multiModel: false
17 supportedModelFormats:
18 - autoSelect: true
19 name: vLLM
20 containers:
21 - name: kserve-container
22 image: quay.io/modh/vllm:rhoai-2.20-cuda # CHANGE if needed. If AMD: quay.io/modh/vllm:rhoai-2.20-rocm
23 command:
24 - python
25 - -m
26 - vllm.entrypoints.openai.api_server
27 args:
28 - "--port=8080"
29 - "--model=/mnt/models"
30 - "--served-model-name={{.Name}}"
31 env:
32 - name: HF_HOME
33 value: /tmp/hf_home
34 ports:
35 - containerPort: 8080
36 protocol: TCP1# Attach model to vllm server. This is an NVIDIA template
2# Save as: inferenceservice.yaml
3apiVersion: serving.kserve.io/v1beta1
4kind: InferenceService
5metadata:
6 annotations:
7 openshift.io/display-name: mistral-small-3-1-24b-instruct-2503-quantized-w4a16 # OPTIONAL CHANGE
8 serving.kserve.io/deploymentMode: RawDeployment
9 name: mistral-small-3-1-24b-instruct-2503-quantized-w4a16 # specify model name. This value will be used to invoke the model in the payload
10 labels:
11 opendatahub.io/dashboard: 'true'
12spec:
13 predictor:
14 maxReplicas: 1
15 minReplicas: 1
16 model:
17 modelFormat:
18 name: vLLM
19 name: ''
20 resources:
21 limits:
22 cpu: '2' # this is model specific
23 memory: 8Gi # this is model specific
24 nvidia.com/gpu: '1' # this is accelerator specific
25 requests: # same comment for this block
26 cpu: '1'
27 memory: 4Gi
28 nvidia.com/gpu: '1'
29 runtime: vllm-cuda-runtime # must match the ServingRuntime name above
30 storageUri: oci://registry.redhat.io/rhelai1/modelcar-mistral-small-3-1-24b-instruct-2503-quantized-w4a16:1.5
31 tolerations:
32 - effect: NoSchedule
33 key: nvidia.com/gpu
34 operator: Exists1# make sure first to be in the project where you want to deploy the model
2# oc project <project-name>
3
4# apply both resources to run model
5
6# Apply the ServingRuntime
7oc apply -f vllm-servingruntime.yaml
8
9# Apply the InferenceService
10oc apply -f qwen-inferenceservice.yaml1# Replace <inference-service-name> and <cluster-ingress-domain> below:
2# - Run `oc get inferenceservice` to find your URL if unsure.
3
4# Call the server using curl:
5curl https://<inference-service-name>-predictor-default.<domain>/v1/chat/completions
6 -H "Content-Type: application/json" \
7 -d '{
8 "model": "mistral-small-3-1-24b-instruct-2503-quantized-w4a16",
9 "stream": true,
10 "stream_options": {
11 "include_usage": true
12 },
13 "max_tokens": 1,
14 "messages": [
15 {
16 "role": "user",
17 "content": "How can a bee fly when its wings are so small?"
18 }
19 ]
20}'
211from transformers import AutoProcessor
2from llmcompressor.modifiers.quantization import GPTQModifier
3from llmcompressor.transformers import oneshot
4from llmcompressor.transformers.tracing import TraceableMistral3ForConditionalGeneration
5from datasets import load_dataset, interleave_datasets
6from PIL import Image
7import io
8
9# Load model
10model_stub = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
11model_name = model_stub.split("/")[-1]
12
13num_text_samples = 1024
14num_vision_samples = 1024
15max_seq_len = 8192
16
17processor = AutoProcessor.from_pretrained(model_stub)
18
19model = TraceableMistral3ForConditionalGeneration.from_pretrained(
20 model_stub,
21 device_map="auto",
22 torch_dtype="auto",
23)
24
25# Text-only data subset
26def preprocess_text(example):
27 input = {
28 "text": processor.apply_chat_template(
29 example["messages"],
30 add_generation_prompt=False,
31 ),
32 "images": None,
33 }
34 tokenized_input = processor(**input, max_length=max_seq_len, truncation=True)
35 tokenized_input["pixel_values"] = tokenized_input.get("pixel_values", None)
36 tokenized_input["image_sizes"] = tokenized_input.get("image_sizes", None)
37 return tokenized_input
38
39dst = load_dataset("neuralmagic/calibration", name="LLM", split="train").select(range(num_text_samples))
40dst = dst.map(preprocess_text, remove_columns=dst.column_names)
41
42# Text + vision data subset
43def preprocess_vision(example):
44 messages = []
45 image = None
46 for message in example["messages"]:
47 message_content = []
48 for content in message["content"]:
49 if content["type"] == "text":
50 message_content.append({"type": "text", "text": content["text"]})
51 else:
52 message_content.append({"type": "image"})
53 image = Image.open(io.BytesIO(content["image"]))
54
55 messages.append(
56 {
57 "role": message["role"],
58 "content": message_content,
59 }
60 )
61
62 input = {
63 "text": processor.apply_chat_template(
64 messages,
65 add_generation_prompt=False,
66 ),
67 "images": image,
68 }
69 tokenized_input = processor(**input, max_length=max_seq_len, truncation=True)
70 tokenized_input["pixel_values"] = tokenized_input.get("pixel_values", None)
71 tokenized_input["image_sizes"] = tokenized_input.get("image_sizes", None)
72 return tokenized_input
73
74dsv = load_dataset("neuralmagic/calibration", name="VLM", split="train").select(range(num_vision_samples))
75dsv = dsv.map(preprocess_vision, remove_columns=dsv.column_names)
76
77# Interleave subsets
78ds = interleave_datasets((dsv, dst))
79
80# Configure the quantization algorithm and scheme
81recipe = GPTQModifier(
82 ignore=["language_model.lm_head", "re:vision_tower.*", "re:multi_modal_projector.*"],
83 sequential_targets=["MistralDecoderLayer"],
84 dampening_frac=0.01,
85 targets="Linear",
86 scheme="W4A16",
87)
88
89# Define data collator
90def data_collator(batch):
91 import torch
92 assert len(batch) == 1
93 collated = {}
94 for k, v in batch[0].items():
95 if v is None:
96 continue
97 if k == "input_ids":
98 collated[k] = torch.LongTensor(v)
99 elif k == "pixel_values":
100 collated[k] = torch.tensor(v, dtype=torch.bfloat16)
101 else:
102 collated[k] = torch.tensor(v)
103 return collated
104
105
106# Apply quantization
107oneshot(
108 model=model,
109 dataset=ds,
110 recipe=recipe,
111 max_seq_length=max_seq_len,
112 data_collator=data_collator,
113 num_calibration_samples=num_text_samples + num_vision_samples,
114)
115
116# Save to disk in compressed-tensors format
117save_path = model_name + "-quantized.w4a16"
118model.save_pretrained(save_path)
119processor.save_pretrained(save_path)
120print(f"Model and tokenizer saved to: {save_path}")lm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks mmlu \
--num_fewshot 5 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks arc_challenge \
--num_fewshot 25 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.9,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks gsm8k \
--num_fewshot 8 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks hellaswag \
--num_fewshot 10 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks winogrande \
--num_fewshot 5 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks truthfulqa \
--num_fewshot 0 \
--apply_chat_template\
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.5,max_model_len=8192,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks mmlu_pro \
--num_fewshot 5 \
--apply_chat_template\
--fewshot_as_multiturn \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.9,max_images=8,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks mmmu_val \
--apply_chat_template\
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16",dtype=auto,gpu_memory_utilization=0.9,max_images=8,enable_chunk_prefill=True,tensor_parallel_size=2 \
--tasks chartqa \
--apply_chat_template\
--batch_size autopython3 codegen/generate.py \
--model RedHatAI/Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16 \
--bs 16 \
--temperature 0.2 \
--n_samples 50 \
--root "." \
--dataset humaneval
python3 evalplus/sanitize.py \
humaneval/RedHatAI--Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16_vllm_temp_0.2evalplus.evaluate \
--dataset humaneval \
--samples humaneval/RedHatAI--Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16_vllm_temp_0.2-sanitized| Category | Benchmark | Mistral-Small-3.1-24B-Instruct-2503 | Mistral-Small-3.1-24B-Instruct-2503-quantized.w4a16 (this model) | Recovery |
|---|---|---|---|---|
| OpenLLM v1 | MMLU (5-shot) | 80.67 | 79.74 | 98.9% |
| ARC Challenge (25-shot) | 72.78 | 72.18 | 99.2% | |
| GSM-8K (5-shot, strict-match) | 58.68 | 59.59 | 101.6% | |
| Hellaswag (10-shot) | 83.70 | 83.25 | 99.5% | |
| Winogrande (5-shot) | 83.74 | 83.43 | 99.6% | |
| TruthfulQA (0-shot, mc2) | 70.62 | 69.56 | 98.5% | |
| Average | 75.03 | 74.63 | 99.5% | |
| MMLU-Pro (5-shot) | 67.25 | 66.56 | 99.0% | |
| GPQA CoT main (5-shot) | 42.63 | 47.10 | 110.5% | |
| GPQA CoT diamond (5-shot) | 45.96 | 44.95 | 97.80% | |
| Coding | HumanEval pass@1 | 84.70 | 84.60 | 99.9% |
| HumanEval+ pass@1 | 79.50 | 79.90 | 100.5% | |
| MBPP pass@1 | 71.10 | 70.10 | 98.6% | |
| MBPP+ pass@1 | 60.60 | 60.70 | 100.2% | |
| Vision | MMMU (0-shot) | 52.11 | 50.11 | 96.2% |
| ChartQA (0-shot) | 81.36 | 80.92 | 99.5% | |