Skip to content

Context variables

A context variable is supplied at specific evaluation moments. Reading it elsewhere is a link error: a session cannot use set x = tokens;.

The names the language supplies are the context variables below, inf, an engine's lists running, waiting and batch (running.count), and self, a queue entry's member index. They are reserved: a set, choose or let cannot assign one, and a def, a parameter, a queue entry's local, an observe, a stage, a pool, a device, an engine, a queue, a gauge, a claim or a schedule's let cannot take one as its name.

Moments

Moment Where an expression is evaluated Evaluated
Session a statement of init, turn, session, server; a run's work; a hold's cache by the session, when it gets there
Admit a hold's units, reserve, reuse for one session at admission
Select a pool's queue by keys for every waiting hold before each selection
Evict an eviction key; a spill clause for one cache entry
Ps a ps stage's capacity for the stage's jobs
Budget an engine's tokens cap and each at most before the iteration, from the running requests
Step an engine's worker after the iteration is scheduled
Serve an engine's by keys and only predicates for one running request
Victim a pool's preempt by keys for one candidate victim, when a growth does not fit
Plan an engine's scheduler: an if guard, an admit waiting's while, a register assignment as the iteration is planned, from the running requests and what it has done so far
Gauge a gauge expression after each instant settles, held until the next event
Given a claim's given for each session, once its init has run
Iteration a claim over iterations when an iteration starts, where the cost is read
End a claim at end once, when the run ends
Request an engine's taking, reuse and prefix; its connector's load for one request, when the scheduler admits it
Release an engine's cache; its connector's save for one request, when it gives its pools back

Variables

Name Type Moments Meaning
now number except Gauge, Given, only predicates and iteration guards simulation clock
waited number Select seconds since this hold entered the queue; reset on re-entry
size number Evict units of the entry
age number Evict now − last
last number Evict time the entry was released
waiting 0 / 1 Evict 1 if the entry's session waits in a pool queue
present number Ps jobs present
residents number Budget, Step, Serve, Plan, Iteration residents, scheduled or not
decoders number Budget, Step, Serve, Plan, Iteration decode residents
kv_decode number Budget, Step, Serve, Plan, Iteration memory held in the stage's memory pool by the decode residents (0 without memory)
kv_prefill number Budget, Step, Serve, Plan, Iteration the same, by the prefill residents
tokens number Step, Plan, Iteration tokens scheduled this iteration (in a body, so far)
admitted number Plan sessions the iteration has admitted so far
preempted number Plan the residents the iteration has preempted so far
prefilled number Step, Plan, Iteration prefill tokens scheduled (in a body, so far)
attention number Step, Iteration attention work of the prefill chunks, Σ n (K + n/2), K the position before a chunk (exact for growing runs)
decoding 0 / 1 Serve, Victim 1 if the resident (or candidate) is decoding, 0 otherwise
admission number Serve, Victim the resident's admission sequence number (its place in vLLM's running list); at Victim, the candidate's place in the candidates' admission order
remaining number Serve tokens the resident's run has left
position number Victim the position the candidate's hold has computed on the pool: what computed becomes if it is the victim
demand number Iteration tokens the residents could take this iteration with no budget: min(1, remaining) per decode, the remaining work up to the chunk per prefill, over the residents after the batch is scheduled (those an only leaves out included)
served number Iteration tokens the stage scheduled in its earlier iterations, from the start of the run
arrived number Iteration sessions the workload has started by the iteration's start, one arriving at that instant included
request.input, request.output number Request, Release the call's arguments, E (input, output);
request.known number Request, Release the tokens the request has: its input and what it has generated
request.hit number Request min(cachedin(P), reuse) on the engine's memory P
request.loaded number Request (in taking) what the engine's connector's load read for this admission
request.preempted 0 / 1 Request 1 once the request has been preempted (vLLM's RequestStatus.PREEMPTED)
request.finished 0 / 1 Release 1 at the release that ends the request, 0 at a preemption

At Budget, totals describe residents before the iteration. At Serve they describe the residents present when the expression is read, including new admissions and excluding preempted residents. At Step and Iteration, decoders, kv_decode and kv_prefill count scheduled residents, while residents counts all residents.

waiting (a context variable at Evict, 0 or 1 for one entry) is not queued(p) (function), the length of a pool's queue.

Reading hidden attributes

hidden attributes are legal at Session and in a claim's Given condition. Scheduler expressions cannot read them.

Examples

A complete program, a deployment and its workload:

model.sq
fn main() {
  device gpu { }
  engine llm on gpu {
    tokens cap 8;
    scheduler { advance running by (remaining); admit waiting while (running.preempted == 0); }
    worker {
      forward (1 + 0.1 * batch.tokens);
    }
  }
  server {
    llm (8, 1);
    observe finished = now;
  }
}
workload.sq
workload {
  arrive batch(2);
}

Save the deployment as model.sq and its workload as workload.sq, then run:

serq run model.sq --workload workload.sq --horizon 10

See also

Functions, attributes, hidden attributes.