Engine¶
The class behind flide serve and flide run, for answering requests from Python. Engine
shows it in use; this page lists every public method, from the docstrings in the code.
Engine ¶
A checkpoint loaded on one GPU with its model family: requests in, answers out, in this process (what
flide serve and flide run run on). decide answers one request; run_plans answers many plans in
packed micro-batches; forward runs one round of plans as the server does.
__init__ ¶
__init__(model: str, format: str | None = None, device: str | None = None, dtype: str = 'bfloat16', budget: int | None = None, backbone_options: dict | None = None, capture: bool | int = 4096, session_cache_gb: float = 0.0, session_min_tokens: int | None = None, batch_invariant: bool = False, adapters=None, share: 'Engine | None' = None, adapter: str | None = None, **format_options)
device: cuda:N (default cuda:0); "mlx", the default on a Mac, is the MLX engine (__new__).
batch_invariant: the batch-invariant products for every engine of the process (settings). adapters:
a lora.Union of LoRA adapters to serve beside this checkpoint (serve --lora); this engine runs the base model.
share: run on that engine's backbone as its adapter named adapter.
decide ¶
decide(request, **options)
Answer one request (a SystemOneRequest): (the response, the server's record of it). The record's path is
graph when the request ran in a CUDA graph, and timing splits its time into planning and the forward.
options go to the family's plan and finish.
forward ¶
forward(plans: Sequence[Plan], mode: str = 'graphs') -> tuple[list, list[str]]
Head outputs of several plans in one round. "graphs" replays each plan's graphs back to back (one host sync at the end) and packs only the plans that do not fit them; "batch" runs the plans the flat graphs take together, one replay for as many as fit (no padding between them), and the rest as "graphs"; "packed" runs one packed forward over all of them; "alone" is "graphs" with every plan that does not fit packed by itself, so no plan's numbers depend on which others share the round (bit for bit the same answers at any load).
run_plans ¶
run_plans(plans: Sequence[Plan | None], budget: int | None = None, log_fn: Callable[[str], None] | None = None, warmup: int = 0, _merge: bool = True) -> tuple[list, dict]
Head outputs for every plan: out[plan][branch][read] is a list of rows, one per read position.
Requests that share a prefix run as one multi-branch plan, which computes that prefix once -- 7x on eight
requests over a 6k prefix. That changes the shape of the prefix's computation, so the answers are bit-for-bit
the same only with the invariant products on; without them the merge is a rounding-level approximation, so it
stays off unless batch_invariant is set.
cost ¶
cost(plan: Plan) -> int
Tokens a plan computes: all of them, less the start of its prefix a saved session state covers.
warmup ¶
warmup() -> None
One packed forward over made-up requests, so the kernels of the packed path (requests the graphs do not take, rounds of several requests) are compiled before the first real one instead of stalling it.