Memory tuning
Control how much RAM and VRAM StrataFlow uses with RAM modes, target ceilings, expert caches and slots.
By default StrataFlow plans memory for you and leaves room for other apps. These options let you change that.
The options
| Option | Effect |
|---|---|
--ram-mode auto | Default. A conservative share of RAM that leaves headroom for other apps. |
--ram-mode max | Dedicate the machine: use all RAM and the VRAM placement budget, keep the full KV window, the largest expert cache and the whole trunk resident. Fastest, leaves no headroom. |
--max-performance | Same as --ram-mode max. |
--target-ram-gb X | Fit the projected peak under X GiB using every lever (KV window, expert cache, trunk streaming, VRAM placement). If it can't, it refuses and names the smallest achievable size. Overrides --ram-mode. |
--cache-gb X | Cap the RAM used for resident experts at X GiB. Only lowers the automatic choice. |
--expert-slots N | Hold exactly N expert bundles. Fewer than the model's expert count forces bounded streaming. |
--ram-gb X, --vram-gb X | RAM and VRAM budgets in GiB (0 = automatic). |
--async-prefetch on|off | Overlap expert reads with compute (default on). Output is identical either way. |
Precedence
When options overlap, the most specific one wins:
- Manual levers:
--expert-slots,--cache-gb, and theSTRATAFLOW_ENGINE_KV_WINDOWenvironment variable --target-ram-gb--ram-mode max--ram-mode auto(default)
Among the expert levers: --expert-slots > --cache-gb > automatic from free RAM.
How the automatic expert cache is sized
StrataFlow measures free RAM and reads the model's expert layout (layers, experts per layer, experts used per token, bytes per expert). It then keeps as many expert bundles as fit:
- If RAM holds the whole working set, it caches all of it and never re-streams.
- If not, it bounds the cache, but never below one layer's top-k experts.
No model-specific constants are involved, so it adapts to any MoE shape.
The KV window
STRATAFLOW_ENGINE_KV_WINDOW bounds the KV cache to a number of columns. The KV store grows on demand up to that window instead of allocating the full context up front. For example, on Mixtral a 512-column window cuts the resident KV from 8 GiB to 128 MiB, with byte-identical output for short generations.
STRATAFLOW_ENGINE_KV_WINDOW=512 ./bin/strataflow --model mixtral.strata --prompt "The city of"Recipes
# A laptop you're also using for other work: the defaults
./bin/strataflow --model m.strata --prompt "..."
# A machine dedicated to inference
./bin/strataflow --model m.strata --max-performance --prompt "..."
# A hard ceiling, for example in a container with an 8 GiB limit
./bin/strataflow --model m.strata --target-ram-gb 8 --prompt "..."
# Stress-test streaming with very few experts resident
./bin/strataflow --model m.strata --expert-slots 4 --prompt "..."What memory buys you
More memory means fewer disk reads per token, so it's faster. It doesn't change the output: decoding with few expert slots produces the same tokens as decoding with the whole model in memory. When RAM is tight, a fast NVMe SSD helps most.