rh-runninghub/minimax-h3-multigpu-lightning/write-sglang-test
Claude Code and agent skill by rh-runninghub/minimax-h3-multigpu-lightning
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Guide for writing SGLang CI/UT tests. Covers CustomTestCase, CI registration, server fixtures, model selection, mock testing, and test placement. Always read test/README.md for the full CI layout, how to run tests, and extra tips. Use when creating new tests, adding CI test cases, writing unit tests, or when the user asks to add tests for SGLang features.
Install
npx vskill@latest install rh-runninghub/minimax-h3-multigpu-lightning/write-sglang-testSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as rh-runninghub/minimax-h3-multigpu-lightning/write-sglang-test.
Writing SGLang CI / UT Tests
This skill covers how to write and register tests. For CI pipeline internals (stage ordering, fail-fast, gating, partitioning, debugging CI failures), see the CI workflow guide. Whether a case is worth adding at all is decided by `unit-test-admission` — read it before writing the case, not after.
Core Rules
- Always use `CustomTestCase` — never raw
unittest.TestCase. It ensurestearDownClassruns even whensetUpClassfails, preventing resource leaks in CI. - `tearDownClass` must shut the server down gracefully — call
terminate_and_kill_process_tree(cls.process), never a barekill_process_tree. SIGKILL alone skips the server's userspace cleanup and leaves its GPU memory charged to the dead process; the next class then OOMs while loading weights. Keep it defensive too:hasattr/null checks before accessing resources (e.g.cls.process) thatsetUpClassmay not have finished allocating. - Place non-kernel tests in `test/registered/<kind>/<subsystem>/` —
<kind>isunit,e2e,accuracy,perf, orstress; kernel tests usetest/registered/kernels/{ops,benchmark}/<group>/; hardware belongs in registrations, not directory names - Reuse server fixtures — inherit from
DefaultServerBaseor writesetUpClass/tearDownClasswithpopen_launch_server - Mock boundaries, not SGLang behavior — mock slow or external dependencies only when the assertion still checks an observable result, state transition, or error. A test whose evidence is only
assert_called*mirrors its mock and is not admissible. Launch a real server only when inference results or lifecycle behavior are the contract under test.
Existing files are not the reference. About 290 test files still call the barekill_process_tree(cls.process.pid), against 43 on the current helper. They predaterule 2 and are being migrated, so grepping the repo for a teardown pattern finds thewrong one roughly seven times out of eight. The same goes forregister_cuda_ci(suite=...):four files still pass it, all of them undertest/registered/stress/.
JIT kernel notes:
- If the task is adding or updating code under
python/sglang/kernels/jit/, prefer theadd-jit-kernelskill first. - JIT kernel correctness tests use
test/registered/kernels/ops/<group>/test_*.py. - JIT kernel benchmarks use
test/registered/kernels/benchmark/<group>/bench_*.py. - Those files are executed by
test/run_suite.pythrough dedicated kernel suites (base-b-kernel-*); aregister_*_ci(...)call placed underpython/sglang/is rejected by thecheck-no-registered-tests-in-packagepre-commit hook.
Model & Backend Selection
| Scenario | Model | CI Registration | Suite | |
|---|---|---|---|---|
| Unit tests (no server / engine launch) | None | register_cpu_ci | base-a-test-cpu | |
| Common / backend-independent (middleware, abort, routing, config, arg parsing) | DEFAULT_SMALL_MODEL_NAME_FOR_TEST (1B) | register_cuda_ci only | base-b-test-1-gpu-small | |
| Model-agnostic functionality (sampling, session, OpenAI API features) | DEFAULT_SMALL_MODEL_NAME_FOR_TEST (1B) | register_cuda_ci (+ AMD if relevant) | base-b-test-1-gpu-small | |
| General performance (single node, no spec/DP/parallelism) | DEFAULT_MODEL_NAME_FOR_TEST (8B) | register_cuda_ci | base-b-test-1-gpu-large | |
| Bigger features (spec, DP, TP, disaggregation) | Case by case | Case by case | See Choosing a Suite below |
Key principle for E2E tests: Do NOT add register_amd_ci unless the test specifically exercises AMD/ROCm code paths. Common E2E tests just need any GPU to run — duplicating across backends wastes CI time with no extra coverage.
All model constants
Defined in python/sglang/test/test_utils.py:
| Constant | Model | When to use | |
|---|---|---|---|
DEFAULT_SMALL_MODEL_NAME_FOR_TEST | Llama-3.2-1B-Instruct | Common features, model-agnostic tests | |
DEFAULT_SMALL_MODEL_NAME_FOR_TEST_BASE | Llama-3.2-1B | Base (non-instruct) model tests | |
DEFAULT_MODEL_NAME_FOR_TEST | Llama-3.1-8B-Instruct | General performance (single node) | |
DEFAULT_MOE_MODEL_NAME_FOR_TEST | Mixtral-8x7B-Instruct | MoE-specific tests | |
DEFAULT_SMALL_EMBEDDING_MODEL_NAME_FOR_TEST | — | Embedding tests | |
DEFAULT_SMALL_VLM_MODEL_NAME_FOR_TEST | — | Vision-language tests |
Naming Conventions
A per-commit suite name is generated from registration metadata as {stage}-test-{runner_config} — you don't hand-write it:
- `stage` — the CI stage (e.g.
base-b,base-b-kernel-unit,base-c). - `runner_config` — a runner-pool key from
scripts/ci/runner_configs.yml, which maps it to the physical runner label (so1-gpu-largeruns on1-gpu-h100). AMD/NPU use their own keys (e.g.amd). - Suite —
register_cuda_ci(stage="base-b", runner_config="1-gpu-small")→base-b-test-1-gpu-small, the name you pass torun_suite.py --suite. The-test-is just the connector; never put it inregister_*_ci.
CUDA nightly uses the same shape withstage="nightly"(e.g.stage="nightly", runner_config="1-gpu-large"→nightly-test-1-gpu-large) and nonightly=True— the stage name carries the cadence, and setting the flag makes the test silently never run. Legacy single-stringsuite=is left only forstressand some AMD/CPU/NPU pools.
All CI Suites
Do not work from a list copied into this file; it goes stale silently. Read the current one:
scripts/ci/runner_configs.yml calls itself the single source of truth for the runner_config field, and run_suite.py is what actually dispatches, so those two files settle any disagreement with prose anywhere else.
Nightly suites live in NIGHTLY_SUITES and run via nightly-test-nvidia.yml, nightly-test-amd.yml, and nightly-test-npu.yml, not pr-test.yml. CUDA nightly is named nightly-test-{runner_config} — one suite per machine type, holding everything that runs nightly on it, with auto_partition splitting the work. There is no per-purpose split; kernel, eval, perf, and precision all share their machine's suite.
Note: Multimodal diffusion usespython/sglang/multimodal_gen/test/run_suite.py, nottest/run_suite.py.
Choosing a Suite
Use the lightest suite that meets your test's needs:
- No GPU required →
base-a-test-cpu - Most small GPU tests →
base-b-test-1-gpu-small(default choice) - Need H100 memory or Hopper features →
base-b-test-1-gpu-large - JIT kernel correctness →
base-b-kernel-unit-test-1-gpu-large - JIT kernel correctness for B200 / SM100 paths →
base-b-kernel-unit-test-4-gpu-b200 - JIT kernel benchmarks →
base-b-kernel-benchmark-test-1-gpu-large - Multi-GPU → only when the test actually needs multiple GPUs
Test File Templates
Unit Tests (no server / engine launch)
See test/registered/unit/README.md for quick-start and rules. Unit tests live in test/registered/unit/, mirroring python/sglang/srt/:
Use unittest.mock.patch / MagicMock only at dependency boundaries. Assert the resulting value, state, protocol output, or error—not merely that the mock was called. If the module transitively imports GPU-only packages (e.g. sgl_kernel), they can be stubbed so the test runs on CPU CI. Do not modify sys.modules at module level—use patch.dict (as a class decorator or with start/stop) to ensure cleanup and avoid cross-test pollution. See test/registered/unit/README.md for details and examples.
Quality bar — test real logic (validation boundaries, state transitions, error paths, branching, etc.). Skip tests that just verify Python itself works (e.g., "does calling an abstract method raise NotImplementedError?", "does a dataclass store the field I assigned?"). Consolidate repetitive patterns into parameterized tests. No production code changes in test PRs.
E2E test (small model, server needed)
Copy the tearDownClass above verbatim. Most existing E2E files still show the bare kill_process_tree; that form is being migrated out and must not be reproduced.
E2E test (8B model, server needed, performance)
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingsglang/.claude/skills/write-sglang-test/SKILL.md
Popularity
- Repository stars
- 123
- Repository forks
- 19
- 7-day trend score
- 23
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/rh-runninghub/minimax-h3-multigpu-lightning/write-sglang-test)