How Flide works¶
A decision model reads an input and answers typed questions about it with probabilities. Flide never generates. It reads the input once, forks the model's state into one branch per question, reads each branch at the positions the model family names and turns those reads into answers. This page follows a request through the code, so a contributor knows where a change belongs.
A request's path¶
- The API.
flide serve(flide/api/serve.py,server.py) takesPOST /v1/systemone, validates the body against the schema inflide/formats/schema.pyand admits it (admission.py). With--frontends N, N processes parse and plan requests and one process keeps the GPU (frontend.py). - The family plans it. A model family (
flide/formats/, or a plugin inplugins/) renders the prompt and tokenizes it on a CPU thread. Itsplanreturns aPlan(flide/formats/base.py): the state's tokens once as the prefix, one suffix per question, and the reads of each branch. Prompts, answer labels and calibration live only in the family; the runtime never sees them. - The scheduler groups plans. Under
flide servethe GPU thread takes every plan waiting and runs them as one round (flide/runtime/online.py).flide runcuts a file's plans into micro-batches under a token budget (flide/runtime/schedule.py); a plan larger than the budget is split by its suffixes, each piece carrying the whole prefix. - The session cache resumes what it can. With
--session-cache-gb, the state of an earlier prefix is saved at a few positions (flide/runtime/session.py), and a later request that starts with the same tokens computes only the rest. Requests of one round that share a start compute it once. - The backbone runs one flat stream. A round becomes one token stream with no batch dimension and no padding:
every prefix first, every suffix after them (
flide/backbones/pack.py), with each token's job, branch and position beside it. A round that fits runs as one replay of a CUDA graph captured at start; others run eagerly (flide/runtime/engine.py). In the backbone (flide/backbones/):- full attention gives each query the key ranges it may see (its prefix, then its own branch) and runs one kernel
over them (
flide/kernels/attention.py;attention_gl.pyon GPUs with about 100 KB of shared memory a block); - linear attention (Gated DeltaNet) runs over the prefixes, then over the branches from the prefix's state
(
flide/kernels/gdn.py, with flash-linear-attention's forward kernels inflide/kernels/fla); - the feed-forward and mixture of experts run token by token (
flide/kernels/moe.py), in 8 bits when the model was loaded with--quantize(flide/backbones/quant.py).
- full attention gives each query the key ranges it may see (its prefix, then its own branch) and runs one kernel
over them (
- The heads read the branches. Each read takes the hidden state at its positions and passes it through the head the family named (the output head's rows for the answer labels, or a readout of the family's own).
- The family answers.
finishturns the head outputs into the response: a probability per option, a yes probability, or a score.
Why forking gives the same answers¶
A branch sees the prefix and itself, never another branch, and the prefix never sees a branch. So each question's
answer is the one the model gives to the state and that question alone, computed once for the state instead of once
per question. Rounding can still differ with what a request is batched with, as in any engine; --batch-invariant
fixes one summation order for every product, so a request gets the same bits alone or under load.
flide verify checks both on your model and GPU.
Where things live¶
Each row uses only the rows above it.
| Directory | What it holds |
|---|---|
flide/settings.py, flide/states.py |
process-wide switches; the saved backbone states that the session cache, the backbones and the vLLM hookup share |
flide/kernels |
the Triton and Gluon kernels, what the GPU can do (gpu.py), the prebuilt kernel bundles (prebuilt/) |
flide/lora.py |
LoRA adapters beside the weights, and the slots that several adapters on one model share |
flide/integrations |
reading the keys and values of a vLLM process on the same GPU |
flide/formats |
the Format interface, the request and answer types, the built-in families (next_token, template) and the shipped template configurations (known/) |
flide/backbones |
one decoder per architecture (Qwen3.5, Qwen2.5 and Qwen3, Gemma 4, LFM2 and LFM3), packed batches, loading, quantization, the products of tensor parallelism |
flide/apple |
the engine on a Mac's GPU through MLX: its Qwen3.5 decoder and its Gated DeltaNet kernel, picked once when an engine starts on device mlx |
flide/runtime |
the engine, scheduling, CUDA graphs, the session cache, starting the ranks of tensor parallelism, the kernel cache |
flide/api |
the HTTP server, admission, front-end processes |
plugins/ |
model families as installable plugins, one package each |
tests/ |
the tests, run together by tests/run.py |
Kernels without compiling¶
Triton compiles a kernel the first time it runs, which takes minutes for a model. Flide ships the compiled kernels of
every supported GPU and Triton release in one archive (flide/kernels/prebuilt), keyed by each kernel's source, and
installs them into Triton's cache at start (flide/runtime/kcache.py). A first start on a supported GPU compiles and
tunes nothing. A change to a kernel changes its key, so the kernels are exported again for a release.
Tests¶
python tests/run.py runs every test in its own process. Tests that need a GPU print SKIP without one. CI runs the
whole suite on CPU over two torch releases and three Python versions, with line coverage on the run's page. Before a
release the suite runs again on GPUs, together with regression runs against the previous release (the same bits on
four reference models), accuracy against each family's own release and a float32 referee, and fresh installs that
must start without compiling.