Skip to content
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
df1af58
Engine, conductor, API server and shared components for the overnight…
dghosef Oct 24, 2026
0193c2c
Merge origin/main into perf/split-1-shared
dghosef Oct 27, 2026
82b83b1
Conductor: count DP replica load per (node group, replica) (R1.4)
dghosef Oct 27, 2026
3d3722a
Piecewise runner: apply one_row_per_step in its own bucket lookup (R1.5)
dghosef Oct 27, 2026
c485d3d
TokenStop: read the generated-token count without creating request st…
dghosef Oct 27, 2026
18c5d21
TokenStepNode: declare token_stop in __init__ like every AR node (P3-2)
dghosef Oct 27, 2026
213cbd8
Ragged attention: hold the custom op's managers weakly (P3-1)
dghosef Oct 27, 2026
79aeb63
Docs: one_row_per_step, shard_heads and compile_op; warmup and switch…
dghosef Oct 27, 2026
58b71cc
Sampler: loopback_input_ids moves from ARNodeSubmodule onto SamplerRe…
dghosef Oct 27, 2026
5358123
Nits: router tie docstring, router test docstring, stray EOF blank li…
dghosef Oct 27, 2026
7dc25f6
Video decode: one thread policy from the preprocess pool and CPU affi…
dghosef Oct 27, 2026
5bd18a4
Whisper: declare token_stop in __init__ (P3-2)
dghosef Oct 27, 2026
bac7cda
Qwen3.5: decode loop-back goes through SamplerResource.loopback_input…
dghosef Oct 27, 2026
26c62af
Canary, Canary-Qwen, Whisper: TokenStop reads the class loop and samp…
dghosef Oct 27, 2026
6f2540e
Media limits: the video decode thread cap follows CPU affinity, not a…
dghosef Oct 27, 2026
e1ff4dc
Tests: the one-row piecewise runner captures batch size 1 only (R2.d)
dghosef Oct 27, 2026
04af3ba
Merge origin/main into the perf stack's shared changes (#858)
dghosef Oct 27, 2026
148a9c9
TokenStop: check_stop reads a row's first element, as check_stop_batc…
dghosef Oct 27, 2026
72ce104
Waypoint harness: serve_rollout's parsers strip the internal id's #<n…
dghosef Oct 27, 2026
377d21a
Warmup: repeat and concurrency share one positive-integer check
dghosef Oct 27, 2026
3ac732b
Warmup: one id form, warmup-<spec>.<level>.<copy>, and the first fail…
dghosef Oct 27, 2026
6d152f3
API server: api_switch_interval_s must be a positive number, checked …
dghosef Oct 27, 2026
49c828e
docs/serving.rst: the warmup copy count is the largest node group's r…
dghosef Oct 27, 2026
fe1b879
Ragged attention: the mstar::ragged_attention op body calls the manag…
dghosef Oct 27, 2026
41d22c2
Resources: every builder shards heads by EngineResourceInfo.head_shar…
dghosef Oct 27, 2026
c881c83
wav2vec2: the frame lengths go up through to_device_nonblocking
dghosef Oct 27, 2026
37ad4f5
MoE: the blocks take a fused router through router=, not a flag of th…
dghosef Oct 27, 2026
7c34610
Tests: the get_device compile check joins test_submodule_device_cache.py
dghosef Oct 27, 2026
d6656dd
Resources: EngineResourceInfo without head_shards shards over its joi…
dghosef Oct 27, 2026
a025ebd
Engine: TP ranks always split a resource's heads; nodes sharing it mu…
dghosef Oct 27, 2026
2391eb1
Tests: test_startup_warmup.py says it covers the API server's process…
dghosef Oct 27, 2026
b14f452
HostRows.first_values: one row map, no in-order fast path beside it
dghosef Oct 27, 2026
bb5fd76
TokenStop: one per-row verdict holds the walk test; no check_walk fla…
dghosef Oct 27, 2026
a6a1de8
Qwen3.5: the decode stop is a TokenStop declaration, not a copy of it…
dghosef Oct 27, 2026
0a79e0e
docs/serving.rst: api_switch_interval_s is re-measured once #849 lands
dghosef Oct 27, 2026
36260eb
Tests: the Qwen3.5 loop-cap test checks the real LLM submodule's stop
dghosef Oct 27, 2026
24a729f
Delete check_stop_batched's unread step_walk parameter (858 RB.1)
dghosef Oct 27, 2026
06fd646
Tests: two blank lines before the new ragged-attention tests (858 RB.2)
dghosef Oct 27, 2026
8f3de98
Tests: drop the last step_context the engine's stop check no longer r…
dghosef Oct 27, 2026
ae6adf6
KV: one rule for whether a prefix cache opens
dghosef Oct 27, 2026
edaef64
Conductor: pick DP replicas by cost over routing mirrors
dghosef Oct 27, 2026
6bb2df6
Routing: mirrors report named facts, one function prices them
dghosef Oct 27, 2026
7e291e6
Warmup: count data-parallel replicas from the worker graphs (merceod …
dghosef Oct 28, 2026
636e2b8
Merge origin/main 73c6c17c4 into merge/858-main
dghosef Oct 28, 2026
d244382
858 I1.1: one WorkerGraph.replica_ranks for a worker graph's DP replicas
dghosef Oct 28, 2026
212cc49
858 I1.2: serving docs count warmup copies from the worker graphs
dghosef Oct 28, 2026
2418298
Routing: a predicted prefix hit is worth up to 8 live requests by def…
dghosef Oct 28, 2026
53a60d1
Warmup: a replicated entry runs one request alone first
dghosef Oct 28, 2026
088a61d
merceod #858 row 15: one pinned H2D helper, capability-gated and list…
dghosef Oct 28, 2026
c540ded
858 R3.1: warmup runs its solo once per entry, only when replicas are…
dghosef Oct 28, 2026
9a03b82
858 R3.2: the warmup solo logs its own outcome
dghosef Oct 28, 2026
32842c9
858 R3.3: to_device_nonblocking says an already-pinned source is read…
dghosef Oct 28, 2026
5058e89
Merge origin/main 94b038c26 into perf/split-1-shared
dghosef Oct 28, 2026
38c186d
M1: copy an already-pinned host tensor to the device in place
dghosef Oct 28, 2026
1c0569b
M2: size video decode threads from usable_cpus, apart from the torch …
dghosef Oct 28, 2026
8b4a2eb
M3: test GLM-5.2's stop id at prefill
dghosef Oct 28, 2026
591bad1
M4: declare a prefill-sampled first token on TokenStop
dghosef Oct 28, 2026
c84d883
M1: model the mocked host tensor in the pin test as pageable
dghosef Oct 28, 2026
b8a3075
N1: copy a pinned source in place only when it is contiguous
dghosef Oct 28, 2026
f22ef3f
N2: read usable_cpus once per process for video decode threads
dghosef Oct 28, 2026
8fe61cd
N3: say a generated_key counter must count the prefill token itself
dghosef Oct 28, 2026
731bd27
N4: the engine drops the closing token of a reply that ended at prefill
dghosef Oct 28, 2026
58bad2e
N4: say prefill_walks needs the loop to emit the token as buffer
dghosef Oct 28, 2026
139a2a8
KV: KVReqConfig.prefix_cache reads only its truth
stephen-dwq Oct 29, 2026
d7ea416
Merge remote-tracking branch 'origin/main' into maint/858
dghosef Oct 29, 2026
0269eec
LingBot-World: call the ragged resource through resource.run, as the …
dghosef Oct 29, 2026
01d9f69
test_subgroup_creation_order: the stub worker graph carries replica_r…
dghosef Oct 29, 2026
71d722c
test_withheld_outputs: the fake check_stop_batched drops step_walk, a…
dghosef Oct 29, 2026
932c8b4
Merge perf/split-1-shared (with origin/main) into routing/kv-aware
dghosef Oct 29, 2026
1f89db1
test_kv_prefix_request_keys: the talker case asks for the prefix cach…
dghosef Oct 29, 2026
2883496
Prefix caches: one startup rule for which KV caches open, recurrent p…
dghosef Oct 29, 2026
dde6837
Routing docs: the KV mirror over-predicts beside a recurrent pool; na…
dghosef Oct 29, 2026
414bfc7
test_conductor_replica_assignment: the refused-request stub model has…
dghosef Oct 29, 2026
68879c4
Prefix caches: the engine opens exactly what opening_prefix_caches opens
dghosef Oct 29, 2026
ebfb51a
ReplicaRouter: size the opened caches per replica set
dghosef Oct 29, 2026
06d7793
Docs: when a recurrent pool allocates snapshot slots; the router deri…
dghosef Oct 29, 2026
fd7211d
Merge origin/main into perf/split-1-shared
dghosef Oct 29, 2026
97dc8b7
TokenStop: leave the token budget to the loop cap
dghosef Oct 29, 2026
21a8d03
TokenStop: withhold a prefill-ended reply's closing token
dghosef Oct 29, 2026
68cd243
Warmup docs: the solo run happens only when replicas are uneven
dghosef Oct 29, 2026
bc84a25
video_decode_threads: the cap of 8 is per decode
dghosef Oct 29, 2026
d913754
Ragged attention: name each manager uniquely in the op registry
dghosef Oct 29, 2026
844266e
Warmup: a replica count that fails leaves warmup at one copy
dghosef Oct 29, 2026
92ff0c9
one_row_per_step docs: what declare_step receives
dghosef Oct 29, 2026
1d6f481
Docs: MSTAR_PY_SWITCH_INTERVAL_SEC gets its worker-scheduling row
dghosef Oct 29, 2026
6f74e95
Comments: the decode budget is the loop cap, not check_stop
dghosef Oct 29, 2026
f3de748
Docs: a prefill_walks token counts toward the budget, so the loop cap…
dghosef Oct 29, 2026
9a6fdd1
Merge perf/split-1-shared fd7211dcd (#858 + origin/main 8a2095f81) in…
dghosef Oct 29, 2026
5286136
Merge origin/main into perf/split-1-shared
dghosef Oct 30, 2026
6e67694
Docs: say which MSTAR_PY_SWITCH_INTERVAL_SEC values the worker ignores
dghosef Oct 30, 2026
bcd00f6
Docs: point api_switch_interval_s to the workers' switch-interval var…
dghosef Oct 30, 2026
ad5f644
Merge origin/main into perf/split-1-shared
dghosef Oct 30, 2026
fe38b60
KV routing mirror: run the worker's own PageArena, which the index re…
dghosef Oct 30, 2026
8fefa4f
KVReqConfig.prefix_cache defaults on again; the replica tests' stub c…
dghosef Oct 30, 2026
08d3d3c
routing_weights: each weight is at most 1e6, so no replica's cost ove…
dghosef Oct 30, 2026
b3521ee
KV routing mirror: a hit runs on to an item cached up to its end insi…
dghosef Oct 30, 2026
02dbca3
Prefix caches: each spec answers whether it opens one and restores a …
dghosef Oct 30, 2026
f1c92f4
Prefix caches: every caller evaluates the open rule as each rank's en…
dghosef Oct 30, 2026
4349e90
Routing metric: a request adds one share of its prompt, however many …
dghosef Oct 30, 2026
b56f437
checkpoint_path overrides are typed to return a path, as names_checkp…
dghosef Oct 30, 2026
86369f2
Routing: the default prefix weight is provisional while the mirror cr…
dghosef Oct 30, 2026
b54669a
Merge perf/split-1-shared ad5f644d3 (#858 + origin/main fadeb2759) in…
dghosef Oct 30, 2026
ed31270
Ragged attention: update a test docstring for unique op keys
dghosef Oct 30, 2026
42c9a26
Data-worker tests deploy the model's nodes on a rank, as every deploy…
dghosef Oct 30, 2026
1d7c638
Merge perf/split-1-shared ed31270d1 (#858 + origin/main fadeb2759) in…
dghosef Oct 30, 2026
009e101
Prefix caches: a rank's set holds only the caches with a node on it (…
dghosef Oct 30, 2026
9d9f9f9
KV routing mirror: a request that never ran takes back only the entri…
dghosef Oct 30, 2026
03cc084
Engine: evaluate the prefix-cache rule and read the checkpoint once (…
dghosef Oct 30, 2026
5bbe5f3
Resource specs: the hook that says a resource keeps a cache is keeps_…
dghosef Oct 30, 2026
0179473
Prefix caches: the shut-cache log names the resources the rule blames…
dghosef Oct 30, 2026
10cc507
KV routing mirror: docs and comments say what it runs now (R2.5)
dghosef Oct 30, 2026
194207f
KV routing mirror: zip a request's filed keys and pages strictly (R2.2)
dghosef Oct 30, 2026
8250edd
Prefix caches: two docstrings say exactly what their code does (R2.3,…
dghosef Oct 30, 2026
da5ef36
Merge origin/main into perf/split-1-shared
dghosef Oct 30, 2026
509189b
Comments and docs: a shard_over_sp=False ragged resource splits its h…
dghosef Oct 30, 2026
f8d377c
Merge perf/split-1-shared 509189bea (#858 + origin/main b433a24a5) in…
dghosef Oct 30, 2026
5514453
Head sharding: one per-resource switch, shard_over_sp; NodeSubmodule.…
dghosef Oct 30, 2026
d28d18d
Merge origin/main into perf/split-1-shared
dghosef Oct 30, 2026
a908f31
Merge origin/main into perf/split-1-shared
dghosef Oct 30, 2026
50401ad
Name the TP x SP head-sharding test for the kinds it covers; reflow a…
dghosef Oct 30, 2026
78c53ac
Merge origin/main into perf/split-1-shared
dghosef Oct 30, 2026
02c4517
Say the api_switch_interval_s numbers predate #849's output-path rewrite
dghosef Oct 30, 2026
82d9fb5
Drop the head-sharding paragraph from the submodule attributes section
dghosef Oct 30, 2026
ac2cd28
Drop the TP x SP head-sharding test that main's sizing already passes
dghosef Oct 30, 2026
bb15c48
Drop the shard_over_sp sizing test, which main's sizing already passes
dghosef Oct 30, 2026
0cc8902
Merge origin/main into perf/split-1-shared
dghosef Oct 30, 2026
bbe03b6
Conductor: build its instance table from WorkerGraph.replica_ranks
dghosef Oct 30, 2026
0e495ae
Merge origin/main (bb0e0a8d7: #962, #941, #944) into perf/split-1-shared
dghosef Oct 30, 2026
7ee5eb4
Merge origin/main (c96e02b7d: #968, #856, #778, #876) into perf/split…
dghosef Oct 30, 2026
15f8249
Merge origin/main (9f84f18cd: #965) into perf/split-1-shared
dghosef Oct 31, 2026
42bb972
Merge main (c829a71cc) into perf/split-1-shared
dghosef Oct 31, 2026
bff76e2
Merge main (ad0a21eca) into perf/split-1-shared
dghosef Nov 1, 2026
7de9cc6
Pin video decode threads to the CPUs the plan leaves under pinning
dghosef Nov 1, 2026
bffb067
API server: drop the api_switch_interval_s knob
dghosef Nov 1, 2026
e0e8787
KV-aware routing for data-parallel replicas
dghosef Nov 1, 2026
641e06c
Tests: the TP2 publish test's KV managers hold one rank's head
dghosef Nov 1, 2026
045fbde
Keep routing/kv-aware's old history as a parent; the tree is the PR r…
dghosef Nov 1, 2026
a25694a
API server: drop warmup_requests' concurrency option
dghosef Nov 1, 2026
34fbf94
Merge remote-tracking branch 'origin/main' into land/858
dghosef Nov 1, 2026
91063cf
Restore #920 to its approved state on #858 (f8d377cbe's tree)
dghosef Nov 1, 2026
03f7758
Merge origin/main (165b403b7: #794, #950) into perf/split-1-shared
dghosef Nov 1, 2026
a4b5fca
Tests: Canary's decode cap leaves the prefill's token in the budget
dghosef Nov 1, 2026
f991121
Docs: last_prefill_flag for a prompt prefilled over several passes; G…
dghosef Nov 1, 2026
a03415b
Merge #858's final head (f99112154) into routing/kv-aware
dghosef Nov 1, 2026
dc0f81d
Merge origin/main (160b4bc6d, #858 squashed) into routing/kv-aware
dghosef Nov 1, 2026
8f2e4b1
Conductor: _assign_worker_graphs_to_workers indexes the replica inlin…
dghosef Nov 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .claude/skills/diffusion-scaffold/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ A recipe such as LTX-2.5's two-stage distilled one (half-resolution denoise →
Every attention in the DiT should go through a ragged resource, so the model gets the engine's kernels and its backend can change in config.

- `attention_segments(bucket_key)` declares every span a request's layers attend over, as `(label, length)`; the default is one `"main"` span of all its tokens. A layer that attends over a sub-span (a refiner over the image tokens alone, a joint model's per-modality self-attention) gets its own label, and `ragged_for(label)` gives that layer its callable.
- `ragged_for` memoizes one callable per label for the life of a binding. The compiled transformer guards on the identity of the callables it is handed; a fresh one per step recompiles every step.
- `ragged_for` memoizes one callable per label (the resource's `run` with the label bound) for the life of a binding, and a rebinding drops them so none attends through the old resource.
- A model with more than one head geometry (LTX-2.5's video 32×128 and audio 32×64 heads) declares one resource per geometry.
- Cross-attention between spans of the same request (video queries over text keys) is a separate cross-attention resource kind (`RaggedCrossAttentionSpec`, added in #372) whose step names `(q_label, kv_label)` pairs; see "Cross-attention between spans" in `docs/adding_models.rst`. Don't fall back to SDPA for it because the shapes are fixed inside a bucket.
- `joint_attention` in `attention.py` packs per-row q/k/v into the ragged layout (or runs SDPA when no resource is bound, which is what a parity backend uses).
Expand All @@ -50,7 +50,7 @@ Every attention in the DiT should go through a ragged resource, so the model get

- The engine's blanket compile is off for the node (`disable_torch_compile = True`); the model compiles its transformer region with `compile_utils.compile_transformer_forward`, which keeps the exact-op exclusions that preserve eager rounding. Compiling the DiT mostly buys the memory-bound elementwise work (modulation, fp32 norms, RoPE, gating), which on LTX-2.5 was ~45% of an eager step.
- `capture_buckets` lists `(graph_walk, bucket_key)` pairs to capture; `capture_request_inputs` supplies one placeholder row per bucket. A bucket is captured per batch size in `capture_batch_sizes`, and each one costs startup, so capture the shapes you serve, not every shape you accept. `replay_walks` lets another walk reuse a captured bucket.
- The captured graph removes the gaps the per-layer attention graph breaks leave in a compiled-but-eager step; measure both before deciding a model doesn't need capture.
- The captured graph removes the launch gaps of a compiled-but-eager step. Ragged attention breaks that compiled graph per layer unless the resource sets `compile_op=True` (then `run` traces as the `mstar::ragged_attention` custom op), so measure both before deciding a model needs capture.

## The overshoot veto

Expand Down
4 changes: 3 additions & 1 deletion benchmark/waypoint/benchmark_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,9 @@ def _dit_step_timestamps(log_text: str, request_ids: set[str]) -> list[float]:
batch = ast.literal_eval(line.split(marker, 1)[1].strip())
except (SyntaxError, ValueError):
continue
if not isinstance(batch, (list, tuple)) or not any(rid in request_ids for rid in batch):
if not isinstance(batch, (list, tuple)) or not any(
str(rid).split("#", 1)[0] in request_ids for rid in batch
):
continue
match = _LOG_TIMESTAMP_RE.match(line)
if match is None:
Expand Down
78 changes: 72 additions & 6 deletions docs/adding_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,12 @@ The spec types are:
``head_dim`` (all pre-sharding, as in ``KVConfig``), an ``sm_scale`` that
defaults to ``head_dim ** -0.5``, ``backend`` (``RaggedAttnBackend.AUTO``, the
default, ``RaggedAttnBackend.FLASHINFER``, or ``RaggedAttnBackend.DENSE``),
``flashinfer_backend``, and the
``flashinfer_backend``, the
two CUDA-graph ceilings ``max_segments_per_request`` and
``max_tokens_per_request``. ``DENSE`` runs FA3 ``flash_attn_varlen`` (AITER on ROCm)
``max_tokens_per_request``, and ``compile_op``, described under `Cacheless
attention (encoder towers)`_. ``compile_op`` is the model's declaration; the
serving config's ``resources:`` overrides take only the backends and the two
ceilings. ``DENSE`` runs FA3 ``flash_attn_varlen`` (AITER on ROCm)
and falls back to FlashInfer if that kernel is missing. See `Cacheless attention (encoder towers)`_.
* - ``RaggedCrossAttentionSpec(config=RaggedAttentionConfig(...))``
- The cross-attention counterpart: one span of each request attends another
Expand Down Expand Up @@ -786,7 +789,11 @@ encoder node only, and names no cache:

A layer binds the key as it binds any other resource, then attends through the resource's
``run(q, k, v, label=None)``. There is no KV write to pair it with, so no
``AttentionCallable`` is involved.
``AttentionCallable`` is involved. A compiled caller breaks at ``run``; with
``RaggedAttentionConfig(compile_op=True)``, ``run`` traces as the ``mstar::ragged_attention``
custom op instead, so the region keeps one graph across the attention (worth it for a
compiled, uncaptured region; it costs startup time and capture memory where the region
is also captured). An eager call goes straight to the kernel.

The step is an ordinary ``AttentionStep``, and its ``segments`` are the entire layout.
There is no cache to read the layout off, so a label that carries no segment in the
Expand Down Expand Up @@ -814,7 +821,7 @@ step names the ``(q_label, kv_label)`` pairs:

Each pair is planned as its own layout, pairing each request's ``q_label`` span with that
request's ``kv_label`` span; cross-attention is never causal. A layer attends through
``RaggedAttentionCallable(resource, cross_label(q_label, kv_label))``, passing the key
``resource.run(q, k, v, label=cross_label(q_label, kv_label))``, passing the key
span's tokens as ``k`` and ``v``. One resource has one head geometry, so a model whose
attentions differ in head count or head dim declares one spec per (kind, geometry).
LTX-2.5 is the reference (``mstar/model/ltx2_5/submodules.py``).
Expand Down Expand Up @@ -999,6 +1006,12 @@ methods are:
``forward_batched`` only, not ``preprocess`` or ``postprocess``. It can also be set
per instance in ``__init__``, for example only when the model loads in fp32.

Under TP or SP the engine sizes every resource it builds for a node (KV, attention,
recurrent state) for one rank's slice of the heads. A node whose SP ranks split other
work instead, such as one guidance branch per rank, sets ``splits_heads = False``,
and its SP ranks keep all the heads (TP ranks still split them). Nodes sharing a
resource must agree.

``postprocess(...)`` (optional)
Metadata-only fixups that run on the GPU thread. This method must not read tensor
values. Do not call ``.item()``, ``.cpu()`` or ``.tolist()`` here. This is a
Expand All @@ -1010,7 +1023,10 @@ methods are:
``check_stop(...) -> set[str]`` (optional)
Runs off the GPU thread, and may read tensor values. Return the names of the ``Loop``
objects to stop, for example after seeing the EOS token. This is how a decode loop
terminates.
terminates. An AR submodule whose loop ends on a stop token or the token budget sets
``self.token_stop = TokenStop(...)`` in ``__init__`` instead of writing one; that also
gives it ``check_stop_batched``, which checks a whole step off one host copy of its
tokens.

``cleanup_request(self, request_id)`` (optional)
Free per-request state held inside the submodule when a request finishes: buffers,
Expand Down Expand Up @@ -1508,6 +1524,12 @@ Both types share the base ``PiecewiseCudaGraphConfig`` fields:
when the region was leased, for example when the outer step is ``None``, and not
whenever ``runner.can_run`` is true: a refused batch can still fit a bucket, and
replaying it would declare the region's resources twice.
- ``one_row_per_step`` makes the runner lease, check (``can_run``) and replay the region as
one row, whatever the step's batch size, under the step's first request. It is for a
packed region that runs every request's segments as one ragged batch, such as a vision
tower, and needs ``lease_before_step`` and ``capture_batch_sizes=[1]``. The whole step's
segments then count against the ragged resource's ``max_segments_per_request``, so pair
it with a ``can_lease`` that refuses a step with more.
- ``capture_batch_sizes`` lists the batch sizes to record. ``None`` uses the runner
default.
- ``compile`` runs ``torch.compile`` on ``capture_fn`` before capture. The default is
Expand Down Expand Up @@ -1722,6 +1744,47 @@ example, ``configs/qwen3tts.yaml`` selects FA2 under ``talker_attn``,
with a message describing the migration. Move the block under ``resources:``, keyed by
the resource name.

Routing across data-parallel replicas
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When a node group has several replicas, the conductor sends each new request to the
replica where it is cheapest (see "Data-parallel routing" in :doc:`serving`). A resource
whose state makes a request cheaper on one replica than another takes part through its
spec, so models declare nothing for it.

**The hook.** ``NodeResourceSpec.routing_mirror(ctx)`` returns a ``RoutingMirror`` or
``None``, the default. The router asks once per set of node groups with replicas that
holds one of the spec's nodes, and ``ctx`` (a ``RoutingContext``) gives the replica count,
the ranks per replica, the walks of the worker graphs there that hold the spec's nodes,
and the model's KV declarations: the resource's keyed labels with the walks that key each
(empty for a resource that is not a KV cache), and whether the model names a checkpoint.
A mirror is conductor-side bookkeeping that follows the resource's own rules as far as
the conductor's inputs allow. The module that defines one must stay free of kernels,
since the conductor builds it.

**The mirror's methods.** Each is given the request's ``ResourceReqConfig`` for the
resource, which the conductor builds and validates before the pick.

- ``facts(config)`` reports the request's ``RoutingFacts`` on each replica: named counts,
such as ``work`` (prompt positions) and ``kv_hit`` (of those, the ones predicted cached).
The router adds every mirror's row on a replica field by field, then prices the sum
once with ``routing_cost`` in ``mstar/conductor/routing.py``, one term per
``routing_weights`` key, each 0 when its facts are absent.
- ``add_request(config, replica)`` records the placement once the request is dispatched,
and returns a handle.
- ``remove_request(handle, ran)`` releases it when the request leaves. ``ran`` says
whether a pass came back for one of the request's partitions with a walk on the
resource's node groups.

**Adding a resource.** A new resource adds its fields to ``RoutingFacts``, its mirror,
and its term to ``routing_cost`` and ``RoutingWeights``. ``ReplicaRouter`` changes only
if its fields are not counts that add, or if its mirror reads a model declaration other
than the KV ones, which then becomes a ``RoutingContext`` field that ``ReplicaRouter``
fills. ``KVSpec`` with a ``PagedKVConfig`` is the one implementation. Its mirror runs the
worker's own ``PrefixIndex`` per replica over a count of the pool's pages, takes each
request's lease, pages and index entries at dispatch, and exists only where a walk keying
the cache runs and ``PagedKVConfig.prefix_cache_opens`` says the workers open it.

Preprocessing threads
~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -1738,7 +1801,10 @@ default:
preprocess_torch_threads: 4

The setting applies only to the API server process. The conductor and workers keep
torch's default.
torch's default. It also bounds the FFmpeg threads of each torchcodec video decode that
asks ``media_limits.video_decode_threads`` (``Model.load_video`` does): at most 8, and no
more than the CPUs in the process's affinity mask (its cpuset). A CFS CPU quota, such as a
container's ``--cpus`` limit, is not read.

.. _tensor-parallelism:

Expand Down
8 changes: 8 additions & 0 deletions docs/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ From the conductor's status message, sent every second while metrics are on.
conductor dispatched and has not heard back from. The conductor sees whole passes,
so a node running a request's decode loop counts it once for the loop.

``mstar_routing_predicted_saving_total{model_name, term}``
Counter, up to a second old. Per term of the data-parallel replica cost (see
"Data-parallel routing" in :doc:`serving`), the saving predicted on the replica each
request was sent to, in request-equivalents, unweighted. For ``prefix``, each request
adds the share of its prompt predicted cached there, so its rate over the request rate
is a mean of per-request shares, not the token ratio the workers' prefix-cache counters
give.

``mstar_conductor_status_age_seconds{model_name}``
Gauge, seconds, computed at scrape time. Time since the API server received the
conductor's last status message, or since metrics were enabled if none arrived yet.
Expand Down
65 changes: 63 additions & 2 deletions docs/serving.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ A config maps the model's computation-graph nodes to physical GPU ranks. The key
- *(optional)* How many requests run at once. Requests past the cap wait in the
conductor's queue, except a live call (open client input), which is refused with
a 503.
* - ``routing_weights``
- *(optional)* The weights of the data-parallel replica pick (see below), one per
term: ``load`` for the live requests on a replica, and ``prefix`` for the share of
the prompt predicted in its KV prefix cache. Each is a finite number >= 0; ``load``
defaults to 1.0 and ``prefix`` to 8.0. Any other key, or ``load: 0`` while another
weight is above 0, fails loading. ``prefix: 0`` picks by load alone, and ``prefix: 1``
or less keeps a hit below one live request, so it only breaks ties. At data
parallelism, warmup copies run with ``prefix_cache=False``, so
they still spread but do not warm the prefill that starts from cached pages; a
warmup spec that sets ``prefix_cache`` keeps its own value.
* - ``gpu_memory_fraction``
- *(optional)* The share of its GPU each worker may hold once CUDA-graph capture is
done, for workers that share a GPU (see below). Unset, capture plans against
Expand Down Expand Up @@ -305,8 +315,15 @@ A config maps the model's computation-graph nodes to physical GPU ranks. The key
``hf://<owner>/<repo>/<path>`` (a file in a model's HF repo); its modality
comes from the extension, or give ``{path: ..., modality: ...}``.
``repeat: N`` sends ``text`` N times over, a long prompt for a path only
long prompts take (a long-context prefill). A malformed or failing warmup
is logged and skipped.
long prompts take (a long-context prefill). Each entry is sent as many
times at once as the most data-parallel replicas any node group serves (its
ranks over ``tp_size`` x ``sp_size``), so every replica warms. A node group
with fewer replicas, such as one DiT instance beside a replicated VAE, gets
those copies together and may batch them, so its one-request shape can stay
cold. ``concurrency: N`` submits N copies per replica at once, so they can batch, for a step that
compiles per batch size (whether they share a step is the scheduler's
call); a list (``concurrency: [1, 2, 4]``) runs the entry once per size, in
order. A malformed or failing warmup is logged and skipped.
* - ``dist_timeout_s``
- *(optional)* Timeout in seconds for the NCCL world group and its parallel
subgroups during weight load and warmup; serving keeps PyTorch's default.
Expand All @@ -330,6 +347,17 @@ A config maps the model's computation-graph nodes to physical GPU ranks. The key
- *(optional)* Largest message, in KiB, the non-NCCL path takes;
larger ones go to NCCL. It is also the size of the buffer each group
rendezvouses. Default 512.
* - ``api_switch_interval_s``
- *(optional)* GIL switch interval of the API server process, in seconds
(``sys.setswitchinterval``), a positive number (anything else fails at
startup); unset keeps Python's 5 ms. Under streaming load
that process keeps three threads busy (event loop, message thread, data
worker), and a shorter interval hands the GIL between them sooner:
``0.001`` gave Qwen3.5-0.8B text, c=64, +4 to +8% tok/s. A
model whose preprocessing runs long on the data-worker thread can lose from
it (Kokoro's G2P: about -3.6% at c=32), so it is per deployment. It is
re-measured once `#849 <https://github.com/mstar-project/mstar/pull/849>`_
lands, and deleted if neutral.
* - ``tp_async_sched``
- *(optional)* Async scheduling for the parallel nodes: ``true``, ``false``
(default) or a list of node names (see ``MSTAR_TP_ASYNC_SCHED``, which
Expand Down Expand Up @@ -390,6 +418,35 @@ frees only the device pages no other running request reads, though, so a request
shares most of its prompt frees little. Offload helps a pool that runs short now and then.
It doesn't replace the cap.

**Data-parallel routing.** A node group whose ``ranks`` hold several lockstep instances
(``tp_size * sp_size`` ranks each, or one rank) runs each request on one of them, its
replica. The conductor picks it per request, at ingest, as the replica with the lowest
cost: ``routing_weights.load`` times the live requests on the replica (counted per set of
groups that pick together, for each request with a partition on them that is not done at
ingest), plus the price of what the conductor predicts about the request there. Ties go
at random. Every term is in request-equivalents. Groups whose replicas sit on the same
ranks, replica for replica, take one pick together.

Today the one prediction is the KV prefix cache's, on the replicas that run a walk keying
the cache (BAGEL's ``LLM``, also with CFG-parallel nodes): ``routing_weights.prefix``
times minus the share of the request's prompt positions (every label's, keyed or not)
the replica's caches are predicted to hold, all the caches on the replica together. At
the default weights a prompt held whole is worth up to 8 live requests: a request
follows its prefix to a busier replica, and a hot prefix spreads once its replica runs
about 8 times its hit share more requests than another. The term is a share rather than
a token count so that one weight fits models whose prefill and decode costs differ.

The prediction runs the worker's own prefix index (``PrefixIndex``) per replica, over a
count of each replica's pages, and takes a request's steps at dispatch: its lease of the
matched pages, its own pages, evicting on a shortfall, and the index entries of its whole
pages. Its end releases its pages; a request that ends before a pass of it comes back
(aborted while queued, say) also takes back the entries only it made. Workers send
nothing for it, so it does not see admit timing, decode growth, preemption or a reply's
tokens, and it is approximate: a wrong prediction makes a request slower, never wrong.
With no cache that opens (one replica, ``prefix_cache: false``, no walk that keys it, or
replicas above one rank, where the cache stays off: ``prefix_cache_tp`` on a pool with
replicas fails at startup) the pick is the replica with the fewest live requests.

**Single GPU.** Everything on rank 0:

.. code-block:: yaml
Expand Down Expand Up @@ -701,6 +758,10 @@ second old:
``node_names`` of the config's ``node_groups``), running requests with a pass on that
node that the conductor dispatched and has not heard back from. The conductor sees
whole passes, so a node running a request's decode loop counts it once for the loop.
- ``mstar_routing_predicted_saving_total{model_name, term}``: counter, per term of the
data-parallel replica cost, the saving predicted on the replica each request went to,
in request-equivalents. For ``prefix``, each request adds the share of its prompt
predicted cached there.
- ``mstar_conductor_status_age_seconds{model_name}``: seconds since the API server
received the last status message, or since metrics were enabled before the first one.
More than a few seconds means the conductor stopped reporting.
Expand Down
Loading
Loading