Sglang Cookbook
Deploying NVIDIA Nemotron-3-Nano with SGLang
This notebook will walk you through how to run the nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B model with SGLang.
SGLang is a fast serving framework for large language models and vision language models.
For more details on the model click here
Prerequisites:
- NVIDIA GPU with recent drivers (≥ 64 GB VRAM for BF16, ≥ 32 GB for FP8, ≥ 20 GB for NVFP4) and CUDA 12.x
- Python 3.10+
Launch on NVIDIA Brev
You can simplify the environment setup by using NVIDIA Brev. Click the button to launch this project on a Brev instance with the necessary dependencies pre-configured.
Once deployed, click on the "Open Notebook" button to get started with this guide.
For H100 (BF16/FP8 models):
For RTX PRO 6000 (NVFP4 model - requires Blackwell architecture):
Install dependencies
Looking in links: /tmp/tmp3hfrr9so Requirement already satisfied: pip in ./.venv/lib/python3.12/site-packages (25.0.1)
Additional Setup only for the NVFP4 Model (Blackwell GPUs):
- Install CUDA Toolkit and C++ compiler
sudo apt update
sudo apt install -y cuda-toolkit-12-8 g++ gcc build-essential
- Set environment variables (add to ~/.bashrc to make permanent)
export CUDA_HOME=/usr/local/cuda-12.8
export PATH=$CUDA_HOME/bin:$PATH
Verify GPU
Confirm CUDA is available and your GPU is visible to PyTorch.
CUDA available: True Num GPUs: 1 GPU[0]: NVIDIA H100 80GB HBM3
Start SGLang Server
SGLang runs as a separate server process.
Before starting the server, ensure that your notebook and terminal are in the same virtual environment.
Within Brev, open a terminal and run:
source /home/shadeform/.venv/bin/activate
Then, choose the desired model (BF16, FP8, or NVFP4) and run the following command in the terminal.
Load the BF16 version
python3 -m sglang.launch_server --model-path nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 \
--host 0.0.0.0 --port 5000 --log-level warning --trust-remote-code --tool-call-parser qwen3_coder --reasoning-parser deepseek-r1
Alternative: Load the FP8 quantized version for faster inference and lower memory usage
python3 -m sglang.launch_server --model-path nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-FP8 \
--host 0.0.0.0 --port 5000 --log-level warning --trust-remote-code --tool-call-parser qwen3_coder --reasoning-parser deepseek-r1
Alternative: Load the NVFP4 quantized version for high efficiency and lowest memory usage
python3 -m sglang.launch_server --model-path nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-NVFP4 --host 0.0.0.0 --port 5000 --log-level warning --trust-remote-code --tool-call-parser qwen3_coder --reasoning-parser deepseek-r1 --tp 1 --attention-backend flashinfer
Generate responses
OpenAI client configured to use server at: http://localhost:5000/v1 Using model: nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16
Simple vs streamed generation
User wants 3 bullet points about SGLang. Provide concise bullet points. Probably about SGLang being a programming language for tensor parallelism, etc. Provide three bullet points. - **High‑performance tensor‑parallel programming** – SGLang provides a Python‑embedded DSL that lets you write models once and automatically generate optimized kernels for CPUs, GPUs, and TPUs, handling parallelism and memory layout behind the scenes. - **Unified graph‑level and operator‑level optimizations** – It analyses the entire computation graph to fuse operators, schedule overlapping work, and select the best parallelism strategy (e.g., data‑parallel, model‑parallel, or hybrid) without manual tuning. - **Seamless integration with existing frameworks** – SGLang works with PyTorch, TensorFlow, and JAX models, offering drop‑in acceleration through simple annotations or a thin wrapper, enabling developers to speed up inference/training without rewriting their code.
The first 5 prime numbers are: 1. **2** (the only even prime number) 2. **3** 3. **5** 4. **7** 5. **11** ### Why these are prime: - **2**: Divisible only by 1 and 2. - **3**: Divisible only by 1 and 3. - **5**: Divisible only by 1 and 5. - **7**: Divisible only by 1 and 7. - **11**: Divisible only by 1 and 11. Numbers like 4, 6, 8, 9, and 10 are excluded because they have divisors other than 1 and themselves (e.g., 4 = 2×2, 6 = 2×3). Let me know if you'd like further clarification! 😊
Reasoning
Note: The model supports two modes - Reasoning ON (default) vs OFF. This can be toggled by setting enable_thinking to False, as shown below.
Reasoning on We need to output a haiku about GPUs. Probably 5-7-5 syllable structure. Something like "Silicon hearts beat fast / Parallel dreams in silicon / Gleam of shader light". Count syllables. First line 5 syllables: "Silicon hearts beat fast" = Si-li-con (3) hearts (1) beat (1) fast (1) = 6? Let's count: Si-li-con (3), hearts (1) =4, beat (1)=5, fast (1)=6. Too many. Maybe "Silicon hearts beat" = Silicon (3) hearts (1) beat (1) =5 good. Second line 7 syllables: "Parallel dreams take flight" = Par-al-lel (3) dreams (1)=4, take (1)=5, flight (1)=6. Need 7. Could be "Parallel dreams take flight" actually count: Par(1) al(2) lel(3) -> maybe 3? Actually "parallel" is 3 syllables (par-al-lel). So 3 + 1 (dreams) = 4, take 1 =5, flight 1 =6. Need 7. Add "high": "Parallel None Reasoning off Here are 3 interesting facts about **SGLang** (a programming language designed for efficient, scalable AI inference and training, particularly for large language models): 1. **Hardware-Aware Compilation for Accelerated Inference** SGLang compiles high-level models (e.g., PyTorch) into optimized code for **GPUs, TPUs, or custom accelerators** by fusing operations and leveraging low-level hardware features. Unlike traditional frameworks that require manual kernel tuning, SGLang automatically generates highly efficient kernels (e.g., for attention mechanisms), achieving **2–10x speedups** over PyTorch or TensorFlow without code changes. This makes it ideal for deploying large models on commodity hardware. 2. **Unified Runtime for Multi-Modal & Multi-Model Workloads** SGLang’s runtime natively supports **diverse model types** (e.g., LLMs, vision transformers, diffusion models) and **multiple hardware backends** (GPU, CPU, custom ASICs) through a single interface. It dynamically routes operations to the best-suited hardware (e.g., using GPU for attention and CPU for preprocessing), enabling seamless execution of complex pipelines like "text None
Tool calling
Call functions using the OpenAI Tools schema and inspect returned tool_calls.
Okay, the user wants to calculate a 15% tip on a $50 bill. Let me check the tools available. There's a calculate_tip function that takes bill_total and tip_percentage. The parameters are both required. The bill is $50, so bill_total is 50. The tip percentage is 15. I need to call the function with these values. Let me make sure the parameters are integers. Yes, 50 and 15 are both integers. So the tool call should be calculate_tip with arguments bill_total=50 and tip_percentage=15. That should give the tip amount.
[ChatCompletionMessageFunctionToolCall(id='call_69429ca05ecc4764a8e63ffa', function=Function(arguments='{"bill_total": 50, "tip_percentage": 15}', name='calculate_tip'), type='function', index=-1)]
Controlling Reasoning Budget
The reasoning_budget parameter allows you to limit the length of the model's reasoning trace. When the reasoning output reaches the specified token budget, the model will attempt to gracefully end the reasoning at the next newline character.
If no newline is encountered within 500 tokens after reaching the budget threshold, the reasoning trace will be forcibly terminated at reasoning_budget + 500 tokens to prevent excessive generation.
Reasoning: We need to comply with policy. It's a simple request: write a haiku about GPUs. No problem. Provide a haiku (5-7-5 syllable). Should be about GPUs. Just produce. We'll output a haiku. Make sure it's correct syllable count. Example: Silicon dreams hum (5) – Let's count: Sil-i-con (3) dreams (1) hum (1) =5. Next line 7 syllables: "shaders paint scenes of light" count: sha-ders (2) paint (1) scenes (1) of (1) light (1. Content: Silicon dreams hum Shaders paint scenes of bright light Pixels rise, swift and clear