__init__ Style for Scheduler / TokenizerManager / ModelRunner
Apply when modifying the __init__ of:
Scheduler—python/sglang/srt/managers/scheduler.pyTokenizerManager—python/sglang/srt/managers/tokenizer_manager.pyModelRunner—python/sglang/srt/model_executor/model_runner.py
Why
- Downstream forks override one piece (tokenizer, KV cache, IPC, …).
- Inline logic forces them to copy the whole
__init__, which rots against upstream. - Splitting into
init_*helpers lets them override exactly what they need. - Reference shape:
TokenizerManager.__init__inpython/sglang/srt/managers/tokenizer_manager.py.
Rules
__init__is an orchestrator. Sequence ofself.init_*(...)calls + minimal glue. No non-trivial construction inlined.- One helper per overridable unit. Each
init_*= one concern a subclass might swap. Don't lump. - Naming:
init_<thing>(snake_case, names the component). Conditional construction →maybe_init_<thing>, gate inside the helper. - No silent state coupling. A helper only reads
self.*set by earlier helpers. Ordering lives in__init__. Shared intermediates → pass as args, not viaself.*. - New logic = new helper. Default to adding
init_<thing>, not another inline block. One-lineself.foo = server_args.foois fine; structured logic is not. - Preserve override points. Prefer additive changes to existing
init_*signatures. Breaking changes → call out in PR.
Scope
Only the three classes listed above. Not other manager-style classes, not small dataclass/utility constructors.