Views
No views yet


How many r in strawberry? without specialized prompting or additional reasoning tokens:A sweet question!
Let’s count the “R”s in “strawberry”:
1. S
2. T
3. R
4. A
5. W
6. B
7. E
8. R
9. R
10. Y
There are **3 “R”s** in the word “strawberry”.1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3model_id = "RedHatAI/Llama-3.1-Nemotron-70B-Instruct-HF"
4number_gpus = 4
5sampling_params = SamplingParams(temperature=0.7, top_p=0.8, max_tokens=256)
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7prompt = "Give me a short introduction to large language model."
8llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
9outputs = llm.generate(prompt, sampling_params)
10generated_text = outputs[0].outputs[0].text
11print(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-HF1# 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:1.51# Serve model via ilab
2ilab model serve --model-path ~/.cache/instructlab/models/llama-3-1-nemotron-70b-instruct-hf
3
4# Chat with model
5ilab model chat --model ~/.cache/instructlab/models/llama-3-1-nemotron-70b-instruct-hf1# 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 # OPTIONAL CHANGE
8 serving.kserve.io/deploymentMode: RawDeployment
9 name: Llama-3.1-Nemotron-70B-Instruct-HF # 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:1.5
31
32 tolerations:
33 - effect: NoSchedule
34 key: nvidia.com/gpu
35 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",
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}'| Model | Arena Hard | AlpacaEval | MT-Bench | Mean Response Length |
|---|---|---|---|---|
| Details | (95% CI) | 2 LC (SE) | (GPT-4-Turbo) | (# of Characters for MT-Bench) |
| Llama-3.1-Nemotron-70B-Instruct | 85.0 (-1.5, 1.5) | 57.6 (1.65) | 8.98 | 2199.8 |
| Llama-3.1-70B-Instruct | 55.7 (-2.9, 2.7) | 38.1 (0.90) | 8.22 | 1728.6 |
| Llama-3.1-405B-Instruct | 69.3 (-2.4, 2.2) | 39.3 (1.43) | 8.49 | 1664.7 |
| Claude-3-5-Sonnet-20240620 | 79.2 (-1.9, 1.7) | 52.4 (1.47) | 8.81 | 1619.9 |
| GPT-4o-2024-05-13 | 79.3 (-2.1, 2.0) | 57.5 (1.47) | 8.74 | 1752.2 |
meta-llama/Llama-3.1-70B-Instruct should support this model as well. If you run into problems, you can consider doing pip install -U transformers.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3model_name = "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF"
4model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6
7prompt = "How many r in strawberry?"
8messages = [{"role": "user", "content": prompt}]
9
10tokenized_message = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt", return_dict=True)
11response_token_ids = model.generate(tokenized_message['input_ids'].cuda(),attention_mask=tokenized_message['attention_mask'].cuda(), max_new_tokens=4096, pad_token_id = tokenizer.eos_token_id)
12generated_tokens =response_token_ids[:, len(tokenized_message['input_ids'][0]):]
13generated_text = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
14print(generated_text)
15
16# See response at top of model card1@misc{wang2024helpsteer2preferencecomplementingratingspreferences,
2 title={HelpSteer2-Preference: Complementing Ratings with Preferences},
3 author={Zhilin Wang and Alexander Bukharin and Olivier Delalleau and Daniel Egert and Gerald Shen and Jiaqi Zeng and Oleksii Kuchaiev and Yi Dong},
4 year={2024},
5 eprint={2410.01257},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/2410.01257},
9}