Layby-Dwell v2
Layby-Dwell predicts how long an LLM session stays idle after a response ends. It reads what a serving engine can see at that moment and returns a calibrated survival curve: the probability that the session's next request has not arrived yet, at 15 horizons from 0.5 s to 30 min.
Code, engine adapters and the ReturnBench benchmark: github.com/avifenesh/layby (v2.1.1), archived on Zenodo as
10.5281/zenodo.23285213.
Paper: layby.pdf (arXiv link to follow). Author: Avi Fenesh.
It exists for one decision: where to keep the session's KV cache while it waits. Keep it on the GPU, move it to CPU memory, write it to disk, or let it go. Layby, the placement rule it was built for, turns the curve and the engine's own measured hardware costs into that choice. There are no workload-fitted decision thresholds.
v2.0 release (
main, tagv2.0):Layby-Dwell v2replaces the 421Mv1model with a standalone 33.8M (135 MB) two-tower model built on jhu-clsp/ettin-encoder-32m (Apache-2.0). It removes thelayadependency, runs on host CPU with 0 MiB GPU VRAM (10.6-19.4 msp50 live on a 64-vCPU server,20.9-29.8 msisolated 8-thread atL=128-512,68.2 msatL=1024,117 mson DGX Spark ARM64,140-380 mson a loaded laptop CPU; or4.07-4.26 mson GPU BF16 using427 MiB), cuts human calibration error by 3.3x, and matches or beatsv1on ReturnBench and held-out splits. Legacyv1(421M,convaiinnovations/laya) remains archived at branchv1/ tagv1.0(Dwell("avifenesh/layby-dwell", revision="v1")).
Architecture (v2_gated)
- Text tower: jhu-clsp/ettin-encoder-32m
(10-layer, 384-dim ModernBERT,
max_len = 1536) over compact delta text (kind,tool,program,model,TOOL_CALL,ASSISTANT,USER) + learnable top-4LayerMix+[CLS]+AttentionPool. - Numeric tower (
PeriodicNumericEncoder): 32 causal server-view numeric features with explicit missing masks, 8 learned Fourier frequencies per feature, and 2 residual SwiGLU blocks (256-dim). - Gated bilinear residual head:
z = z_num + sigmoid(gate) * z_deltaover concatenated[h_txt, h_num, h_num * txt_proj], producing 16 right-censored discrete survival bin logits with per-kind temperature calibration (_all: 1.0261,human: 1.0051,tool: 1.0309). - Size:
33,755,701parameters (14.4Mnon-embedding),135 MBfp32 safetensors, zerolayadependency. One forward pass per state; no text is generated.
Input
A server-view state: a JSON object (or Python dict) built at the moment a response ends. Any
OpenAI-compatible server can fill every field. layby_dwell.Tracker builds it from the request and
response stream.
| field | what it is |
|---|---|
kind | tool if the response asks for tool calls, else human |
model, tool, program, arg_chars | the served model, the first tool call's name, the program of a shell command, argument size |
ctx_tokens, turn, session_age_s, hour, dow | context size, position in the session, clock (UTC) |
recent | the session's last 8 idle periods: kind, tool, seconds |
meta | previous gap and kind, same-kind gap and its EWMA, command size, timeout, background flag |
tool_history, meta.program_history, meta.user_kind_history | this user's earlier gaps for the same tool, program and kind: count, mean, p90, share under 1 s |
tool_call, assistant, user | the tool calls, the current turn's assistant text and the last user message, truncated |
Sessions are linked by a hash of the conversation prefix. A user is whatever key the server has
(API key, tenant, header). History fields are optional: the model was trained with telemetry dropout
(p_id = 0.30, p_history = 0.15) and degrades gracefully on cold-start traffic, though session
history remains valuable for long human waits (see Limits).
Output
P(T > h) for h in [0.5, 1, 2, 3, 5, 8, 12, 20, 30, 45, 60, 120, 300, 600, 1800] seconds, where
T is the time until the session's next request. Probabilities are strictly non-increasing and
calibrated per kind with temperatures stored in config.json.
Use
from layby_dwell import Dwell, Tracker
# v2 (33.8M, zero laya dependency; runs comfortably on CPU with 0 MiB GPU VRAM, or GPU bf16)
dwell = Dwell("avifenesh/layby-dwell", device="cpu")
tracker = Tracker()
# in the serving path, per request and response:
sess = tracker.on_request(body, user)
state, kind = tracker.on_response(sess, body, resp_message, usage, user)
surv = dwell.survival([state], [kind])[0] # 15 values of P(T > h)
To reproduce legacy v1 (421M, requires pip install -e ".[dwell,dwell-v1]"):
dwell_v1 = Dwell("avifenesh/layby-dwell", revision="v1")
Score at the end of each response, off the critical path. Batch the boundaries that end together:
survival sorts states by length and pads each batch only to its longest state (rounded to 16).
With vLLM and SGLang
The Layby adapters run the placement rule inside the engine and take the curve as a hint keyed by request:
- vLLM 0.30, 0.31, 0.34, and nightly (
>=0.34.0rc1):ParkConnector(layby.vllm.connector, anOffloadingConnectorsubclass) withParkCachePolicy(layby.vllm.policy) andParkFsTier(layby.vllm.fs_tier), configured through--kv-transfer-config. - SGLang 0.5.21 and 0.5.23: the
parkplugin (layby.sglang,SGLANG_PLUGINS=park,--radix-cache-backend park --radix-eviction-policy park) on HiCache with a file storage backend.
The Layby sidecar (python -m layby.sidecar.proxy --device cpu) is an OpenAI-compatible proxy that
handles session tracking, CPU scoring (0 MiB GPU VRAM), optional online temperature recalibration
(--online-calib), and hint delivery for either engine.
Training
Trained from jhu-clsp/ettin-encoder-32m
(1b8ba06455dd44f80fc9c1ca9e22806157a57379) on 3,236,086 cleaned, secret-scrubbed server-view
turns for 1 epoch with ScheduleFree AdamW, FP32 master weights under BF16 autocast, max_len = 1536,
inverse-subsampling importance weighting normalized by kind, and server-telemetry dropout
(p_id = 0.30, p_history = 0.15). Target: exact right-censored 16-bin discrete survival negative
log-likelihood (a strictly proper scoring rule). The published weights are Seed 0 of the 3-seed
champion run (rung4_32m_all_corpora).
Data
Only datasets whose licenses allow commercial use, with 0 secret regex hits across 100% of rows and
strict zero-leakage splits (0 unseen-user overlap, 0 cross-split sessions, 0/9,987 ReturnBench
replay_pop turns in training, and future weeks 12-15 of FreeInference held out):
- GitHub Copilot Coding Agent Traces 2026 (CC BY 4.0): agent sessions, timestamps only.
- SWE-chat and SWE-chat v2 (ODC-BY): Claude Code and Codex transcripts.
- WildChat-4.8M (ODC-BY): chat conversations with exact request timestamps.
- TraceLab (CC BY 4.0): coding-agent traces (broken 0 ms clock artifacts removed).
- BurstGPT v2 (
BurstGPT_3.csv, CC BY 4.0): chronological 80% session train split (10% dev / 10% eval OOD held out). - The author's own Claude Code and Codex sessions, and users' data under the terms they agreed to.
Evaluation
Head-to-head vs. archived v1 (421M) on strictly untouched splits
All v2 offline metrics below are 3-seed medians on strictly untouched evaluation splits:
| Metric / Benchmark | Archived v1 (421M) | Layby-Dwell v2 (33.8M) | Improvement |
|---|---|---|---|
| Parameters (total / non-embedding) | 421M / 369M | 33.8M / 14.4M | 12.5x smaller (25.6x non-emb) |
| Checkpoint size (fp32 safetensors) | 1,685 MB | 135 MB | 12.5x smaller |
| Peak serving VRAM (GPU BF16) | 2,616 MiB | 427 MiB (or 0 MiB on CPU) | 6.1x less VRAM |
Official 33-cell ReturnBench (p95 vs no-disk, pub. s0) | 0.659 (worst 1.043) | 0.661 (worst 1.039) | Matches overall, beats v1 on worst cell |
ReturnBench slow disk (0.5 GB/s vs no-disk, pub. s0) | 0.823 | 0.816 | Beats v1 on all 3 seeds (write-through: 0.986) |
Untouched eval_uhold matched human NLL (n=18,096) | 1.5980 | 1.5439 | -0.0541 NLL |
Untouched eval_uhold matched human ECE@300s | 0.0340 | 0.0104 | 3.3x lower calibration error |
Untouched eval_uhold swechat:tool (n=7,260) | 0.7589 | 0.6490 | -0.1099 NLL |
Untouched eval_uhold ask_user / subagent NLL | 2.1127 / 1.8073 | 1.6967 / 1.6127 | -0.4160 / -0.1946 NLL |
Untouched eval_uhold matched tool Spearman rho | 0.774 | 0.790 (published seed 0: 0.798) | +0.016 to +0.024 rank gain |
Untouched BurstGPT v2 eval_ood (n=20,000) | 2.1235 (ece60 0.0405) | 2.0871 (ece60 0.0148) | -0.0364 NLL, 2.7x lower 60s ECE |
AgentX 390-session replay (0.5 GB/s) | 1.012 (wt: 1.158) | 1.004 | Eliminates write-through blow-up |
Architecture & objective ablations (full eval_uhold, n=184,148 + 33 ReturnBench cells)
One-epoch ablations on the 3.24M-row corpus (*Compact 18.5M aux=0 trained on 3.00M rows without swechat_v2_new), all evaluated apples-to-apples on full eval_uhold (n=184,148):
| Model variant | Params | All NLL | Tool NLL | Human NLL | Human ECE@300s | wait_poll NLL | RB p95 (worst) | RB @0.5 |
|---|---|---|---|---|---|---|---|---|
Layby-Dwell v2 (aux=0, 3-seed med.) | 33.8M | 1.5950 | 1.6148 | 1.4374 | 0.0103 | 2.1261 | 0.660 (1.039) | 0.817 |
Layby-Dwell v2 (aux=0, pub. s0) | 33.8M | 1.5862 | 1.6046 | 1.4375 | 0.0116 | 1.8843 | 0.661 (1.039) | 0.816 |
Joint-Prefix (aux=0.10, 3-seed med.) | 33.8M | 1.6068 | 1.6282 | 1.4338 | 0.0115 | 2.2126 | 0.659 (1.039) | 0.815 |
Stronger Aux (aux=0.25) | 33.8M | 1.6027 | 1.6233 | 1.4359 | 0.0115 | 2.0448 | 0.657 (1.039) | 0.817 |
Long-Tail Upweight (2x >60s, aux=0.10) | 33.8M | 1.6006 | 1.6214 | 1.4326 | 0.0128 | 2.3348 | 0.660 (1.073) | 0.806 |
Compact 18.5M (Ettin-17M, aux=0*) | 18.5M | 1.5926 | 1.6121 | 1.4342 | 0.0130 | 2.0797 | 0.663 (1.079) | 0.824 |
Plain MLP + Concat (v1_plain) | 32.1M | 1.6435 | 1.6664 | 1.4577 | 0.0202 | 2.2865 | 0.661 (1.084) | 0.819 |
| Tabular Telemetry Only (no text) | 1.4M | 1.6684 | 1.6906 | 1.4888 | 0.0323 | 1.8861 | 0.667 (1.061) | 0.828 |
| Text Encoder Only (no telemetry) | 32.5M | 2.1852 | 2.2540 | 1.6288 | 0.0514 | 2.6953 | 0.678 (1.324) | 0.873 |
Real-engine serving (CPU sidecar, 0 MiB GPU VRAM)
Running this exact checkpoint (rung4_32m_all_corpora, seed 0) on host CPU across 4 hardware tiers and 5 model families (O_DIRECT / fadvise, 0 hint errors across >8,000 live turns, 0 MiB extra GPU VRAM; multi-repeat averages for layby):
- 4x RTX PRO 6000 Blackwell, vLLM 0.34.0, untouched held-out
GLM-5.3-Flash320B MoE TP=4 (seed=2027, 128K-190K ctx, 398 all turns,12.5 GB/sNVMe):21.51 smean TTFT (56.39 sp95, 2-rep avg; repeats19.52 / 23.49 s), 4.26x faster mean thanno-disk(91.57 s), 1.96x faster thanLMCache 0.5.7.post1 ARC(42.23 s, with 33.0% less disk and 3.5 GiB less VRAM), 1.97x faster thanfreq-gated(42.31 s), and 7.81x faster thanContinuum(167.91 s). - 1x RTX PRO 6000 Blackwell (
96 GB), vLLM 0.34.0:Qwen3-8BBF16 (2.0 GB/s, 351 resumed turns):#1on mean, p95, p99, and max at2.12 smean /9.99 sp95 /15.72 sp99 (3-rep avg:1.91 / 2.02 / 2.44 s) vs3.98 sno-disk(1.88x),3.17 sLMCache ARC(1.50x), and3.04 swrite-through(35.38 sp99 /139.07 smax).Gemma-4-31BFP8 (1.35 GB/s, 443 all turns):#1mean and p95 (3.81 s/17.88 s, 3-rep avg) vs3.85 s / 18.88 swrite-through;Qwen3.8-27BFP8 (1.31 GB/s, 488 all turns): tieswrite-throughon mean (1.83 s, 3-rep avg, p957.67 svs7.39 s);Qwen3.8-27Bslow (141 MB/s):#1mean and p95 (10.53 s/36.70 s, 3-rep avg,0afal);Gemma-4-31Bslow (146 MB/s):#1p95 (77.88 svs82.20 sno-disk, whileLMCachetimed out at190.2 sp95).
- 1x RTX 5090 Laptop (
24 GB), vLLM 0.34.0 (Qwen3-8BBF16,2.0 GB/s, 351 resumed turns): Leads mean and p95 at25.69 smean /97.11 sp95 /117.52 sp99 (2-rep avg:23.75 / 27.62 s) vs39.24 sno-disk(1.53x),35.03 sLMCache ARC(1.36x, best p99109.30 s), and31.03 swrite-through(272.0 sp99 /490.7 smax). - NVIDIA DGX Spark GB10 ARM64 (
121 GiB), vLLM nightly0.34.0rc1(Inkling 2 Mini26.4B looped SWA MoE NVFP4, native8.3 GB/sNVMe): Runs natively on ARM64 CPU (117 msmedian, 0 MiB VRAM). Reaches8.17 smean (2-rep avg:7.77 / 8.56 s; 2.83x faster thanno-disk23.10 s, 2.27x faster thanfreq-gated18.54 s), whileLMCache 0.5.7.post1failed to import on vLLM nightly;write-throughled mean/p50/p95/p99 (6.18 smean) due to2.9xsingle-stride overestimation of Inkling 2's compact hybrid-SWA KV. - Slow-disk neural vs. heuristic ladder (
141 MB/s,Qwen3-8B, 351 resumed turns,0.0 GBwritten by Layby/no-disk): Monotonic mean and p99 latency drop purely via CPU eviction order:no-disk(2.98 smean /17.23 sp99) -> EWMA (2.33 s/15.55 s) -> Kaplan-Meier (2.23 s/14.55 s) -> neurallayby(2-rep avg:2.06 s/13.57 s, repeats2.04 / 2.07 s, 11.6% faster mean and 12.7% faster p99 than EWMA). Stockwrite-throughcollapses to10.53 smean /274.3 sp99 (77.2 GBwritten). - SGLang 0.5.23 + HiCache (
Qwen3-8BBF16, 366 all turns): 3-repeat average beatshicache-selectiveacross every metric at2.0 GB/s(3.44 svs3.60 s), cuts disk writes20.3%(15-26%across 2 repeats) at1.31 GB/s, and auto-suppresses disk writes (0.0 GB, lowest recompute at1.31M) on141 MB/sslow disk whilehicache-write-backOOM-crashes at turn 21.
Full real-hardware tables across all hardware tiers and model families are in the Layby repository README and layby.pdf.
Speed
| device | precision | one state (bs=1) | batch of 8 | VRAM |
|---|---|---|---|---|
CPU x86, 8 threads (L = 128 / 256 / 512 / 1024) | fp32 | 20.9 / 24.3 / 29.8 / 68.2 ms | 0 MiB | |
| CPU x86, live sidecar (64-vCPU server, mixed lengths) | fp32 | 10.6 to 19.4 ms p50 | 0 MiB | |
| CPU x86, live sidecar (loaded laptop CPU) | fp32 | 140 to 380 ms p50 | 0 MiB | |
| CPU ARM64, live sidecar (DGX Spark GB10) | fp32 | 117 ms p50 | 0 MiB | |
RTX 5090 (L = 256 / 1536, PyTorch sdpa) | bf16 | 4.07 / 4.26 ms | 1,960 / 488 st/s (L=256/1024) | 427 MiB |
Unlike v1 (1.7-2.9 s on CPU, GPU-required), v2 is fast enough to run directly on CPU inside the
inference router or sidecar process with zero GPU contention. On GPU, serve in bf16 (the default).
Weight-only 8-bit options (precision="int8w", "fp8w") remain available via torchao; see
model/QUANT.md for the v1 quantization study.
Limits
- Session history matters for long human waits. Without session linking (stateless scoring),
long-horizon human recall degrades sharply. Run
Trackerso prior session gaps are populated. - Temporal harness drift on tool latencies. On the single slice where archived
v1edgedv2(freeinference:toolfuture weeks 12-15:1.6336vs1.6828,+0.0492NLL driven bywait_polllatency shift),v2still ranked tools better (rho = 0.790-0.798vs0.774) and beatv1onfreeinference:human(-0.0690NLL). For deployments with shifting agent harnesses,layby/sidecar/proxy.pyimplements optional rolling per-kind temperature recalibration (--online-calib) for/v1/chat/completionsproxy traffic (not yet evaluated under live proxy replay). - English-centric text fields: non-English corpora were not specifically benchmarked.
- Forecast, not a guarantee: use the survival curve inside a cost-aware rule that prices wrong calls, as Layby does, rather than as a hard eviction timeout.
- Data handling: scoring reads prompt and response text locally; it stores nothing, but treat it like any other component on the inference host.
License
Apache-2.0, matching the base jhu-clsp/ettin-encoder-32m weights.
Citation
@misc{fenesh2026layby,
title = {Layby: Placing Idle KV Cache by Predicted Return Time and Measured Cost},
author = {Avi Fenesh},
year = {2026},
note = {arXiv id to follow}
}