The per-model values
Each model role (ModelRole.TARGET, ModelRole.DRAFT) has one immutable ModelExecutionConfig (sglang/srt/configs/model_execution.py). Its fields are exposed as leaves of the get_model() namespace while that model is selected:
Every runner of one model shares its role’s entry; multi-layer EAGLE’s step runners all use the draft entry.
Lifecycle
- Resolve and install. The scheduler calls
resolve_model_execution_configsonce per process, after platform and distributed initialization and before any worker exists, and installs the table withinstall_model_execution_configs. A draft role is resolved only when the speculative algorithm builds a draft model (has_draft_model()), and the draft’s MoE choices followdraft_builds_with_own_moe_backends(). - Build inside the model’s scope.
ModelRunner.model_context()selects the runner’s role entry. Model construction, weight loading, post-load preparation, attention-backend construction and CUDA graph setup run inside it. - Built modules keep their choice. A layer, quantization method, dispatcher or attention backend reads the value when it is built and keeps it. New code follows this rule: execution methods such as
forward, a quantization method’sapplyor a runner’srunuse the kept value instead of callingget_model()or its accessors again. A few existing execution paths still read the current scope, so a model’s forward, graph capture and weight updates must run inside its own scope (steps 2, 4 and 5); running a built module under another model’s scope is not supported. - Per-batch code reads the current scope. Code that no built module owns, such as batch preparation, reads the leaf of the model whose scope is current. The scheduler keeps the target’s scope entered for its lifetime; draft work outside the draft runner’s forward enters
draft_model_scope(). - Weight updates run in the model’s scope. A runner’s weight update, reload and post-processing run inside the same scope as its build, so reloaded weights are prepared for the backends the model was built with.
Migrating from the earlier interfaces
In
get_flags().moe, runner_backend, runner_backend_explicit, a2a_backend and disable_fp4_allgather are the served model’s choices as configured: each model’s moe_backends starts from them, and model code reads get_model().moe_backends instead. The other fields, such as deepep_mode, deepep_config, tbo_enabled and sbo_enabled, are process-wide settings and are still read from the flags.
Examples
A speculative worker helper that runs draft modules outside the draft runner’s forward enters the draft scope:What the scope guarantees
- A scope selects an entry and restores the previous values on exit, including on exceptions. It cannot resize weights, buffers or captured graphs built under another entry.
- In a serving process that installed the table, reading a per-model value outside every scope raises. Tools and tests that install no table see the startup defaults for the MoE values and the shared-expert layout; a linear-attention backend always needs a bound kernel choice.
- Draft work that runs under the target’s scope reads the target’s values without any error. A missing
draft_model_scope()is therefore not always detected; the unit testtest/registered/unit/spec/test_draft_model_calls_scoped.pychecks only calls made through the namedraft_model.
Speculative algorithm plugins
ACustomSpecAlgo declares two facts the resolver needs before its worker exists:
has_draft_model() -> bool: whether its worker builds a draft model. The default is true when--speculative-draft-model-pathis set or the algorithm answers true to a draft-building trait (is_eagle,is_eagle3,is_frozen_kv_mtp,is_standalone,is_dflash,is_dspark,is_dflash_family).draft_builds_with_own_moe_backends() -> tuple[bool, bool]: two independent answers,(own_runner, own_a2a): whether its draft builds with its own MoE runner (--speculative-moe-runner-backend), and whether with its own all-to-all backend (--speculative-moe-a2a-backend). For example,(True, False)gives the draft its own runner and the target’s all-to-all, as multi-layer EAGLE does. The default applies the built-in rule to the algorithm’sis_*()answers; see MoE backends for the draft model.
draft_model_scope() so it builds with the resolved choices.