Skip to content

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

  1. The API. flide serve (flide/api/serve.py, server.py) takes POST /v1/systemone, validates the body against the schema in flide/formats/schema.py and admits it (admission.py). With --frontends N, N processes parse and plan requests and one process keeps the GPU (frontend.py).
  2. The family plans it. A model family (flide/formats/, or a plugin in plugins/) renders the prompt and tokenizes it on a CPU thread. Its plan returns a Plan (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.
  3. The scheduler groups plans. Under flide serve the GPU thread takes every plan waiting and runs them as one round (flide/runtime/online.py). flide run cuts 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.
  4. 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.
  5. 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.py on 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 in flide/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).
  6. 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).
  7. The family answers. finish turns 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.