翻篇收录说明
翻篇网页快照

SGLang Deployment & Inference Guide | Unsloth Documentation

https://unsloth.ai/docs/basics/inference-and-deployment/sglang-guide

最近抓取:2026-12-04 23:32:13(北京时间)

最近内容变化:2026-12-02 11:00:25(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Guide on saving and deploying LLMs to SGLang for serving LLMs in production

正文摘录

You can serve any LLM or fine-tuned model via SGLang for low-latency, high-throughput inference. SGLang supports text, image/video model inference on any GPU setup, with support for some GGUFs.💻Installing SGLangTo install SGLang and Unsloth on NVIDIA GPUs, you can use the below in a virtual environment (which won't break your other Python libraries)AskCopy# OPTIONAL use a virtual environment python -m venv unsloth_env source unsloth_env/bin/activate # Install Rust, outlines-core then SGLang curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env && sudo apt-get install -y pkg-config libssl-dev pip install --upgrade pip && pip install uv uv pip install "sglang" && uv pip install unslothFor Docker setups run:AskCopydocker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server --model-path unsloth/Llama-3.1-8B-Instruct --host 0.0.0.0 --port 30000🐛Debugging SGLang Installation issuesNote if you see the below, update Rust and outlines-core as specified in SGLangIf you see a Flashinfer issue like below:Remove the flashinfer cache via rm -rf .cache/flashinfer and also the directory listed in the error message ie rm -rf ~/.cache/flashinfer🚚Deploying SGLang modelsTo deploy any model like for example unsloth/Llama-3.2-1B-Instruct, do the below in a separate terminal (otherwise it'll block your current terminal - you can also use tmux):You can then use the OpenAI Chat completions library to call the model (in another terminal or using tmux):And you will get 2 + 2 = 4.🦥Deploying Unsloth finetunes in SGLangAfter fine-tuning Fine-tuning Guide or using our notebooks at Unsloth Notebooks, you can save or deploy your models directly through SGLang within a single workflow. An example Unsloth finetuning script for eg:To save to 16-bit for SGLang, use:To save just the LoRA adapters, either use:Or just use our builtin function to do that:🚃gpt-oss-20b: Unsloth & SGLang Deployment GuideBelow is a step-by-step tutorial with instructions for training the gpt-oss-20b using Unsloth and deploying it with SGLang. It includes performance benchmarks across multiple quantization formats.1Unsloth Fine-tuning and Exporting FormatsIf you're new to fine-tuning, you can read our guide, or try the gpt-oss 20B finetuning notebook at gpt-oss After training, you can export the model in multiple formats:2Deployment with SGLangWe saved our gpt-oss finetune to the folder "finetuned_model", and so in a new terminal, we can launch the finetuned model as an inference endpoint with SGLang:You might have to wait a bit on Capturing batches (bs=1 avail_mem=20.84 GB): !3Calling the inference endpoint:To call the inference endpoint, first launch a new terminal. We then can call the model like below:💎FP8 Online QuantizationTo deploy models with FP8 online quantization which allows 30 to 50% more throughput and 50% less memory usage with 2x longer context length supports with SGLang, you can do the below:You can also use --kv-cache-dtype fp8_e5m2 which has a larger dynamic range which might solve FP8 inference issues if you see them. Or use our pre-quantized float8 quants listed in https://huggingface.co/unsloth/models?search=-fp8 or some are listed below:unsloth/Llama-3.2-3B-FP8-Dynamic · Hugging Facehuggingfaceunsloth/Llama-3.3-70B-Instruct-FP8-Dynamic · Hugging Facehuggingface⚡Benchmarking SGLangBelow is some code you can run to test the performance speed of your finetuned model:Then in another terminal or via tmux:You will see the benchmarking run like below:We used a B200x1 GPU with gpt-oss-20b and got the below results (~2,500 tokens throughput)Batch/Input/OutputTTFT (s)ITL (s)Input ThroughputOutput Throughput8/1024/10240.403.5920,718.952,562.878/8192/10240.423.74154,459.012,473.84See https://docs.sglang.ai/advanced_features/server_arguments.html for server arguments for SGLang.🏃SGLang Interactive Offline ModeYou can also use SGLang in offline mode (ie not a server) inside a Python interactive environment.🎇GGUFs in SGLangSGLang also interestingly supports GGUFs! Qwen3 MoE is still under construction, but most dense models (Llama 3, Qwen 3, Mistral etc) are supported.First install the latest gguf python package via:Then for example in offline mode SGLang, you can do:🎬High throughput GGUF serving with SGLangFirst download the specific GGUF file like below:Then serve the specific file Qwen3-32B-UD-Q4_K_XL.gguf and use --served-model-name unsloth/Qwen3-32B and also we need the HuggingFace compatible tokenizer via --tokenizer-pathPreviousLoRA Hot Swapping GuideNextllama-serverLast updated 10 months agoWas this helpful?