Views
No views yet


1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3
4model_id = "RedHatAI/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic"
5number_gpus = 2
6
7sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
8
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11messages = [
12 {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
13 {"role": "user", "content": "Who are you?"},
14]
15
16prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
17
18llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
19
20outputs = llm.generate(prompts, sampling_params)
21
22generated_text = outputs[0].outputs[0].text
23print(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/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic1# 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/llama-3-1-nemotron-70b-instruct-hf-fp8-dynamic:1.51# Serve model via ilab
2ilab model serve --model-path ~/.cache/instructlab/models/llama-3-1-nemotron-70b-instruct-hf-fp8-dynamic
3
4# Chat with model
5ilab model chat --model ~/.cache/instructlab/models/llama-3-1-nemotron-70b-instruct-hf-fp8-dynamic1# 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: Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic # OPTIONAL CHANGE
8 serving.kserve.io/deploymentMode: RawDeployment
9 name: Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic # 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-llama-3-1-nemotron-70b-instruct-hf-fp8-dynamic: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# 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": "Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",
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}'1import torch
2
3from transformers import AutoTokenizer
4
5from llmcompressor.transformers import SparseAutoModelForCausalLM, oneshot
6from llmcompressor.transformers.compression.helpers import ( # noqa
7 calculate_offload_device_map,
8 custom_offload_device_map,
9)
10
11recipe = """
12quant_stage:
13 quant_modifiers:
14 QuantizationModifier:
15 ignore: ["lm_head"]
16 config_groups:
17 group_0:
18 weights:
19 num_bits: 8
20 type: float
21 strategy: channel
22 dynamic: false
23 symmetric: true
24 input_activations:
25 num_bits: 8
26 type: float
27 strategy: token
28 dynamic: true
29 symmetric: true
30 targets: ["Linear"]
31"""
32
33model_stub = "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF"
34model_name = model_stub.split("/")[-1]
35
36device_map = calculate_offload_device_map(
37 model_stub, reserve_for_hessians=False, num_gpus=1, torch_dtype="auto"
38)
39
40model = SparseAutoModelForCausalLM.from_pretrained(
41 model_stub, torch_dtype="auto", device_map=device_map
42)
43
44output_dir = f"./{model_name}-FP8-dynamic"
45
46oneshot(
47 model=model,
48 recipe=recipe,
49 output_dir=output_dir,
50 save_compressed=True,
51 tokenizer=AutoTokenizer.from_pretrained(model_stub),
52)| Benchmark | nvidia/Llama-3.1-Nemotron-70B-Instruct-HF | neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic (this model) | Recovery |
| Arena Hard | 85.0 | 84.5 | 99.41% |
| OpenLLM Leaderboard v1 | 80.1 | 80.3 | 100.2% |
| OpenLLM Leaderboard v2 | 40.2 | 39.8 | 99.0% |
| Benchmark (per-task breakdown) | nvidia/Llama-3.1-Nemotron-70B-Instruct-HF | neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic (this model) | Recovery |
| OpenLLM v1 | |||
| MMLU (5-shot) | 83.51 | 83.49 | 99.97% |
| MMLU-cot (0-shot) | 85.89 | 86.18 | 100.33% |
| ARC Challenge (0-shot) | 93.09 | 93.09 | 100% |
| GSM-8K-cot (8-shot, strict-match) | 70.13 | 69.98 | 99.78% |
| Hellaswag (10-shot) | 87.39 | 87.22 | 99.80% |
| Winogrande (5-shot) | 84.93 | 84.93 | 100% |
| TruthfulQA (0-shot, mc2) | 55.97 | 57.12 | 102.05% |
| Average | 80.1 | 80.3 | 100.2% |
| OpenLLM v2 | |||
| MMLU-Pro (5-shot) | 43.45 | 42.99 | 98.94% |
| IFEval (0-shot) | 73.32 | 74.08 | 101.02% |
| BBH (3-shot) | 47.12 | 46.88 | 99.5% |
| Math-lvl-5 (4-shot) | 23.85 | 21.78 | 91.32% |
| MuSR (0-shot) | 13.5 | 13.35 | 98.88% |
| Average | 40.2 | 39.8 | 99% |
lm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
--tasks mmlu \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
--tasks mmlu_cot_0shot_llama_3.1_instruct \
--apply_chat_template \
--num_fewshot 0 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
--tasks arc_challenge_llama_3.1_instruct \
--apply_chat_template \
--num_fewshot 0 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
--tasks gsm8k_cot_llama_3.1_instruct \
--apply_chat_template \
--fewshot_as_multiturn \
--num_fewshot 8 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
--tasks hellaswag \
--num_fewshot 10 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
--tasks winogrande \
--num_fewshot 5 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",dtype=auto,add_bos_token=True,max_model_len=4096,tensor_parallel_size=2 \
--tasks truthfulqa \
--num_fewshot 0 \
--batch_size autolm_eval \
--model vllm \
--model_args pretrained="neuralmagic/Llama-3.1-Nemotron-70B-Instruct-HF-FP8-dynamic",dtype=auto,max_model_len=4096,tensor_parallel_size=2,enable_chunked_prefill=True \
--apply_chat_template \
--fewshot_as_multiturn \
--tasks leaderboard \
--batch_size auto