Skip to content

vLLM

The executable model and oracle correspondence use vLLM 0c87a197. They cover a synchronous scheduling fragment, not every vLLM feature. The source survey below separately examines full-attention scheduling and KV cache in v0.31.0rc2. The oracle does not establish equivalence with that entire version.

Tagged behavior

Scheduler.schedule shares a token budget between resident and waiting requests, using computed progress to determine selected work. Allocation failure triggers victim selection: FCFS and priority paths choose differently. Scheduler

KVCacheManager.get_computed_blocks finds reusable prefixes, while allocate_slots acquires space for scheduled work and lookahead. Identical prefixes can share blocks across requests, requiring more than a session's cached length. KV manager

The scheduler guards whether victim blocks can actually be freed and manages deferred free. AsyncScheduler tracks output placeholders and in-flight results. Releasing or publishing KV before completion can create invalid reuse. Victim/free guard, async scheduler

Executable serQ model

vLLM deployment in serQ

examples/multi-turn/vllm.sq is vLLM v1 on one device at the pinned revision (ref/vllm at 0c87a197): continuous batching with chunked prefill, a block pool with an LRU prefix cache, and recompute on preemption. The sections below build it a part at a time. Each says what vLLM does, what the program needs for it, and how serQ writes it. vLLM v1 as a serQ program has the line-by-line correspondence with citations.

Settings

vLLM's engine is configured by a handful of numbers. The program names each once and takes the ones a run varies from the command line (serq run examples/multi-turn/vllm.sq --workload examples/workloads/chat.sq --max_seqs 32). The constants come before main and the arguments open it; the rest of the program is inside main. The program is the deployment: the client is a file of its own, examples/workloads/chat.sq, given when the program runs (the client).

examples/multi-turn/vllm.sq
let B = 8192;  // max_num_batched_tokens
let bs = 16;  // block_size
let a = 2e-5;  // compute per scheduled token (s)
let omega = 2e-4;  // weights read per iteration (s)
let beta = 2e-9;  // KV read per iteration per resident context token (s)
let c0 = 0;  // fixed cost per iteration (s)

fn main() {
  let max_seqs = args.number("max_seqs", 16);  // max_num_seqs
  let blocks = args.number("blocks", 10000);  // num_gpu_blocks (less the null block)
  let chunk_cap = args.number("chunk_cap", inf);  // long_prefill_token_threshold (inf: none)
serQ vLLM Meaning
B max_num_batched_tokens the token budget of one step
bs block_size tokens per KV block
max_seqs max_num_seqs requests resident at once
blocks num_gpu_blocks, less the null block KV capacity in blocks
chunk_cap long_prefill_token_threshold the most one prefill takes per step; inf for none
a, omega, beta, c0 — the cost model in seconds: a per scheduled token; omega per step, to read the weights; beta per step per resident context token, to read its KV; c0 fixed per step

KV memory: a block pool with a prefix cache

vLLM's KV cache is a pool of fixed-size blocks. A finished or preempted request's full blocks go back to the free queue still hashed, so a later turn of the same session can reuse them; when the free queue runs dry the oldest freed block is evicted first. When a running request needs a block and none is free, the most recently admitted request is preempted: its blocks go back to the cache, and it re-enters the waiting queue at the head (scheduler.py:1539-1582) to recompute what was lost.

serQ says this with a device that has KV capacity and a pool on it whose three clauses are those three rules:

device gpu {
  compute (t) = t * a;
  hbm (k) = omega + beta * k;
  kv cap blocks * bs;
}
pool kv on gpu { block bs; evict lru; preempt lifo; }

block bs makes the pool hand out whole blocks, evict lru evicts cached blocks tail first, and preempt lifo picks the last admitted request as the victim. The device also carries the cost of a step: compute per scheduled token and hbm for the weights plus the KV read.

The engine's two caps

Each step vLLM schedules at most max_num_seqs requests and at most max_num_batched_tokens tokens (scheduler.py:872, 877-879). These are the engine's two capacities, the first lines of its block; the request, the schedule and the cost below are the rest of it:

engine vllm on gpu {
  reqs cap max_seqs;
  tokens cap B;

What a request does

A request in vLLM is a prompt to prefill and an output to decode, but two details make it more than that.

  • Preemption keeps the tokens, not the KV. A preempted request is rescheduled with every token it has, the prompt plus what it generated, and recomputes their KV (scheduler.py:1560-1561). So the program needs known, every token the request has, read again at each admission: max(kept, computed + 1), never fewer than an earlier attempt had.
  • A prefix hit is full blocks, never the last token. The last token is recomputed for its logits (kv_cache_manager.py:289-300), so the reusable prefix is the cached full blocks of known − 1.

In serQ these are the engine's own state of the request, which the scheduler reads when it admits: request.known is every token the request has, the generated ones kept across a preemption, and request.hit the cached full blocks of request.known − 1 it reuses. A request needs no procedure of its own: the server calls the engine with its input and output, vllm (input, output);, and the engine prefills what the cache does not hold, then decodes, allocating a block at a time as allocate_slots does. The admission below says what is reused (reuse) and what a finished request leaves cached for the next turn (cache).

Scheduling the running requests

Each step first hands the budget to the running requests in admission order: one token to each decoding request, and up to the chunk cap to a prefilling one. vLLM applies long_prefill_token_threshold only while another request is running or waiting; a request alone takes the whole budget (scheduler.py:606-616). That rule is written in the program, not assumed by the language. It opens the schedule block, which the admission below continues:

scheduler {
  let threshold = running.count + waiting.count > 1 ? chunk_cap : inf;
  advance running each at most (threshold);

A constant cap would not be vLLM's, and serq target refuses it.

Admitting waiting requests

With the budget the running requests leave, vLLM admits waiting requests FCFS while the request cap and the KV blocks allow, and the first that does not fit blocks the rest. Four details shape the admission:

  • the prefix lookup happens when the scheduler admits, not when the request queues (scheduler.py:932-939);
  • it allocates the reused tokens plus the chunk the budget allows (scheduler.py:1078-1128, 1214-1226);
  • it admits only if every known token fits, the reused ones counted (scheduler_reserve_full_isl, on by default: config/scheduler.py:191, kv_cache_manager.py:515-531);
  • nothing is admitted in a step that preempted (scheduler.py:869).

In serQ these are the taking units, the reserve, and the while, the last statement of the scheduler block, with the prefix it reuses and the blocks it leaves cached:

  admit waiting while (running.preempted == 0) each at most (threshold)
    taking reqs (1), kv (min(request.known, request.hit + budget_left(vllm)))
      reserve (request.known)
    reuse (floor(request.known - 1, blocksize(kv)))
    cache (request.input + request.output);
}

Admission has the full argument.

The cost of a step

A step's time is the larger of its compute and its memory traffic, plus a fixed overhead. It is the engine block's last line:

worker {
  forward (c0 + max(hbm(batch.kv_decode + batch.kv_prefill), compute(batch.tokens)));
}

The waiting queue the engine admits from is a pool on the engine, served in arrival order:

pool reqs on vllm { queue fifo; }

The client

Nothing in the workload is vLLM, and it is not in the program: it is examples/workloads/chat.sq, a file of its own, given when the program runs (--workload). It declares its own settings: Lambda sessions per second, Z the mean tool time, p the chance a session continues. Sessions arrive, each turn brings a prompt of n new tokens on a context of K and wants o back, and after a turn the session calls a tool and returns with probability p. The workload sends each request its prompt and its output, send (input: K + n, output: o), and the server takes the output hidden, server (input, hidden output): the scheduler cannot read the output length: it knows max_tokens, not when EOS comes (sched/utils.py:98-119).

examples/workloads/chat.sq
workload {
  arrive poisson(Lambda);
  init { set K = 0; }
  turn {
    set n = ceil(K == 0 ? ~uniform(1000, 3000) : ~exp(500));
    set o = floor(~exp(200)) + 1;
    set more = ~bernoulli(p);
  }
  send (input: K + n, output: o);
  session {
    turn;
    while (more) {
      set K = K + n + o;
      tool (~exp(Z));
      turn;
    }
  }
}

A turn is one request to the engine, on the whole context:

// the scheduler knows max_tokens, not the length (sched/utils.py:98-119)
server (input, hidden output) {
  vllm (input, output);
}

Different workloads runs this engine under other clients.

The whole program, and its workload
examples/multi-turn/vllm.sq
// vLLM v1 on one device (ref/vllm at 0c87a197), as a serQ program.
// docs/use-cases/vllm.md explains it a part at a time. It runs under several
// workloads (examples/pairs.json, docs/use-cases/workloads.md).
use "std/args";

let B = 8192;  // max_num_batched_tokens
let bs = 16;  // block_size
let a = 2e-5;  // compute per scheduled token (s)
let omega = 2e-4;  // weights read per iteration (s)
let beta = 2e-9;  // KV read per iteration per resident context token (s)
let c0 = 0;  // fixed cost per iteration (s)

fn main() {
  let max_seqs = args.number("max_seqs", 16);  // max_num_seqs
  let blocks = args.number("blocks", 10000);  // num_gpu_blocks (less the null block)
  let chunk_cap = args.number("chunk_cap", inf);  // long_prefill_token_threshold (inf: none)

  device gpu {
    compute (t) = t * a;
    hbm (k) = omega + beta * k;
    kv cap blocks * bs;
  }
  pool kv on gpu { block bs; evict lru; preempt lifo; }
  engine vllm on gpu {
    reqs cap max_seqs;
    tokens cap B;
    scheduler {
      let threshold = running.count + waiting.count > 1 ? chunk_cap : inf;
      advance running each at most (threshold);
      admit waiting while (running.preempted == 0) each at most (threshold)
        taking reqs (1), kv (min(request.known, request.hit + budget_left(vllm)))
          reserve (request.known)
        reuse (floor(request.known - 1, blocksize(kv)))
        cache (request.input + request.output);
    }
    worker {
      forward (c0 + max(hbm(batch.kv_decode + batch.kv_prefill), compute(batch.tokens)));
    }
  }
  pool reqs on vllm { queue fifo; }

  // the scheduler knows max_tokens, not the length (sched/utils.py:98-119)
  server (input, hidden output) {
    vllm (input, output);
  }
}
examples/workloads/chat.sq
// Multi-turn chat sessions: a context that grows by each turn's prompt and
// output, a tool call between turns (examples/multi-turn/vllm.sq starts
// under it, and vllm_lmcache.sq and vllm_lmcache_replicas.sq run it).
use "std/args";

let p = 0.9;  // continue after a turn
let Lambda = args.number("Lambda", 0.3);  // sessions per second
let Z = args.number("Z", 3.0);  // tool time (s)

workload {
  arrive poisson(Lambda);
  init { set K = 0; }
  turn {
    set n = ceil(K == 0 ? ~uniform(1000, 3000) : ~exp(500));
    set o = floor(~exp(200)) + 1;
    set more = ~bernoulli(p);
  }
  send (input: K + n, output: o);
  session {
    turn;
    while (more) {
      set K = K + n + o;
      tool (~exp(Z));
      turn;
    }
  }
}

What the model leaves out

Requirement Current expression Limit of the model
Token budget and chunked prefill engine … { tokens cap …; scheduler { … each at most (…); } } Resident selection then waiting admission is a specific policy
Request slots and KV space taking, reserve, the engine's request state Tagged fit/lookahead conditions are not fully validated
FCFS/priority Queue order and preempt lifo; PRIORITY is preempt by (-priority, -t0) requeue tail beside queue by (priority, t0) No oracle scenario checks the PRIORITY victim
Shared prefix cachedin, reuse, cache Cache identity is session-based, not content-key shared objects
Local decode preemption request.known, which keeps the generated tokens Latest-tag recovery paths need differential validation
Async and speculative execution Cost expressions, explicit leases/transfers In-flight scheduler state and proposed/accepted progress remain absent

Validation

The vLLM correspondence records the existing scheduler scenarios and trace. Those checks apply to their stated reference and paths, not to every feature of v0.31.0rc2.

See vendor plugins for the reference versions, executable model and remaining limitations.

Measured replay

examples/replay/vllm_replay.sq models the A100/Qwen3-8B testbed; its workload, examples/workloads/vllm_replay.sq, replays examples/replay/data/short_base.csv (333 sessions). It uses block size 16, token budget 512, 64 request slots and 128 160 tokens of KV capacity. Session i starts at i * spacing; later turns follow their recorded think times. This is a separate calibration from the tagged-source survey above.

Cost and calibration

tools/a100/step_fit.json records a fit to 3 022 measured steps:

cost = c + d * decoders + e * kv_decode + a * prefilled + b * attention
Coefficient Value
c 13.9 ms
d 41 µs
e 0.138 µs
a 51.5 µs
b 4.02 ns

The fit's mean absolute percentage errors are 2.7% for decode, 5.6% for prefill and 5.7% for mixed steps. For served-path replay, two light-load runs calibrated c_it = 4 ms per step and c0 = 40 ms per request. These are effective parameters: those runs do not uniquely identify the split between per-step and per-request overhead.

Reported comparison

Session spacing Policy Predicted mean TTFT Measured mean TTFT
3.0 s Unpinned waiting prefixes 0.605 s 0.441 s
2.5 s Unpinned waiting prefixes 39.1 s 34.6 s
2.5 s Pinned waiting prefixes 0.888 s 0.878 s

The pinning prediction preceded its measurement. Each point is one run; the two 2.5 s measurements were made on different days, and only the pinned run carried a step tracer. The run records are not published; the scripts are in serving-queue-theory/scripts/exp/. This table records that comparison, not a reproducible benchmark shipped with this repository.