> your AI agent picks dependencies from memory; give it dated facts — try starlog.dev ↗ vet your agent's deps ↗ vibe-coding is fine. vibe-importing isn’t. — try starlog.dev ↗ vibe-importing isn’t fine ↗ your agent has never seen your private packages — try starlog.dev ↗ facts for private packages ↗ a linter for the dependencies your AI agent picks — try starlog.dev ↗ a linter for agent deps ↗

Back to Articles

Running a 2.78-Trillion-Parameter Model on a Laptop: Inside WASTE's NVMe-Streaming Engine

[ View on GitHub ]

Running a 2.78-Trillion-Parameter Model on a Laptop: Inside WASTE's NVMe-Streaming Engine

Hook

The critical cache threshold for trillion-parameter inference is exactly one token's working set—17GB for K3. Cross that line and more RAM makes your model slower, not faster.

Context

Frontier language models have crossed into the trillion-parameter regime, but inference remains locked behind server racks with terabytes of memory. Kimi K3's 2.78 trillion parameters require 982GB just to load the weights at 3 bits per parameter. Even a well-equipped workstation with 128GB of RAM falls 854GB short. The standard playbook—quantize harder, offload to GPU, distribute across a cluster—hits hard walls: K3 was already trained with quantization-aware training on its experts, offloading assumes you have aggregate memory somewhere in the system, and distribution requires network infrastructure.

WASTE (Weight Activation STreaming Engine) takes a different approach: treat NVMe as the primary storage tier and stream only the activated experts for each token. The insight is architectural: Mixture-of-Experts models like K3 are sparse by design, activating only 2 of 256 experts per layer across 92 layers. You don't need all 2.78 trillion parameters resident—you need the 17GB working set for the current token. The engine converts models into a custom container format with 3-bit residual vector quantization, uses aligned preads to eliminate seek overhead, bypasses the kernel page cache entirely, and runs a bounded LRU cache sized to avoid OS paging. The result: genuine frontier-model inference on a MacBook Pro at 0.5 tokens per second, no internet required.

Technical Insight

WASTE's architecture revolves around one core constraint: every expert access must be exactly one pread() call. The model format enforces this at conversion time. Each expert—comprising gate, up, and down projection matrices—is stored as a contiguous 4KiB-aligned block with RVQ codebooks and a CRC32 header. When the router selects expert 42 from layer 17, the engine calculates the file offset, issues a single pread(), validates the header, and dequantizes on the fly. No seeks, no page cache pollution, no kernel buffering.

The container format reflects this: a JSON manifest with architecture metadata, a 'trunk' file containing embeddings and normalization layers at 4/8 bits, and per-layer expert banks. The trunk stays resident in RAM because it's accessed every token. Experts stream from NVMe because they're sparse—most never activate for a given input. Here's what an expert access looks like in the API:

// Expert activation path - one pread(), one dequant, one matmul
void* expert_cache_get(ExpertCache* cache, int layer, int expert_id) {
    uint64_t key = ((uint64_t)layer << 32) | expert_id;
    void* cached = lru_lookup(cache, key);
    if (cached) return cached;
    
    // Cache miss - stream from disk
    off_t offset = expert_offset(layer, expert_id);
    ExpertBlock block;
    pread(cache->fd, &block, sizeof(block), offset);
    validate_crc32(&block);
    
    float* dequantized = rvq_dequantize(&block);
    lru_insert(cache, key, dequantized);
    return dequantized;
}

The RVQ dequantization is where WASTE saves bandwidth without sacrificing quality. Residual vector quantization at 3 bits per weight sounds aggressive, but K3 was trained with QAT specifically on experts. The trick: never materialize the full weight matrix. Instead, build partial dot product lookup tables per codebook and position. When computing an expert's output, each row is three codebook lookups and two additions. This keeps decompression under 20% of decode time while hitting exactly 3.00 bits per weight—no entropy coding overhead, just raw table lookups.

The attention mechanism uses a load-time algebraic trick that cuts KV cache from 11.25GB to 0.21GB at 4K context. Standard MLA (Multi-head Latent Attention) caches key/value projections in latent space. WASTE absorbs the projection: instead of computing q_nope · (W_kb · c) at decode time, it precomputes W_kbᵀ · q_nope once at load and caches only the transformed queries. The math is identical, but the cached state shrinks by 53x. At 1M-token context, this is the difference between 7.2GB and 360GB—the difference between feasible and impossible on consumer hardware.

The read-ahead overlap was the only algorithmic optimization that measured positive. The engine spawns prefetch threads that speculatively load the next token's likely experts while the current token computes. This sounds obvious, but two 'obvious' optimizations failed: demoting low-probability experts (K3's router has no useful tail—the 10th-ranked expert still matters) and expanding the cache beyond one working set (triggers OS paging that inverts performance). WASTE's cache is capped at 7/8 of available RAM and steps down in 17GB increments. On a 64GB machine, the sweet spot is 46-52GB cached. Below that, hit rate is zero. Above that, the kernel starts swapping and your 0.5 tok/s drops to 0.07 tok/s as thrashing begins.

Disk I/O bypasses the page cache using F_NOCACHE on macOS and O_DIRECT on Linux. This sounds like premature optimization until you realize the working set is 982GB and the kernel has no useful heuristic for 'this 4KiB expert block will be accessed exactly once per token, then never again for 1000 tokens.' Letting the OS manage the cache destroys performance because it evicts trunk layers to make room for cold experts. WASTE's explicit LRU keeps hot experts resident and lets cold ones stay on disk.

Gotcha

Performance is hard-bound by NVMe sequential read bandwidth. You're streaming 17GB per token, and consumer NVMe tops out around 7-10GB/s. That's your ceiling: 0.5-0.7 tok/s on ideal hardware with perfect cache hits. Drop to an external USB SSD and you're at 0.07 tok/s—fourteen times slower, and there's no software fix. The physics doesn't care about your read-ahead strategy.

The usable RAM window is brutally narrow. WASTE needs exactly enough memory to cache one token's working set without triggering OS paging. On a 64GB machine, that's 46-52GB. A 32GB laptop pages constantly and becomes unusable. A 128GB workstation can't use the extra capacity—the cache must stay under pressure thresholds or the kernel 'helps' by paging out your carefully curated expert LRU. You either have the right hardware or you're in a degenerate regime. The format is also hardcoded for Kimi K3's architecture: Delta Attention, absorbed MLA projections, RVQ experts trained with QAT. This isn't a general MoE streamer you can point at Mixtral or DBRX. Porting means understanding why K3's specific design enables streaming and rewriting assumptions. The vision tower is a practical trap: encoding 1024 image patches takes 15 seconds, but decoding them through 92 MoE layers costs 731 seconds. You can halve resolution via the patch budget dial, but you're still measuring latency in minutes per image, not seconds. There's no batching, no speculative decoding, no tool integration—just generate() with a token callback. If your use case needs stateful agents that interleave generation with external API calls, you're building that orchestration layer yourself.

Verdict

Use if: Your threat model requires airgapped inference on confidential data, your deployment target is edge devices with no backhaul, or you're doing research on trillion-parameter models without access to server racks. WASTE is the only published path to K3-scale inference on a single consumer machine with 64GB of RAM and 1TB of NVMe. The engineering is exemplary—deterministic, reproducible, brutally honest about failed optimizations. Skip if: You control the hardware budget or have any network connectivity. Rent a server with 1TB of RAM and run llama.cpp or vLLM—you'll get 50x the throughput. If you're building a production API with SLAs, this is a research artifact, not infrastructure. The 0.5 tok/s ceiling and narrow RAM requirements mean WASTE is a last resort for when you're stuck with a laptop and forbidden from touching the network. It works, but only when you have no other choice.