Views
No views yet
0.6, and Top P to 0.95 for Reasoning ON mode4.44.2 or higher.1import torch
2import transformers
3
4model_id = "nvidia/Llama-3.1-Nemotron-Nano-4B-v1.1"
5model_kwargs = {"torch_dtype": torch.bfloat16, "device_map": "auto"}
6tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
7tokenizer.pad_token_id = tokenizer.eos_token_id
8
9pipeline = transformers.pipeline(
10 "text-generation",
11 model=model_id,
12 tokenizer=tokenizer,
13 max_new_tokens=32768,
14 temperature=0.6,
15 top_p=0.95,
16 **model_kwargs
17)
18
19# Thinking can be "on" or "off"
20thinking = "on"
21
22print(pipeline([{"role": "system", "content": f"detailed thinking {thinking}"}, {"role": "user", "content": "Solve x*(sin(x)+2)=0"}]))1import torch
2import transformers
3
4model_id = "nvidia/Llama-3.1-Nemotron-Nano-4B-v1"
5model_kwargs = {"torch_dtype": torch.bfloat16, "device_map": "auto"}
6tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
7tokenizer.pad_token_id = tokenizer.eos_token_id
8
9pipeline = transformers.pipeline(
10 "text-generation",
11 model=model_id,
12 tokenizer=tokenizer,
13 max_new_tokens=32768,
14 do_sample=False,
15 **model_kwargs
16)
17
18# Thinking can be "on" or "off"
19thinking = "off"
20
21print(pipeline([{"role": "system", "content": f"detailed thinking {thinking}"}, {"role": "user", "content": "Solve x*(sin(x)+2)=0"}]))1import torch
2import transformers
3
4model_id = "nvidia/Llama-3.1-Nemotron-Nano-4B-v1.1"
5model_kwargs = {"torch_dtype": torch.bfloat16, "device_map": "auto"}
6tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
7tokenizer.pad_token_id = tokenizer.eos_token_id
8
9# Thinking can be "on" or "off"
10thinking = "off"
11
12pipeline = transformers.pipeline(
13 "text-generation",
14 model=model_id,
15 tokenizer=tokenizer,
16 max_new_tokens=32768,
17 do_sample=False,
18 **model_kwargs
19)
20
21print(pipeline([{"role": "system", "content": f"detailed thinking {thinking}"}, {"role": "user", "content": "Solve x*(sin(x)+2)=0"}, {"role":"assistant", "content":"<think>\n</think>"}]))vllm/vllm-openai:v0.6.6 or newer should support the model.1#!/bin/bash
2
3CWD=$(pwd)
4PORT=5000
5git clone https://huggingface.co/nvidia/Llama-3.1-Nemotron-Nano-4B-v1.1
6docker run -it --rm \
7 --runtime=nvidia \
8 --gpus all \
9 --shm-size=16GB \
10 -p ${PORT}:${PORT} \
11 -v ${CWD}:${CWD} \
12 vllm/vllm-openai:v0.6.6 \
13 --model $CWD/Llama-3.1-Nemotron-Nano-4B-v1.1 \
14 --trust-remote-code \
15 --seed 1 \
16 --host "0.0.0.0" \
17 --port $PORT \
18 --served-model-name "Llama-Nemotron-Nano-4B-v1.1" \
19 --tensor-parallel-size 1 \
20 --max-model-len 131072 \
21 --gpu-memory-utilization 0.95 \
22 --enforce-eager \
23 --enable-auto-tool-choice \
24 --tool-parser-plugin "${CWD}/Llama-3.1-Nemotron-Nano-4B-v1.1/llama_nemotron_nano_toolcall_parser.py" \
25 --tool-call-parser "llama_nemotron_json" \
26 --chat-template "${CWD}/Llama-3.1-Nemotron-Nano-4B-v1.1/llama_nemotron_nano_generic_tool_calling.jinja"1$ git clone https://huggingface.co/nvidia/Llama-3.1-Nemotron-Nano-4B-v1.1
2
3$ conda create -n vllm python=3.12 -y
4$ conda activate vllm
5
6$ python -m vllm.entrypoints.openai.api_server \
7 --model Llama-3.1-Nemotron-Nano-4B-v1.1 \
8 --trust-remote-code \
9 --seed 1 \
10 --host "0.0.0.0" \
11 --port 5000 \
12 --served-model-name "Llama-Nemotron-Nano-4B-v1.1" \
13 --tensor-parallel-size 1 \
14 --max-model-len 131072 \
15 --gpu-memory-utilization 0.95 \
16 --enforce-eager \
17 --enable-auto-tool-choice \
18 --tool-parser-plugin "Llama-3.1-Nemotron-Nano-4B-v1.1/llama_nemotron_nano_toolcall_parser.py" \
19 --tool-call-parser "llama_nemotron_json" \
20 --chat-template "Llama-3.1-Nemotron-Nano-4B-v1.1/llama_nemotron_nano_generic_tool_calling.jinja"1>>> from openai import OpenAI
2>>> client = OpenAI(
3 base_url="http://0.0.0.0:5000/v1",
4 api_key="dummy",
5 )
6
7>>> completion = client.chat.completions.create(
8 model="Llama-Nemotron-Nano-v1.1",
9 messages=[
10 {"role": "system", "content": "detailed thinking on"},
11 {"role": "user", "content": "My bill is $100. What will be the amount for 18% tip?"},
12 ],
13 tools=[
14 {"type": "function", "function": {"name": "calculate_tip", "parameters": {"type": "object", "properties": {"bill_total": {"type": "integer", "description": "The total amount of the bill"}, "tip_percentage": {"type": "integer", "description": "The percentage of tip to be applied"}}, "required": ["bill_total", "tip_percentage"]}}},
15 {"type": "function", "function": {"name": "convert_currency", "parameters": {"type": "object", "properties": {"amount": {"type": "integer", "description": "The amount to be converted"}, "from_currency": {"type": "string", "description": "The currency code to convert from"}, "to_currency": {"type": "string", "description": "The currency code to convert to"}}, "required": ["from_currency", "amount", "to_currency"]}}},
16 ],
17 )
18
19>>> completion.choices[0].message.content
20'<think>\nOkay, let\'s see. The user has a bill of $100 and wants to know the amount of a 18% tip. So, I need to calculate the tip amount. The available tools include calculate_tip, which requires bill_total and tip_percentage. The parameters are both integers. The bill_total is 100, and the tip percentage is 18. So, the function should multiply 100 by 18% and return 18.0. But wait, maybe the user wants the total including the tip? The question says "the amount for 18% tip," which could be interpreted as the tip amount itself. Since the function is called calculate_tip, it\'s likely that it\'s designed to compute the tip, not the total. So, using calculate_tip with bill_total=100 and tip_percentage=18 should give the correct result. The other function, convert_currency, isn\'t relevant here. So, I should call calculate_tip with those values.\n</think>\n\n'
21
22>>> completion.choices[0].message.tool_calls
23[ChatCompletionMessageToolCall(id='chatcmpl-tool-2972d86817344edc9c1e0f9cd398e999', function=Function(arguments='{"bill_total": 100, "tip_percentage": 18}', name='calculate_tip'), type='function')]