Profiling SGLang
Run SGLang with the Zymtrace GPU profiler injected, on NVIDIA or AMD GPUs. The examples serve zai-org/GLM-4-9B-0414 (~19 GB of BF16 weights) with CUDA or HIP graphs enabled, which is SGLang's default. Check the prerequisites first.
- NVIDIA (CUDA)
- AMD (ROCm)
- Kubernetes (Helm)
- Docker
- Binary
Install the Zymtrace profiler on your cluster with Helm and enable the CUDA profiler (--set profiler.cudaProfiler.enabled=true). It extracts the CUDA profiler library to /var/lib/zymtrace/profiler on every GPU node. See Install with Helm.
The manifest mounts /var/lib/zymtrace/profiler from the node and sets CUDA_INJECTION64_PATH, as described in Kubernetes GPU configuration. These are the fields that enable profiling:
spec:
template:
spec:
hostIPC: true
containers:
- name: sglang
image: lmsysorg/sglang:v0.5.22
command: ["python3", "-m", "sglang.launch_server"]
args: ["--model-path", "zai-org/GLM-4-9B-0414", "--host", "0.0.0.0", "--port", "30000", "--enable-metrics"]
env:
- name: CUDA_INJECTION64_PATH
value: /opt/zymtrace/profiler/libzymtracecudaprofiler.so
resources:
limits:
nvidia.com/gpu: 1
volumeMounts:
- name: zymtrace-profiler
mountPath: /opt/zymtrace/profiler
readOnly: true
volumes:
- name: zymtrace-profiler
hostPath:
path: /var/lib/zymtrace/profiler
type: Directory
Apply the full manifest:
kubectl apply -f https://gist.githubusercontent.com/iogbole/16c39f0915cb4998a7a201c8c0864ba8/raw/sglang.yaml
# Reach the OpenAI-compatible API on localhost:30000
kubectl -n sglang port-forward svc/sglang 30000:30000
Run the Zymtrace profiler container on the host. It extracts the CUDA profiler library to /var/lib/zymtrace/profiler. See Install with Docker.
Mount /var/lib/zymtrace/profiler from the host and set CUDA_INJECTION64_PATH, as described in Docker GPU configuration:
docker run --gpus all \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-v /var/lib/zymtrace/profiler:/opt/zymtrace/profiler:ro \
-e CUDA_INJECTION64_PATH="/opt/zymtrace/profiler/libzymtracecudaprofiler.so" \
-p 30000:30000 \
--ipc=host \
--rm -d \
--name sglang-server \
lmsysorg/sglang:v0.5.22 \
python3 -m sglang.launch_server \
--model-path zai-org/GLM-4-9B-0414 \
--host 0.0.0.0 \
--port 30000 \
--enable-metrics
Install and start the Zymtrace profiler binary on the host. It ships the CUDA profiler library at /opt/zymtrace/profiler/libzymtracecudaprofiler.so. See Install with Binary.
Install SGLang into a virtual environment (Python 3.11 or newer) and start it with CUDA_INJECTION64_PATH set:
python3 -m venv ~/sglang-env
source ~/sglang-env/bin/activate
pip install sglang==0.5.22
env CUDA_INJECTION64_PATH="/opt/zymtrace/profiler/libzymtracecudaprofiler.so" \
python3 -m sglang.launch_server \
--model-path zai-org/GLM-4-9B-0414 \
--host 0.0.0.0 \
--port 30000 \
--enable-metrics
SGLang publishes ROCm images per GPU family: use the -mi30x tag for MI300X and MI325X, and the -mi35x tag for MI350X and MI355X.
- Kubernetes (Helm)
- Docker
- Binary
Install the Zymtrace profiler on your cluster with Helm and enable GPU profiling (--set profiler.cudaProfiler.enabled=true). It extracts the ROCm profiler libraries to /var/lib/zymtrace/profiler on every GPU node. See Install with Helm.
Run SGLang's ROCm image with /var/lib/zymtrace/profiler mounted from the node and the ROCm profiling variables set. The AMD GPU device plugin exposes GPUs as amd.com/gpu. Add these fields to your SGLang Deployment:
spec:
template:
spec:
hostIPC: true
containers:
- name: sglang
image: lmsysorg/sglang:v0.5.22-rocm724-mi30x
command: ["python3", "-m", "sglang.launch_server"]
args: ["--model-path", "zai-org/GLM-4-9B-0414", "--host", "0.0.0.0", "--port", "30000", "--enable-metrics"]
env:
- name: ROCP_TOOL_LIBRARIES
value: /opt/zymtrace/profiler/libzymtracerocmprofiler.so
- name: ROCPROFILER_REGISTER_LIBRARY
value: /opt/zymtrace/profiler/librocprofiler-sdk.so.1
resources:
limits:
amd.com/gpu: 1
volumeMounts:
- name: zymtrace-profiler
mountPath: /opt/zymtrace/profiler
readOnly: true
volumes:
- name: zymtrace-profiler
hostPath:
path: /var/lib/zymtrace/profiler
type: Directory
Run the Zymtrace profiler container on the host. It extracts the ROCm profiler libraries to /var/lib/zymtrace/profiler. See Install with Docker.
Pass the AMD GPU devices through, mount /var/lib/zymtrace/profiler from the host, and set the ROCm profiling variables:
docker run \
--device /dev/kfd \
--device /dev/dri \
--group-add video \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-v /var/lib/zymtrace/profiler:/opt/zymtrace/profiler:ro \
-e ROCP_TOOL_LIBRARIES="/opt/zymtrace/profiler/libzymtracerocmprofiler.so" \
-e ROCPROFILER_REGISTER_LIBRARY="/opt/zymtrace/profiler/librocprofiler-sdk.so.1" \
-p 30000:30000 \
--ipc=host \
--rm -d \
--name sglang-server \
lmsysorg/sglang:v0.5.22-rocm724-mi30x \
python3 -m sglang.launch_server \
--model-path zai-org/GLM-4-9B-0414 \
--host 0.0.0.0 \
--port 30000 \
--enable-metrics
Install and start the Zymtrace profiler binary on the host. It ships the ROCm profiler libraries in /opt/zymtrace/profiler. See Install with Binary.
Start SGLang from a ROCm-enabled environment with the ROCm profiling variables set:
env ROCP_TOOL_LIBRARIES="/opt/zymtrace/profiler/libzymtracerocmprofiler.so" \
ROCPROFILER_REGISTER_LIBRARY="/opt/zymtrace/profiler/librocprofiler-sdk.so.1" \
python3 -m sglang.launch_server \
--model-path zai-org/GLM-4-9B-0414 \
--host 0.0.0.0 \
--port 30000 \
--enable-metrics
See SGLang's AMD GPU guide to install SGLang for ROCm.
Send requests​
SGLang exposes an OpenAI-compatible API:
curl http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "zai-org/GLM-4-9B-0414", "messages": [{"role": "user", "content": "How does machine learning work?"}], "max_tokens": 256}'
Metrics​
SGLang only exposes its Prometheus metrics when started with --enable-metrics, which every example above sets. Zymtrace then collects them alongside the profiles. See Inference Server Metrics.
For PC sampling (NVIDIA) and verification, see the overview.