How dlm runs a 70B model on 16 GB.
Resident loading assumes every weight sits in VRAM at once. dlm drops that assumption: it keeps a small window of transformer blocks resident and streams the next window in over PCIe while the GPU computes the current one. Here's the whole machine, from the partition to the math to the serving stack.
Three zones split the VRAM.
VRAM is carved into a zone that never moves, a zone that holds a working window of layers, and a cache that spills to CPU RAM and NVMe. Each zone has a job, and only one of them churns.
Pinned zone
always residentEmbeddings, final norm, and the LM head never move. They stay put so every token starts and ends without a transfer.
Streaming zone
double-buffered A · BA working window of layers lives here. Buffer A computes the current block while buffer B streams the next one in — then they swap. That swap is the whole trick.
Cache zone
spills to CPU RAM · NVMeLayers not in VRAM wait in a tiered CPU-RAM cache backed by the weights on NVMe. They stream in on demand, just ahead of when they're needed.
A window of layers, one copy stream ahead.
At serve time the streaming zone holds N layers. A miss uploads that layer on a dedicated copy stream — so the transfer overlaps compute on the default stream — and evicts the most recently used layer. Layers are read in a cycle, so the least recently used one is exactly the one needed next; evicting the newest keeps most of the window in place across tokens, and only the rest streams. A background worker loads the next layer the pass is missing ahead of compute. What streaming still costs is bandwidth.
The resident window runs the transformer math for this token, layer by layer, threading each layer’s real K/V history. KV for every layer stays resident, so attention always sees the full history.
The prefetch worker DMAs the next layers into VRAM from the pinned staging buffer, evicting the most recently used one to make room. (On the CPU path, --prefetch-depth and --auto-prefetch set how far ahead.)
Each layer travels disk → compute, just in time.
A streamed layer is read from NVMe in one positioned, unbuffered read, held in a tiered host-RAM cache, staged in a page-locked buffer, streamed into VRAM, and executed. The direct read bypasses the OS page cache, which the RAM cache would only duplicate; the hot-layer cache skips the disk read on repeat; the pinned buffer lets the PCIe controller DMA straight to VRAM — so I/O and copies hide under GPU compute.
one unbuffered read per layer or expert
hot layers held in host RAM
page-locked buffer for transfer
next window lands here
current window executes
Stages 01–04 run asynchronously while stage 05 computes. The transfer never blocks the GPU — DMA hides under compute, so the next layer is already resident when it’s needed.
How many layers stay resident.
The profiler decides the resident window size with one formula. Everything after the fixed costs — safety, KV cache, pinned zone — is spent on as many streamed layers as fit.
Clamped to [1, N_layers] — streaming needs at least one resident slot, and never more than the model has.
27 of 80 layers stay resident — 34% in VRAM — and the other 53 stream through the resident window. That’s a 70B model on a 16 GB card at --quant int4; without it, the checkpoint’s own 16-bit weights make each layer 4x heavier.
- M_free16 GB
- Free VRAM reported by the GPU runtime (simulated off-GPU).
- M_safety1.5 GB
- Cushion for activation spikes.
- M_kv_total2.8 GB
- Paged KV cache summed across all layers, for the whole 8,192-token context.
- M_pinned0.9 GB
- Embeddings, final norm, and LM head — always resident.
- M_layer_weight0.4 GB
- One streamed transformer block (largest measured, or estimated).
One trait, three interchangeable kernels.
The transformer math sits behind a block-level ComputeKernel trait — run_block runs one decoder block for one token. A ForwardOrchestrator drives a sequence through the model autoregressively, calling the kernel per layer. Three kernels plug into the same slot.
CpuKernel
oracleThe real math: a Llama-style decode block — RMSNorm, RoPE, grouped-query attention over the KV history, SwiGLU MLP. A complete, if slow, CPU forward path, and the correctness oracle the GPU kernel is checked against.
StubKernel
testingA trivial deterministic kernel that exercises the orchestration — KV growth, per-layer iteration — in isolation, without the cost of real math.
GpuKernel
cuda-kernelsA CUDA run_block on the device, mirroring the CPU oracle op-for-op. KV history stays resident in VRAM, so only the hidden vector crosses PCIe per token — not the whole history. Validated against the CPU kernel.
What sits above the streaming core.
The core streams layers; the stack around it turns that into a server — continuous batching, speculative decoding, multi-GPU pipeline parallelism, and distributed master-worker serving.
OpenAI-compatible server
shippedA dependency-free HTTP server exposing the OpenAI /v1/chat/completions and Anthropic /v1/messages endpoints (both with SSE streaming), plus /v1/models. Real tokenizers, chat templates, per-request sampling, bearer + x-api-key auth. Started by dlm serve.
Continuous batching
shippedA background scheduler keeps up to max_batch generations in flight, advancing each one token per tick and admitting queued requests as slots free. Each request's output is identical to running it alone.
Speculative decoding
shippedA cheap draft model — or, with no draft, n-gram lookup over the request's own context (on by default on the GPU) — proposes gamma tokens; the target verifies them and accepted tokens advance in bulk. With greedy sampling the output is provably identical to plain decoding, with acceptance-rate stats.
Multi-GPU pipeline parallelism
shippeddlm serve --multi-gpu-ids splits the layer stack into contiguous per-GPU stages so only the hidden residual crosses the boundary — a split run is bit-for-bit identical to a single device.
Distributed master-worker
shippedLayers shard across worker nodes; a coordinator streams the hidden state through them as length-prefixed Protobuf over TCP. Heartbeats track liveness, and an unreachable worker falls back to local CPU-RAM.
The GPU you already own is enough.
Clone the repo, run the profiler on your card, and watch a 70B model fit where it shouldn’t. No GPU required to try it.
Apache-2.0 · Rust 1.75+ · Linux · macOS · Windows