Skip to content

Stream MoE experts (experimental)

Off unless you set the flags. Built and tested for identical output. Speed and memory are measured on one machine, one model and one prompt (see Measured): no claim beyond that.

  • --gravity-stream needs --moe-cache-mib N, upstream's GPU cache for MoE experts kept on the CPU. On a cache miss, the expert bytes are read from the model file through a pool of read threads (--gravity-stream-threads) instead of copied from host memory. The bytes are the same, so output is bit-identical to the cache without streaming. The file must be the one that was loaded (device, inode, size, mtime). If it changed or a read fails, those experts come from host memory and the log says how many. Tested on Metal; the cache it builds on is upstream's, which also runs on CUDA. Known gap: warmup and prompt processing still read experts through the mmap.
  • LoRA on cached or streamed experts. Expert LoRA tensors are copied to the cache device once, not every token. That copy is not counted in --moe-cache-mib, and an INFO line at load prints its size. Server test: answers with an adapter on are bit-identical with --gravity-stream on and off.
  • --gravity-residency-mib N (prototype) drops cold expert pages of the mmap after each decode, to keep resident expert bytes under N MiB. It works in two cases. In the first, experts stay in host memory and are computed there (-ngl 0). In the second, you use -cmoe, --moe-cache-mib and --gravity-stream, and every expert is a host expert the stream covers; there only decodes that read the mmap (large prompt batches) drop pages. In any other setup it turns itself off with a warning: a GPU buffer wraps the experts (full Metal offload pins the pages), some experts are not streamed, or the OS has no way to drop pages. Not for production use.
  • gravity repack IN OUT [--dry-run] rewrites a MoE GGUF with 4096-byte alignment and a per-expert offset index (gravity.expert_index.* keys). Tensors keep name, type, shape, bytes and order, so stock llama.cpp still loads the file. Run it last: quantize or split first, then repack. The layout idea comes from Strata (MIT). Built from source, run build/bin/llama-gravity-repack in place of gravity repack.
  • general.alignment is honoured. The GGUF writer, gguf-split and llama-quantize keep a file's general.alignment.