Step-by-step tutorial for adding a new lightweight JIT CUDA kernel to sglang.kernels JIT infrastructure and public operator groups
日本語の概要は準備中です。原文の説明を表示しています。
Code style for SGLang large classes `Scheduler`, `TokenizerManager`, and `ModelRunner`: frozen-code conventions and `__init__` orchestration style. Use when modifying any of these three classes or reviewing changes to them.
インストールする前に、エージェントに与えられる指示の中身を確認できます。
Conventions for SGLang's three large classes:
Scheduler — python/sglang/srt/managers/scheduler.pyTokenizerManager — python/sglang/srt/managers/tokenizer_manager.pyModelRunner — python/sglang/srt/model_executor/model_runner.pypython/sglang/srt/model_executor/model_runner.pyEvery statement refers to a collaborator and is one of:
init_<thing> helper whose body is essentially a single construction (follows §2); use maybe_init_<thing> with a one-line gate when conditional.__init__).self.foo.run(...)).if choosing whether / which collaborator to wire or call, the order of calls, threading one call's result into the next.# model_runner.py — orchestration only.
def init_foo(self): # construct
self.foo = FooManager(server_args=self.server_args, device=self.device)
self.init_foo() # wire (in __init__)
if self.server_args.enable_bar: # coordinate: select
self.bar.prepare(forward_batch) # delegate
out = self.foo.run(forward_batch) # delegate
self.baz.consume(out) # coordinate: thread result into next delegate
# NOT allowed in a frozen file: domain logic inlined.
self.foo = None
if self.server_args.enable_foo:
config = build_foo_config(self.model_config, self.device) # config logic in frozen file
self.foo = FooManager(config) # inline construction, not via (maybe_)init_foo
out = [step(x) for x in batch] # computation, not coordination
FooManager (its __init__ or a factory) plus a (maybe_)init_foo helper.When you extract domain logic into a collaborator (a factory, an initializer, a pipeline), give it the specific values it needs — model_config, device, the sizes — not the whole frozen object (ModelRunner, Scheduler).
Passing the god object back re-creates the coupling the split was meant to remove: the module still reads dozens of attributes off it, can't be unit-tested without building the whole class, and every field rename ripples back in.
Default to narrow, keyword args. Reference shape: layer_setup.resolve_layer_indices(*, model, model_config, is_draft_worker, spec_algorithm).
Return a small frozen struct and let the orchestrator assign it onto its own fields. The collaborator should not reach back in and mutate the god object.
If a leaf genuinely needs the live object — its constructor contract already takes the runner, or it reads state that mutates after init — confine that dependency to the smallest leaf and pass narrow args everywhere above it. Note why it can't be narrowed.
ModelRunner owns by reading model_runner.py, the hidden writes race with the orchestrator's own ordering, and the callee silently depends on being invoked at exactly the right moment.# Good — callee reads the runner and returns a small frozen struct; the orchestrator
# owns the writes.
# model_runner.py
class ModelRunner:
def bar(self):
self.foo_result = foo(self)
# another_file.py
def foo(model_runner) -> FooResult:
return FooResult(a=xx, b=yy, c=zz)
# Avoid — callee reaches back in and writes the runner's fields.
# model_runner.py
class ModelRunner:
def bar(self):
foo(self)
# another_file.py
def foo(model_runner):
model_runner.a = xx
model_runner.b = yy
model_runner.c = zz
__init__ styleApply when modifying the __init__ of the three classes above.
__init__, which rots against upstream.init_* helpers lets them override exactly what they need.TokenizerManager.__init__ in python/sglang/srt/managers/tokenizer_manager.py.__init__ is an orchestrator. Sequence of self.init_*(...) calls + minimal glue. No non-trivial construction inlined.init_* = one concern a subclass might swap. Don't lump.init_<thing> (snake_case, names the component). Conditional construction → maybe_init_<thing>, gate inside the helper.self.* set by earlier helpers. Ordering lives in __init__. Shared intermediates → pass as args, not via self.*.init_<thing>, not another inline block. One-line self.foo = server_args.foo is fine; structured logic is not.init_* signatures. Breaking changes → call out in PR.まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Step-by-step tutorial for adding a new lightweight JIT CUDA kernel to sglang.kernels JIT infrastructure and public operator groups
日本語の概要は準備中です。原文の説明を表示しています。
Step-by-step tutorial for adding a heavyweight AOT CUDA/C++ kernel to sgl-kernel (including tests & benchmarks)
日本語の概要は準備中です。原文の説明を表示しています。
Start and persistently pursue a goal to babysit an SGLang pull request until selected GitHub Actions workflows pass on the latest PR head. Use when asked to monitor, babysit, retry, or fix PR CI for lint.yml, pr-test.yml, pr-test-extra.yml, AMD, or other named workflows; classify failures as PR-related versus flaky or infrastructural, auto-fix and push only small clean fixes, rerun failed jobs only up to 10 times, and ignore unselected workflows.
日本語の概要は準備中です。原文の説明を表示しています。
Audit the existing test tree and CI configuration for improvements, using a catalog of patterns previously applied in this repo. Use when asked to audit tests or CI, shrink CI time or cost, find redundant or misplaced tests, clean up a test group, or review whether a CI change follows established practice.
日本語の概要は準備中です。原文の説明を表示しています。
Guide to SGLang CI workflow orchestration — stage ordering, fail-fast, gating, partitioning, execution modes, and debugging CI failures. Use when modifying CI workflows, adding stages, debugging CI pipeline issues, or understanding how tests are dispatched and gated across stages.
日本語の概要は準備中です。原文の説明を表示しています。
Audit SGLang startup logs, save evidence, and propose cleanup for user review. With no arguments, run Qwen3-8B at TP1 and TP2 plus gpt-oss-20b at TP1.
日本語の概要は準備中です。原文の説明を表示しています。