mstar.worker.batch_builder#
Batch composition: which ready rows of one (node, walk) run this step.
The MicroScheduler picks the (node, walk) and owns the mechanics (popping
ready queues, the backlog, holds, TP follow); a BaseBatchBuilder decides
which rows the step takes out of a speculation chain’s own rows, the backlog
and the ready queues (pick), and splits what was popped into the step, the
rows that stay parked in the backlog and the ones that go back to their ready
queues (build_batch).
Functions
|
Max-min fair share of |
|
|
|
|
|
The rids of |
Classes
|
|
|
|
|
|
One capture group per step, up to the cap; who goes first when the rows don't all fit is the node's StepOrder. |
|
|
|
|
How rows line up for a step that can't take them all. |
|
Every row that could run one step of a scheduling key, for |
|
- class mstar.worker.batch_builder.BaseBatchBuilder[source]#
Bases:
ABC- abstractmethod build_batch(request)[source]#
One step’s rows out of
request’s backlog and entries.- Parameters:
request (BatchBuildRequest)
- Return type:
- chain_must_yield(backlog, live_rids, anchor, capture_group)[source]#
Whether a speculation chain anchored at
anchorhas to stop sobacklog’s live rows can run: a step sharing the chain’s capture group would never take them.
- abstractmethod pick(candidates)[source]#
Who runs one step: the one place a capped step’s rows are chosen, for a speculation chain and for a step the scheduler builds fresh.
- Parameters:
candidates (StepCandidates)
- Return type:
- class mstar.worker.batch_builder.BatchBuildRequest(node_name: str, graph_walk: str, backlog: 'ScheduledBatch | None' = None, fresh: 'ScheduledBatch | None' = None, pick: mstar.worker.batch_builder.StepPick | None = None, continuing: 'ScheduledBatch | None' = None, max_batch_tokens: int | None = None, walk_max_tokens: dict[str, int] | None=None, row_tokens: dict[int, int]=<factory>, chunkable: set[int] = <factory>, min_chunk_tokens: int = 1, chunk_alignment: int = 1, start_order: dict[int, int]=<factory>)[source]#
Bases:
object- Parameters:
node_name (str)
graph_walk (str)
backlog (ScheduledBatch | None)
fresh (ScheduledBatch | None)
pick (StepPick | None)
continuing (ScheduledBatch | None)
max_batch_tokens (int | None)
min_chunk_tokens (int)
chunk_alignment (int)
- backlog: ScheduledBatch | None = None#
- continuing: ScheduledBatch | None = None#
- fresh: ScheduledBatch | None = None#
- class mstar.worker.batch_builder.BatchBuildResult(scheduled, backlog, returned, chunk_tokens)[source]#
Bases:
NamedTuple- Parameters:
scheduled (ScheduledBatch | None)
backlog (ScheduledBatch | None)
- backlog: ScheduledBatch | None#
Alias for field number 1
- scheduled: ScheduledBatch | None#
Alias for field number 0
- class mstar.worker.batch_builder.BatchBuilderType(*values)[source]#
Bases:
Enum- FAIR_SHARE = 'fair_share'#
- FIFO = 'fifo'#
- class mstar.worker.batch_builder.FIFOBatchBuilder[source]#
Bases:
BaseBatchBuilderOne capture group per step, up to the cap; who goes first when the rows don’t all fit is the node’s StepOrder.
When every row fits, the step takes them in the order backlog, the chain’s own rows, then the queues: nothing is left out, so the order only decides the capture group, which the chain’s or else the first row’s sets, and a row of another group waits for a step of its own. When they don’t all fit, every row goes in the order’s sort and the first sets the group. A row of another group then waits for a step of its own: under TURNS the rows behind it pass it, since it leads the next step; under ARRIVAL they don’t, or rows that came later would join the step’s holders and keep it from it.
Under a combined walk a step of one walk takes that walk’s cap and a mixed step the combined walk’s own, or with none the smallest of the caps of the walks present in it; a walk with no row in the step does not cap it. Rows join in order; one whose walk would cap the step at or below the rows already in it is left out.
Of the rows
build_batchgets, a fresh row the cap pushed out goes back to its ready queue only on a step that served a backlog. Parking it would refill the backlog from the queues on every pass, so it would never drain, and since a key holding a backlog is served before any other node, that node starves the rest: onwan22.yamlwithditcapped at 1 a fifth request’stext_encoderwaited 48.7 s for its first step against 0.2 s before backlogs were topped up. With no backlog it parks, so a split set drains before anything new starts. A row held back for any other reason – OOM backoff, pending remove, a foreign capture group, a walk the combined cap left out – always parks: it cannot run this step whoever holds it.Under a token budget, of the rows the pick took, prompts are served in the order they started (
fill_token_budget_in_start_order), and the caller’s rows mid-prefill come first. A row the budget leaves out always parks, ahead of the cap’s leftovers, because a budgeted walk’s backlog is its line: the Rust runtime scans ready rows in handle order, so a row sent back rejoins behind rows that arrived after it. Such a backlog can stay non-empty under sustained load; the worker’s fairness peek still hands the step after a prompt step to other ready work.- build_batch(request)[source]#
One step’s rows out of
request’s backlog and entries.- Parameters:
request (BatchBuildRequest)
- Return type:
- pick(candidates)[source]#
Who runs one step: the one place a capped step’s rows are chosen, for a speculation chain and for a step the scheduler builds fresh.
- Parameters:
candidates (StepCandidates)
- Return type:
Bases:
FIFOBatchBuilderFIFOBatchBuilderwith the token budget shared max-min fair (fill_token_budget): every waiting prompt advances each step, so a long prompt’s first token waits on every other prompt’s prefill too.
- class mstar.worker.batch_builder.LineOrder(key, strict)[source]#
Bases:
NamedTupleHow rows line up for a step that can’t take them all.
- class mstar.worker.batch_builder.StepCandidates(graph_walk, continuing=(), own_walk=None, backlog=(), queued=(), walk_of=<function StepCandidates.<lambda>>, one_walk=None, ready=<function StepCandidates.<lambda>>, capture_group=None, walk_caps=<factory>, walk_row_caps=<factory>, line_order=<function StepCandidates.<lambda>>)[source]#
Bases:
objectEvery row that could run one step of a scheduling key, for
pick.- line_order()#
- ready()#
- walk_of()#
- class mstar.worker.batch_builder.StepPick(taken, continuing, room, held_back, ordered)[source]#
Bases:
NamedTuple- Parameters:
- mstar.worker.batch_builder.fill_token_budget(rids, tokens, chunkable, budget, min_chunk=1, align=1)[source]#
Max-min fair share of
budgetoverrids: rows under an equal share go in whole, the rest split what is left (chunkable rows) or sit out. A cut row takes at leastmin_chunktokens, or all it has left if that is fewer: when the share is smaller, only as many rows as what is left holds are cut, and if it holds none, they wait for the next step. Never empty while a row exists: the first row runs over budget if it must. Returns (rid -> tokens taken, rids left out).
- mstar.worker.batch_builder.fill_token_budget_in_start_order(rids, tokens, chunkable, budget, min_chunk=1, start_order=None, align=1)[source]#
budgetoverridsfirst come, first served. Rows under an equal share go in whole, and then any row that can finish in what is left, shortest first, so a short prompt never waits behind a long one. The rest follow in start order – prompts already mid-prefill by when they started (start_order), then the others as listed – each taking all it needs of what is left, so a prompt finishes before the next one starts and its first token does not wait on every other prompt’s prefill. The first that does not fit is cut to what is left, rounded down to a multiple ofalign, if that is at leastmin_chunktokens, and otherwise waits for the next step; one that cannot be cut sits out without holding up the rows behind it. Never empty while a row exists: the first row runs over budget if it must.The first prompt in line (the oldest mid-prefill, else the first not started) keeps
min_chunkof the budget from the other prompts in the finishing pass, so a steady stream of short prompts cannot starve it, before its first chunk or after. Returns (rid -> tokens taken, rids left out).
- mstar.worker.batch_builder.make_batch_builder(kind)[source]#
- Parameters:
kind (BatchBuilderType)
- Return type: