Skip to content

About

Pure-Rust LLM inference engine for GGUF (Qwen, DeepSeek, GLM, Hy4, Flint). Runs models bigger than your VRAM on CUDA and Vulkan, with MTP drafts and an OpenAI/Anthropic server. 12 GB RTX 3060 vs llama.cpp: Qwen3.6-35B-A3B UD-Q5_K_M 80.5 vs 64.4 tok/s, Flint UD-Q5_K_XL 64.6 vs 48.6. With MTP: 108 tok/s (UD-Q3_K_M), up to 160 (UD-Q2_K_XL).

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

RustingStrata

Reviewed by Aletheore

A pure-Rust inference engine for GGUF models, built for MoE models that do not fit in VRAM. The CUDA kernels are compiled at run time with NVRTC, and the same kernels run on Vulkan: no C++ build step, no ggml. Experts that do not fit in VRAM run on the CPU at the same time as the GPU work, and the expert placement adapts to the routing it sees.

Supported models: Qwen3, Qwen3-Next, Qwen3.5/3.6, Qwen3.8-Flash-Next, Qwen4-35B-A3B, Recursive Flint, Gemma 4, DeepSeek-V4.1-Flash, GLM-5.3-Flash, Hy4-flash, Inkling 2 Mini, Kolibri 1.1, GigaChat 4 and Ternary Bonsai 2. The architectures, the GGUF types and the notes for each model are in docs/MODELS.md.

Version 1.5.1.

Numbers

Qwen3.6-35B-A3B on an RTX 3060 12 GB (Ryzen 5 7600X, 32 GB RAM), CUDA, greedy, against llama.cpp tuned for the same file. Neither file fits in VRAM.

RustingStrata llama.cpp
UD-Q5_K_M (25.2 GiB), decode after a 4K prompt 80.5 tok/s 64.4
UD-Q5_K_M, prefill of a 4K prompt 1530 tok/s 1118-1122
UD-Q2_K_XL (11.7 GiB), decode after a 4K prompt 113.4 tok/s 66.5
UD-Q2_K_XL, prefill of a 4K prompt 2216 tok/s ~2236

Many users at once

serve --parallel N decodes the requests together in one batched forward (CUDA). Same machine, same load script (tools/loadtest.py: N streamed chats at once, 128 reply tokens each, greedy), total decode tok/s:

Clients Qwen3-4B, RustingStrata (Q4_K_M) Qwen3-4B, vLLM 0.33 (bf16) Qwen3.6-35B-A3B UD-Q5_K_M, RustingStrata
1 91.3 36.7 49.0
4 228.1 139.9 88.9
16 799.0 520.1 100.7
64 1698 1688-1765 129.3

vLLM runs bf16 weights and RustingStrata Q4_K_M, so the dense columns are not like for like. The 27 GB MoE file does not fit on the 12 GB card, so vLLM was not run on it. RustingStrata reads each expert once for all requests of a step, runs the experts that are not in VRAM on the CPU, and keeps slot state that does not fit in VRAM in RAM. The MoE column moves by about 30% between runs on this machine (the 27 GB file is read through a 30 GB page cache).

The method, the ranges, Vulkan, the other models and the quality checks are in docs/BENCHMARKS.md.

Qwen4-35B-A3B on a 12 GB RTX 3060 (this branch)

This branch (rtx3060-12gb-qwen4-35b) is upstream main plus the patches needed to run unsloth/Qwen4-35B-A3B-GGUF UD-Q4_K_XL as a persistent, long-context agent on one 12 GB card. The model is 24.7 GB of weights plus an 11.5 GB per-layer embedding (PLE) table, so neither the experts nor the PLE table fit in VRAM, and the whole thing does not fit in the page cache either.

Measured on:

  • RTX 3060 12 GB (360 GB/s), CUDA, 60-65 °C, 124-149 W while decoding
  • Ryzen 5 5600 (6C/12T), 32 GB RAM, SATA SSD (~11k 4 KiB random IOPS)
  • serve --gpu --ctx 262144 --kv q8 --vram-margin 128 --chunk 1024 --mtp 1, greedy
Result
Decode, warm, 4K context, f16 KV 77-83 tok/s (92-93% expert hit rate)
Decode, warm, 256K context, q8 KV 72-73 tok/s (82-83% expert hit rate)
Prefill, 4K prompt 390-440 tok/s
Prefill, 132K-token prompt 374 tok/s (about 6 minutes cold; prefix caching makes later turns cheap)
Long-context retrieval passed: correct code recovered from a 132,782-token prompt
Resident experts, 256K/q8 2635 of 10496, 5254 MB of expert slots

Context is paid for in expert slots (the KV cache is 20 MB per 1024 tokens at f16 and 10.6 MB at q8, the sparse indexer pool is 1.4 MB per 1024, and each resident expert is about 2 MB):

Context KV Resident experts Hit rate Decode
4K f16 4333 93.7% 67-70
64K f16 3625 89.2% 71
128K f16 2870 85.4% 72
256K f16 1381 59-61% 52
256K q8 2635 82-83% 72-73
512K q8 1025 ~50% 48-51
1M q4 514 ~35% 42

f16 runs out of VRAM at 512K and q8 at 1M; the model itself is trained to 1,048,576 tokens. 256K with q8 KV is the practical ceiling on this card: it keeps decode near the 4K number, while 512K and 1M lose so many expert slots that every token starts paying for PCIe transfers. Background RAM users (a torrent client, a media server, Docker) reduce the hit rate, because the experts live in the page cache.

What the branch changes:

  • qwen4 pre-tokenizer (tokenizer.rs): map it to the Qwen3.5 regexes, as llama.cpp does.
  • MTP on Qwen4 (weights.rs): the fused hc_attn_down_inject / hc_ffn_down_inject tensors are split into their low-rank and inject halves for the MTP block too (0..n_layer + n_nextn). Without this the draft head does not load.
  • PLE table off the page cache (weights.rs, model.rs, gpu_model.rs): rows are read with O_DIRECT on any file system when the model does not fit in RAM (previously ZFS only), 16 scattered rows per token are issued in parallel, a small in-process row cache skips repeats, and a prefetch thread warms the rows the MTP drafter will verify while the GPU runs the draft head. This is worth about 20% decode on a SATA drive, and it keeps the 11.5 GB table from evicting the experts.
  • Page-cache trim at load (gguf.rs, gpu_model.rs): posix_fadvise(DONTNEED) on every tensor that is not a routed expert, freeing ~13.6 GB (dense weights, PLE, output heads) so the ~21 GB of experts own the cache. Warm decode reads about 0.4 MB per token from the drive at a ~92% hit rate.

Install

Windows (PowerShell; installs to %LOCALAPPDATA%\Programs\RustingStrata, adds it to PATH and makes a Start menu entry that opens the chat page):

irm https://raw.githubusercontent.com/RustingStudio/RustingStrata/main/install.ps1 | iex

Linux x86_64 (installs to ~/.local/bin):

curl -fsSL https://raw.githubusercontent.com/RustingStudio/RustingStrata/main/install.sh | sh

Arch Linux: yay -S rustingstrata-bin (AUR). Or download a binary from the releases page, or build it (Rust 2024 edition; on Windows install the Visual Studio C++ Build Tools first):

cargo build --release    # the binary is target/release/rustingstrata

Then rustingstrata serve --gpu --open opens the chat page, which downloads models, and rustingstrata interface asks a few questions in the terminal. rustingstrata update replaces the binary with the newest release (--check only says whether one is out); serve prints a line at start when a newer release is out. A binary installed by a package manager (the AUR package) is updated with that package manager.

To uninstall, delete the binary and the data folders. The models folder can be large; keep it if other tools use the files.

  • Linux: rm ~/.local/bin/rustingstrata (AUR: yay -R rustingstrata-bin), then rm -r ~/.cache/rusting_strata (kernels, calibration, expert profiles) and ~/.local/share/rusting_strata (downloaded models, usage stats).
  • Windows (PowerShell): delete %LOCALAPPDATA%\Programs\RustingStrata, %LOCALAPPDATA%\rusting_strata and the Start menu entry, then remove the first folder from the user PATH:
Remove-Item -Recurse "$env:LOCALAPPDATA\Programs\RustingStrata", "$env:LOCALAPPDATA\rusting_strata"
Remove-Item "$([Environment]::GetFolderPath('Programs'))\RustingStrata.lnk"
$d = "$env:LOCALAPPDATA\Programs\RustingStrata"
[Environment]::SetEnvironmentVariable('Path', ((([Environment]::GetEnvironmentVariable('Path','User')) -split ';') -ne $d) -join ';', 'User')

XDG_CACHE_HOME/XDG_DATA_HOME or --models-dir move these folders; delete them where you pointed them. Models that the chat page found in the Hugging Face or llama.cpp cache stay there.

A GPU run needs one of:

  • an NVIDIA driver with the CUDA NVRTC library (loaded at run time). Volta (sm_70), Turing (sm_75) and Ampere or newer (sm_80+) work; CUDA 13 dropped Volta, so a V100 needs the 12.x toolkit. Pascal and older use Vulkan. The library is found by name (libnvrtc.so; on Windows nvrtc64_130_0.dll or nvrtc64_120_0.dll, on PATH or under %CUDA_PATH%\bin); STRATA_NVRTC names another file. Without it the run falls back to Vulkan.
  • a Vulkan 1.3 driver with shaderFloat64, int8/16/64 and subgroup size 32 or a fixed 64 (tested on RTX 3060, Radeon VII and V100; a user runs Inkling 2 Mini on an Intel Arc B580; a driver without one of these features is refused at start with the list of what it lacks).
  • for --backend hip: a ROCm runtime with hiprtc (libamdhip64.so, libhiprtc.so), also loaded at run time; the kernels are compiled for the card's gfx target on first use. Experimental — status, numbers and limits are in docs/HIP.md.

--gpu picks CUDA when it loads, else Vulkan; --backend chooses (cuda, vulkan or hip). The first CUDA run compiles the kernels (~15 s) and caches them. Every GPU tried so far is in docs/SUPPORTED_GPUS.md.

Quick start

Run rustingstrata with no arguments (double-click rustingstrata.exe on Windows). It starts a server on http://127.0.0.1:8080 and opens a chat page that downloads models from Hugging Face and switches between the ones in your models folder. Any app that takes an OpenAI-compatible address (Open WebUI, Jan, SillyTavern, code editors) can use http://127.0.0.1:8080/v1.

rustingstrata interface asks for the model, the mode (terminal chat, chat page, API server, speed test), GPU or CPU, which GPUs (every NVIDIA card by default), the context length and the address, prints the command these make and runs it.

With flags:

M=path/to/model.gguf

rustingstrata calibrate --model $M --dry-run  # preview the workload matrix and knob space
rustingstrata calibrate --model $M     # once per model and machine: best chunk, MTP drafts, short threshold
rustingstrata chat --model $M --gpu    # --think for thinking mode, --temp 0.7 to sample
rustingstrata generate --model $M --gpu --prompt "Write a haiku about rivers." -n 128
rustingstrata serve --model $M --gpu --addr 127.0.0.1:8080
# Optional inline terminal metrics and responsive Braille graphs:
rustingstrata serve --model $M --gpu --pretty --graph --status-interval 250ms
rustingstrata bench --model $M --gpu --pp 512,4096 --tg 128

Without --gpu the model runs on the CPU reference, which is slow and meant for checking; --fast-cpu runs the CPU with integer kernels instead, the mode for a machine without a usable GPU (see USAGE.md). DeepSeek, GLM, Hy4 and Inkling 2 open the GPU by themselves.

Docs

  • USAGE.md: flags, the chat page and MCP tools, the OpenAI and Anthropic APIs, prompt caching, several GPUs.
  • CALIBRATION.md: the budgeted search, task corpora, the spec sweep and the JSON file.
  • MODELS.md: supported architectures and GGUF types, notes and caveats for each model.
  • BENCHMARKS.md: every model against llama.cpp; older runs are in the benchmark history.
  • HOSTING.md: running a server for other people.
  • SUPPORTED_GPUS.md and AMD.md: the GPUs tried so far and AMD notes.
  • VISION.md: image input. LORA.md: LoRA adapters.
  • ROADMAP.md: what is planned next, by section; ideas from users are welcome.

Development

cargo test --release                      # GPU tests need the model: STRATA_MODEL=path/to/model.gguf
python -I tools/parity.py $M --extra "--gpu" --tag gpu   # agreement with llama.cpp (needs llama-server once)

CI only builds, so run the tests before a pull request.

Source map: src/gguf.rs (file reader), src/quant/ (dequantization), src/model.rs (CPU reference forward), src/cuda/ and src/vulkan/ (GPU kernels, behind src/backend.rs), src/gpu_model.rs (GPU forward), src/expert_cache.rs (expert placement), src/deepseek/, src/glm/, src/hy4/, src/inkling2/ and src/gemma4/ (the models with their own forward), src/serve.rs (HTTP), src/chat.rs (chat templates and tool calls), src/main.rs (CLI).

License

RustingStrata is released under the RustingStrata License 1.0. You may use, modify and distribute it, including for commercial services, as long as you keep the license and credit Vasyl Trefilov as the original author. You may not sell RustingStrata itself.

About

Pure-Rust LLM inference engine for GGUF (Qwen, DeepSeek, GLM, Hy4, Flint). Runs models bigger than your VRAM on CUDA and Vulkan, with MTP drafts and an OpenAI/Anthropic server. 12 GB RTX 3060 vs llama.cpp: Qwen3.6-35B-A3B UD-Q5_K_M 80.5 vs 64.4 tok/s, Flint UD-Q5_K_XL 64.6 vs 48.6. With MTP: 108 tok/s (UD-Q3_K_M), up to 160 (UD-Q2_K_XL).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages