Architecture & math
A reference summary of how dlm streams layers. For the illustrated, long-form walkthrough — zone diagrams, the animated A/B schedule, the data path — see How it works.
The three VRAM zones
- Pinned zone — embedding, LM head, and norms stay resident permanently; moving them each step would thrash the PCIe bus.
- Streaming zone — two buffers,
AandB. While A executes on the compute stream, B DMAs the next window of layers in over PCIe, then they swap. - Cache zone — the PagedAttention KV cache plus residual activations, spilling to a tiered CPU-RAM cache backed by the weights on NVMe.
The data path
A streamed layer travels direct read (NVMe) → CPU-RAM cache → pinned staging → streaming-zone buffer → compute. Each layer or expert arrives in one positioned, unbuffered read (O_DIRECT on Linux, FILE_FLAG_NO_BUFFERING on Windows): about 3x the throughput of faulting pages in from a memory map on an NVMe drive, without a second copy in the OS page cache. DLM_MMAP_READS=1 goes back to copying from the map. The hot-layer cache skips the disk read on repeat; and the page-locked host buffer lets the PCIe controller DMA straight to VRAM asynchronously — so disk I/O and copies hide under GPU compute.
The LayersToLoad formula
The profiler decides how many transformer blocks fit resident at once:
M_free— free VRAM from the GPU runtime (simulated off-GPU).M_safety— cushion for activation spikes (by default a tenth of the card’s VRAM, between 256 MiB and 1.5 GiB).M_kv_total— KV cache for the whole context, summed across all layers.M_pinned— the permanent pinned-zone cost (embedding + LM head + norms).M_layer_weight— size of one streamed block.
The result is clamped to [1, N_layers]. Try it live on the Benchmarks page.
The compute kernels
The transformer math sits behind a block-level ComputeKernel trait — run_block runs one decoder block for one token. Three kernels plug into the same slot:
CpuKernel— the real Llama-style decode block (RMSNorm, RoPE, GQA, SwiGLU); the correctness oracle.StubKernel— a trivial deterministic kernel for testing the orchestration in isolation.GpuKernel— a CUDArun_blockmirroring the CPU oracle op-for-op; KV history stays resident in VRAM, so only the hidden vector crosses PCIe per token.
Distributed & scaling
- Continuous batching — a scheduler keeps up to
max_batchgenerations in flight, admitting queued requests as slots free. - Speculative decoding — a draft model, or n-gram lookup over the request’s own context, proposes tokens the target verifies in bulk; with greedy sampling the output is provably identical to plain decoding.
- Multi-GPU pipeline parallelism — 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 — layer shards across nodes, hidden state streamed as length-prefixed Protobuf over TCP, with heartbeats and CPU-RAM fallback for a dead worker.