Agent Skillssgl-project/sglang › generate-profile

generate-profile

GitHub

启动SGLang服务器,验证模型准确性后生成端到端性能分析追踪文件,返回Chrome兼容的trace路径,用于评估推理性能。

.claude/skills/generate-profile/SKILL.md sgl-project/sglang

Trigger Scenarios

需要分析SGLang服务器性能时 生成推理追踪报告时 检查模型服务响应时间时

Install

npx skills add sgl-project/sglang --skill generate-profile -g -y
More Options

Non-standard path

npx skills add https://github.com/sgl-project/sglang/tree/main/.claude/skills/generate-profile -g -y

Use without installing

npx skills use sgl-project/sglang@generate-profile

指定 Agent (Claude Code)

npx skills add sgl-project/sglang --skill generate-profile -a claude-code -g -y

安装 repo 全部 skill

npx skills add sgl-project/sglang --all -g -y

预览 repo 内 skill

npx skills add sgl-project/sglang --list

SKILL.md

Frontmatter
{
    "name": "generate-profile",
    "description": "Generate an e2e profiling trace of an SGLang server run. Launches a server, validates accuracy, captures a Chrome-compatible trace, and returns the profile path."
}

Generate an E2E Profile of an SGLang Server Run

This skill launches an SGLang server, validates it with a quick accuracy test, generates a profiling trace, and returns the profile file path.

Prerequisites

  • A working SGLang installation (pip install -e . or equivalent)
  • At least one available CUDA GPU

Step-by-step Workflow

Step 1: Launch the server

CUDA_VISIBLE_DEVICES=<gpu_id> sglang serve --model-path <model> --port <port> &
  • Default model: Qwen/Qwen3-8B (good balance of speed and quality)
  • Default port: 30000
  • The server runs in the background. Save the PID for cleanup.
  • Use the GPU specified by the user's preferences (check memory files for GPU preferences).

Step 2: Wait for server readiness

Poll the health endpoint until the server is ready:

for i in $(seq 1 120); do
  if curl -s http://127.0.0.1:<port>/health 2>/dev/null | grep -q "ok\|healthy"; then
    echo "Server ready"
    break
  fi
  sleep 5
done

The server prints "The server is fired up and ready to roll!" to stdout when ready. The health endpoint returns 200 once the server can accept requests.

Typical startup time: 30-90 seconds depending on model size and whether CUDA graphs are being compiled.

Step 3: Validate accuracy (sanity check)

python3 -m sglang.test.run_eval --host 127.0.0.1 --port <port> --eval-name gsm8k --num-examples 20
  • Expected accuracy: > 0.8 for capable models (Qwen3-8B, Llama-3.1-8B-Instruct, etc.)
  • This is a quick sanity check, not a rigorous benchmark.
  • sglang.test.few_shot_gsm8k is deprecated; use the unified run_eval entrypoint.
  • If you intentionally need the old completion-style GSM8K path, add --api completion.
  • If accuracy is unexpectedly low, something is wrong — do not proceed to profiling.

Step 4: Generate the profile

python3 -m sglang.test.send_one --profile

This command:

  1. Sends a request to the server
  2. Triggers the profiler for 5 steps (default)
  3. Generates a trace file under /tmp/<timestamp>/
  4. The trace directory contains:
    • <timestamp>-TP-0.trace.json.gz — Chrome trace format (open in chrome://tracing or Perfetto)
    • server_args.json — the server configuration used

Output format:

Dump profiling traces to /tmp/<timestamp>

The profile path is printed to stdout. Parse it from the output.

Optional flags:

  • --profile-steps N — number of profiling steps (default: 5)
  • --profile-by-stage — profile by stage (prefill/decode separately)
  • --profile-prefix <path> — custom output prefix

Step 5: Kill the server

pkill -9 -f "sglang.launch_server\|sglang serve\|sglang.srt"

Wait a moment and verify no sglang processes remain:

sleep 2 && pgrep -af "sglang serve" || echo "Server killed"

Step 6: Report the profile path

Return the profile directory path (e.g., /tmp/1773999986.4769795) and list its contents so the user knows what files were generated.

Example Full Run

# 1. Launch server
source cleanup/bin/activate
CUDA_VISIBLE_DEVICES=1 sglang serve --model-path Qwen/Qwen3-8B --port 30000 &

# 2. Wait for ready
for i in $(seq 1 120); do
  curl -s http://127.0.0.1:30000/health | grep -q "ok" && break
  sleep 5
done

# 3. Accuracy check
python3 -m sglang.test.run_eval --host 127.0.0.1 --port 30000 --eval-name gsm8k --num-examples 20
# Expected: Accuracy > 0.8

# 4. Profile
python3 -m sglang.test.send_one --profile
# Output: "Dump profiling traces to /tmp/1773999986.4769795"

# 5. Cleanup
pkill -9 -f "sglang.launch_server\|sglang serve\|sglang.srt"
sleep 2

# 6. Check output
ls -la /tmp/1773999986.4769795/
# 1773999986.4851577-TP-0.trace.json.gz  (Chrome trace)
# server_args.json                        (server config)

Customization

  • Different port: Pass --port <port> and use --host 127.0.0.1 --port <port> for test commands
  • Multi-GPU: Use --tp <N> for tensor parallelism; trace files will be generated per TP rank
  • Longer profile: Use --profile-steps 10 for more steps in the trace
  • Stage profiling: Use --profile-by-stage to separate prefill and decode phases

Viewing the Profile

Open the .trace.json.gz file in:

Both support the gzipped Chrome trace format natively.

Version History

  • 1df78c2 Current 2026-08-20 08:18

Same Skill Collection

.claude/skills/add-jit-kernel/SKILL.md
.claude/skills/add-sgl-kernel/SKILL.md
.claude/skills/babysit-pr-to-pass-ci/SKILL.md
.claude/skills/ci-workflow-guide/SKILL.md
.claude/skills/clean-startup-log/SKILL.md
.claude/skills/compute-mamba-ratio/SKILL.md
.claude/skills/cookbook-add-model/SKILL.md
.claude/skills/cookbook-migrate-model/SKILL.md
.claude/skills/cookbook-review-pr/SKILL.md
.claude/skills/debug-cuda-crash/SKILL.md
.claude/skills/debug-distributed-hang/SKILL.md
.claude/skills/env-var-conventions/SKILL.md
.claude/skills/kl-consistency-test/SKILL.md
.claude/skills/large-class-style/SKILL.md
.claude/skills/llm-torch-profiler-analysis/SKILL.md
.claude/skills/mechanical-refactor-verify/SKILL.md
.claude/skills/scripted-runtime-notes/SKILL.md
.claude/skills/sglang-bisect-ci-regression/SKILL.md
.claude/skills/sglang-cherrypick/SKILL.md
.claude/skills/sglang-prod-incident-triage/SKILL.md
.claude/skills/sglang-runtime-context/SKILL.md
.claude/skills/speculative-naming/SKILL.md
.claude/skills/write-sglang-test/SKILL.md

Metadata

Files
0
Version
1df78c2
Hash
0fcd8069
Indexed
2026-08-20 08:18

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-25 15:16
浙ICP备14020137号-1 $방문자$