Views
No views yet


vllm serve RedHatAI/Mistral-Small-24B-Instruct-2501-quantized.w4a16 --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-24B-Instruct-2501-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--max-model-len 32768 \
10--enforce-eager --model RedHatAI/Mistral-Small-24B-Instruct-2501-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-24b-instruct-2501-quantized-w4a16:1.51# Serve model via ilab
2ilab model serve --model-path ~/.cache/instructlab/models/mistral-small-24b-instruct-2501-quantized-w4a16 --gpu 1 -- --trust-remote-code
3
4# Chat with model
5ilab model chat --model ~/.cache/instructlab/models/mistral-small-24b-instruct-2501-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-24B-Instruct-2501-quantized.w4a16 # OPTIONAL CHANGE
8 serving.kserve.io/deploymentMode: RawDeployment
9 name: Mistral-Small-24B-Instruct-2501-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 args:
18 - "--trust-remote-code"
19 modelFormat:
20 name: vLLM
21 name: ''
22 resources:
23 limits:
24 cpu: '2' # this is model specific
25 memory: 8Gi # this is model specific
26 nvidia.com/gpu: '1' # this is accelerator specific
27 requests: # same comment for this block
28 cpu: '1'
29 memory: 4Gi
30 nvidia.com/gpu: '1'
31 runtime: vllm-cuda-runtime # must match the ServingRuntime name above
32 storageUri: oci://registry.redhat.io/rhelai1/modelcar-mistral-small-24b-instruct-2501-quantized-w4a16:1.5
33 tolerations:
34 - effect: NoSchedule
35 key: nvidia.com/gpu
36 operator: Exists1# make sure first to be in the project where you want to deploy the model
2# oc project <project-name>
3# apply both resources to run model
4# Apply the ServingRuntime
5oc apply -f vllm-servingruntime.yaml
6# Apply the InferenceService
7oc 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# Call the server using curl:
4curl https://<inference-service-name>-predictor-default.<domain>/v1/chat/completions
5 -H "Content-Type: application/json" \
6 -d '{
7 "model": "Mistral-Small-24B-Instruct-2501-quantized.w4a16",
8 "stream": true,
9 "stream_options": {
10 "include_usage": true
11 },
12 "max_tokens": 1,
13 "messages": [
14 {
15 "role": "user",
16 "content": "How can a bee fly when its wings are so small?"
17 }
18 ]
19}'python quantize.py --model_path mistralai/Mistral-Small-24B-Instruct-2501 --quant_path "output_dir" --calib_size 1024 --dampening_frac 0.05 --observer minmax --actorder false1from datasets import load_dataset
2from transformers import AutoTokenizer
3from llmcompressor.modifiers.quantization import GPTQModifier
4from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot, apply
5import argparse
6from compressed_tensors.quantization import QuantizationScheme, QuantizationArgs, QuantizationType, QuantizationStrategy
7
8def parse_actorder(value):
9 # Interpret the input value for --actorder
10 if value.lower() == "false":
11 return False
12 elif value.lower() == "group":
13 return "group"
14 elif value.lower() == "weight":
15 return "weight"
16 else:
17 raise argparse.ArgumentTypeError("Invalid value for --actorder. Use 'group' or 'False'.")
18
19
20parser = argparse.ArgumentParser()
21parser.add_argument('--model_path', type=str)
22parser.add_argument('--quant_path', type=str)
23parser.add_argument('--num_bits', type=int, default=4)
24parser.add_argument('--sequential_update', type=bool, default=True)
25parser.add_argument('--calib_size', type=int, default=256)
26parser.add_argument('--dampening_frac', type=float, default=0.05)
27parser.add_argument('--observer', type=str, default="minmax")
28parser.add_argument(
29 '--actorder',
30 type=parse_actorder,
31 default=False, # Default value is False
32 help="Specify actorder as 'group' (string) or False (boolean)."
33)
34
35args = parser.parse_args()
36
37model = SparseAutoModelForCausalLM.from_pretrained(
38 args.model_path,
39 device_map="auto",
40 torch_dtype="auto",
41 use_cache=False,
42)
43tokenizer = AutoTokenizer.from_pretrained(args.model_path)
44
45NUM_CALIBRATION_SAMPLES = args.calib_size
46DATASET_ID = "garage-bAInd/Open-Platypus"
47DATASET_SPLIT = "train"
48ds = load_dataset(DATASET_ID, split=DATASET_SPLIT)
49ds = ds.shuffle(seed=42).select(range(NUM_CALIBRATION_SAMPLES))
50
51def preprocess(example):
52 concat_txt = example["instruction"] + "\n" + example["output"]
53 return {"text": concat_txt}
54
55ds = ds.map(preprocess)
56
57def tokenize(sample):
58 return tokenizer(
59 sample["text"],
60 padding=False,
61 truncation=False,
62 add_special_tokens=True,
63 )
64
65
66ds = ds.map(tokenize, remove_columns=ds.column_names)
67
68quant_scheme = QuantizationScheme(
69 targets=["Linear"],
70 weights=QuantizationArgs(
71 num_bits=args.num_bits,
72 type=QuantizationType.INT,
73 symmetric=True,
74 group_size=128,
75 strategy=QuantizationStrategy.GROUP,
76 observer=args.observer,
77 actorder=args.actorder
78 ),
79 input_activations=None,
80 output_activations=None,
81)
82
83recipe = [
84 GPTQModifier(
85 targets=["Linear"],
86 ignore=["lm_head"],
87 sequential_update=args.sequential_update,
88 dampening_frac=args.dampening_frac,
89 config_groups={"group_0": quant_scheme},
90 )
91]
92oneshot(
93 model=model,
94 dataset=ds,
95 recipe=recipe,
96 num_calibration_samples=args.calib_size,
97)
98
99# Save to disk compressed.
100SAVE_DIR = args.quant_path
101model.save_pretrained(SAVE_DIR, save_compressed=True)
102tokenizer.save_pretrained(SAVE_DIR)lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Mistral-Small-24B-Instruct-2501-quantized.w4a16",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=1,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
--tasks openllm \
--write_out \
--batch_size auto \
--output_path output_dir \
--show_configlm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Mistral-Small-24B-Instruct-2501-quantized.w4a16",dtype=auto,add_bos_token=False,max_model_len=4096,tensor_parallel_size=1,gpu_memory_utilization=0.8,enable_chunked_prefill=True,trust_remote_code=True \
--apply_chat_template \
--fewshot_as_multiturn \
--tasks leaderboard \
--write_out \
--batch_size auto \
--output_path output_dir \
--show_config
| Metric | mistralai/Mistral-Small-24B-Instruct-2501 | neuralmagic/Mistral-Small-24B-Instruct-2501-quantized.w4a16 |
|---|---|---|
| ARC-Challenge (Acc-Norm, 25-shot) | 72.18 | 71.16 |
| GSM8K (Strict-Match, 5-shot) | 90.14 | 89.69 |
| HellaSwag (Acc-Norm, 10-shot) | 85.05 | 84.43 |
| MMLU (Acc, 5-shot) | 80.69 | 80.00 |
| TruthfulQA (MC2, 0-shot) | 65.55 | 63.92 |
| Winogrande (Acc, 5-shot) | 83.11 | 82.24 |
| Average Score | 79.45 | 78.57 |
| Recovery (%) | 100.00 | 98.9 |
| Metric | mistralai/Mistral-Small-24B-Instruct-2501 | neuralmagic/Mistral-Small-24B-Instruct-2501-quantized.w4a16 |
|---|---|---|
| IFEval (Inst-and-Prompt Level Strict Acc, 0-shot) | 73.27 | 74.37 |
| BBH (Acc-Norm, 3-shot) | 45.18 | 45.15 |
| MMLU-Pro (Acc, 5-shot) | 38.83 | 36.00 |
| Average Score | 52.42 | 51.84 |
| Recovery (%) | 100.00 | 98.89 |
| GPQA (Acc-Norm, 0-shot) | 8.29 | 6.81 |
| MUSR (Acc-Norm, 0-shot) | 7.84 | 9.46 |