Model families¶
What a model family implements and what it gets back (flide.formats.base), and the registry that finds a
checkpoint's family (flide.formats).
base ¶
What a model family hands the runtime, and what it gets back.
A family turns a request into a plan: one shared prefix, one suffix per branch, and for each branch the reads to take. The runtime runs the backbone over packed plans, takes the hidden states each read names, passes them through the named head and returns every branch's head outputs. The family turns those into the response. The runtime knows nothing about prompts, answer slots or calibration.
Read
dataclass
¶
Hidden states of one branch, fed to one head.
head: name of a head the family loaded; None returns the hidden states themselves. layer: FINAL (None) reads the output of the last layer after the final norm; an integer k reads the raw residual stream after decoder layer k (1-based; 0 is the input embeddings), and the backbone stops after the highest layer any read of the micro-batch needs. positions: offsets into the branch's own tokens, negative from its end; -1 is its last token.
Plan
dataclass
¶
reads is one tuple of reads shared by every branch, or a list with one tuple per branch.
data is the family's own bookkeeping for finish; the runtime only carries it.
Media: vision holds the backbone's vision inputs for media inside the prefix (for qwen3_5 the
processor's pixel tensors and grids); the prefix ids carry the placeholder tokens the features replace.
positions are the prefix's rotary positions [3, P] when they are not 0..P-1, and suffix tokens start
at position P + offset. The backbone fills both from vision when the family leaves them empty.
An empty prefix makes every suffix a sequence of its own (nothing shared); with attention "blocks" each such
sequence is one block, read bidirectionally whole in the full-attention layers. Such sequences may hold media under
attention "blocks" or "set": the same media in each, inside the head every sequence starts with, which vision's
token types (when it has them) cover; positions and offset are then lists, one per sequence.
attention "blocks": in the full-attention layers the prefix sees all of itself and each suffix sees the prefix
and all of itself (the block-bidirectional mask some checkpoints are trained with); recurrent layers stay causal,
and the prefix still never sees a suffix, so it is shared exactly. Such a plan needs a backbone with
block_attention, and takes no session states.
attention "prefix": in the full-attention layers the prefix sees all of itself, as under "blocks", and each suffix
sees the prefix and itself one way (a request read both ways, then a question's tail read one way). It needs a
prefix and a backbone with prefix_attention, and takes no session states.
attention "set": no prefix; each suffix is one sequence, a state and the questions packed after it, cut by
segments (one tuple per suffix: the state's end, then each question's end, the last the sequence's length). In
the full-attention layers a state token sees the whole sequence and a question's token the state and its own
question; every other layer reads the sequence causally, so a question still hears the ones before it there. It
needs a backbone with set_attention, and takes no session states.
Format ¶
A model family: how its checkpoints are asked and read. Subclasses register with
flide.formats.register and are published to other installs through the flide.formats
entry point group.
detect
classmethod
¶
detect(model_dir: str, config: Any, decision_config: dict | None) -> bool
Whether this family claims a checkpoint that does not name its format in decision_config.json.
run_dir
classmethod
¶
run_dir(model_dir: str) -> str
The directory the engine loads the checkpoint from: its own, unless the family's release keeps the weights' LoRA adapter where the loader does not look (the family then links it under lora/ of a directory it makes).
for_thread ¶
for_thread() -> 'Format'
A twin that plans and finishes on another thread. It shares everything except the tokenizer, which keeps mutable truncation and padding state and fails ("Already borrowed") when two threads encode at once.
load_heads ¶
load_heads(backbone) -> dict[str, Any]
Heads by name; each maps hidden states [rows, hidden] to outputs [rows, ...]. A head with on_device true
keeps its outputs on the device, for a family that reads them there again (finish).
plan ¶
plan(request, **options) -> Plan
The request as a Plan: the state's tokens as the prefix, one suffix per question and the reads of each.
Runs on a CPU thread, often several at once (for_thread); raise ValueError to refuse the request (the
server answers 422 with the message).
follow_up ¶
follow_up(request, plan: Plan, outputs: Sequence[Sequence[Any]], **options) -> Plan | None
A further plan that depends on this plan's outputs (a second read of the questions the model is unsure
about), or None. The runtime runs it and asks again; finish gets the last plan and its outputs, so a family
carries what it needs from earlier rounds in that plan's data.
finish ¶
finish(request, plan: Plan, outputs: Sequence[Sequence[Any]], **options)
outputs[b][r] is the head output of read r of branch b: one row per position, as lists (a tensor of
those rows on the device for a head with on_device).
rooted ¶
rooted(plan: Plan) -> Plan
A causal text plan without a prefix as the same computation with one: the start its sequences share (each keeps at least the tokens its reads look at, and one token) becomes the prefix, so the flat graphs and the session cache take it (a family whose prompt is one stream read at several positions). Other plans as they are.
media_bytes ¶
media_bytes(ref: str, what: str = 'image') -> bytes
The bytes of a base64 data URL or bare base64 string; ValueError (a 422) when it is not base64 or is larger than
settings.max_media_bytes.
check_limits ¶
check_limits(family: Format, request) -> None
Refuses a request with a choice or a score larger than the family reads.
formats ¶
Model families are plugins. The core ships two generic families, next_token and template, and imports no other by name.
A family package registers its Format subclass in the flide.formats entry point group:
[project.entry-points."flide.formats"]
myjev = "myjev_package:MyJev"
A script can also call register directly.
Which family serves a checkpoint, in order: the name given explicitly; the format_id in the
checkpoint's decision_config.json; the first family whose detect claims it; the built-in next_token
family, which reads any chat model at the first token of its reply (logged as such). A checkpoint whose
decision_config.json names a format that is not installed is refused, with the package to install.
register ¶
register(name: str, format_ids: tuple[str, ...] = ())
Class decorator: make a Format available under name, and under each decision_config format_id.
detect ¶
detect(model_dir: str, config: Any, name: str | None = None) -> type[Format]
The family that serves a checkpoint: name when given, else the one its decision_config.json names by
format_id, else the first family whose detect claims it, else next_token (a chat model read at the first token
of its reply).