[PR #5344] [Engine] add fractional total-VRAM ceiling (--vram-frac) and setup scaling #5393

Open
opened 2026-11-07 16:34:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5344
Author: @atomicmilkshake
Created: 11/5/2026
Status: 🔄 Open

Base: main ← Head: vram-fractional-cap


📝 Commits (2)

  • 2bcf0c0 engine: introduce total-VRAM fractional ceiling (--vram-frac) and quality mode
  • 4d22dd9 setup: account for fractional VRAM in hardware check and model sizing (--vram-cap)

📊 Changes

27 files changed (+1640 additions, -113 deletions)

View changed files

📝 CMakeLists.txt (+10 -1)
📝 include/strata/core/expert_source.hpp (+2 -0)
📝 include/strata/core/geometry.hpp (+1 -0)
📝 include/strata/core/peer_experts.hpp (+1 -1)
📝 include/strata/core/remote_experts.hpp (+2 -1)
📝 include/strata/core/verify.hpp (+8 -1)
➕ include/strata/core/vram_floor.hpp (+21 -0)
📝 include/strata/kernels/cpu/expert_layout.hpp (+3 -1)
📝 include/strata/prefill/prefill.hpp (+5 -0)
➕ include/strata/program/vram_cap.hpp (+110 -0)
📝 setup.py (+161 -44)
📝 src/core/expert_source.cpp (+33 -10)
📝 src/core/mtp.cpp (+27 -0)
📝 src/core/peer_experts.cpp (+8 -3)
📝 src/core/remote_experts.cpp (+16 -5)
📝 src/core/verify.cpp (+64 -6)
➕ src/core/vram_floor.cpp (+89 -0)
📝 src/kernels/cpu/expert_layout.cpp (+10 -2)
📝 src/kernels/cuda/native_router.cu (+4 -1)
📝 src/prefill/kernels.cu (+12 -0)

...and 7 more files

📄 Description

Problem and result

On consumer GPUs (e.g. 8 GB - 16 GB VRAM) running alongside desktop compositors, browsers, or concurrent background tasks, allocating up to 100% of physical VRAM frequently triggers desktop stutter, Windows display driver timeouts (TDRs), or out-of-memory errors during allocation spikes. Previously, Strata only offered --vram-reserve-mib as a static megabyte subtraction.

This change introduces an optional fractional ceiling on total VRAM (--vram-frac <F>, 0.0 < F <= 1.0, or STRATA_VRAM_FRAC=F). When active, Strata dynamically sizes internal reserves and expert/KV cache allocations so total memory strictly adheres to the requested fraction (e.g., --vram-frac 0.8 on a 10 GB card enforces an 8,192 MiB ceiling). setup.py also accepts --vram-cap <F>, correctly reflecting usable memory in hardware checks and model sizing.

none

Approach

  1. CLI & Environment: Added --vram-frac <F> CLI argument in generate.cpp and STRATA_VRAM_FRAC environment parsing.
  2. Cap Calculation & Floor: Implemented vram_cap.hpp and vram_floor.cpp to calculate dynamic reserves and assert memory floors during expert and prompt allocations. Added --vram-cap-mode fast|quality for miss routing.
  3. Setup Integration: Added --vram-cap <F> in setup.py. Sizing calculations in low_ram_vram(), gpu_table(), and amd_mem_text() scale usable VRAM by the cap factor.
  4. Backward Compatibility: Fully opt-in. Default behavior (--vram-frac 1.0 or omitted) remains identical to upstream.

Validation

Passed:

  • python tools/test_setup_vram_cap.py
    • Revision: vram-fractional-cap (commit 4d22dd99 on top of 9f7d977d)
    • Environment: Windows 11, Python 3.14, AMD Ryzen 7 5800X3D
    • Result: 16/16 tests passed in 1.932s.
  • python tests/core/vram_cap_cli_test.py --exe J:/strata/Strata/build/strata.exe
    • Revision: vram-fractional-cap (commit 4d22dd99)
    • Environment: Windows 11, MSVC 18.11, CUDA 13.2, RTX 3080 10GB (sm_86)
    • Result: 6/6 tests passed (1 skipped by design for multi-GPU).
  • python setup.py --check --vram-cap 0.8
    • Result: Correctly reported [ok] GPU: NVIDIA GeForce RTX 3080, 10.0 GB VRAM (8.0 GB usable with --vram-cap 0.8) and sized Qwen3.8 / DeepSeek variants against 8.0 GB VRAM.
  • strata.exe --pack <pack> --tokens "1,2,3" --vram-frac 0.8
    • Result: CUDA telemetry confirmed 8,192 MiB cap floor and verified 0.8 VRAM ceiling with Ampere sm_86 speed switches active.

Failed:
none observed

Not run:

  • ROCm / HIP and Apple Silicon Metal builds were not run locally (Windows 11 / CUDA sm_86 testbed only).

Limits

  • --vram-cap-mode quality is targeted at single-GPU native configurations; multi-GPU splits fall back to fast mode.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5344 **Author:** [@atomicmilkshake](https://github.com/atomicmilkshake) **Created:** 11/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `vram-fractional-cap` --- ### 📝 Commits (2) - [`2bcf0c0`](https://github.com/Niko1221/Strata/commit/2bcf0c07e8bd34b03f5a7ba72bfec7e7c2467e3b) engine: introduce total-VRAM fractional ceiling (--vram-frac) and quality mode - [`4d22dd9`](https://github.com/Niko1221/Strata/commit/4d22dd99b4be55da310abeba50f6be36286983e1) setup: account for fractional VRAM in hardware check and model sizing (--vram-cap) ### 📊 Changes **27 files changed** (+1640 additions, -113 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+10 -1) 📝 `include/strata/core/expert_source.hpp` (+2 -0) 📝 `include/strata/core/geometry.hpp` (+1 -0) 📝 `include/strata/core/peer_experts.hpp` (+1 -1) 📝 `include/strata/core/remote_experts.hpp` (+2 -1) 📝 `include/strata/core/verify.hpp` (+8 -1) ➕ `include/strata/core/vram_floor.hpp` (+21 -0) 📝 `include/strata/kernels/cpu/expert_layout.hpp` (+3 -1) 📝 `include/strata/prefill/prefill.hpp` (+5 -0) ➕ `include/strata/program/vram_cap.hpp` (+110 -0) 📝 `setup.py` (+161 -44) 📝 `src/core/expert_source.cpp` (+33 -10) 📝 `src/core/mtp.cpp` (+27 -0) 📝 `src/core/peer_experts.cpp` (+8 -3) 📝 `src/core/remote_experts.cpp` (+16 -5) 📝 `src/core/verify.cpp` (+64 -6) ➕ `src/core/vram_floor.cpp` (+89 -0) 📝 `src/kernels/cpu/expert_layout.cpp` (+10 -2) 📝 `src/kernels/cuda/native_router.cu` (+4 -1) 📝 `src/prefill/kernels.cu` (+12 -0) _...and 7 more files_ </details> ### 📄 Description ## Problem and result On consumer GPUs (e.g. 8 GB - 16 GB VRAM) running alongside desktop compositors, browsers, or concurrent background tasks, allocating up to 100% of physical VRAM frequently triggers desktop stutter, Windows display driver timeouts (TDRs), or out-of-memory errors during allocation spikes. Previously, Strata only offered `--vram-reserve-mib` as a static megabyte subtraction. This change introduces an optional fractional ceiling on total VRAM (`--vram-frac <F>`, `0.0 < F <= 1.0`, or `STRATA_VRAM_FRAC=F`). When active, Strata dynamically sizes internal reserves and expert/KV cache allocations so total memory strictly adheres to the requested fraction (e.g., `--vram-frac 0.8` on a 10 GB card enforces an 8,192 MiB ceiling). `setup.py` also accepts `--vram-cap <F>`, correctly reflecting usable memory in hardware checks and model sizing. ## Related discussion none ## Approach 1. **CLI & Environment**: Added `--vram-frac <F>` CLI argument in `generate.cpp` and `STRATA_VRAM_FRAC` environment parsing. 2. **Cap Calculation & Floor**: Implemented `vram_cap.hpp` and `vram_floor.cpp` to calculate dynamic reserves and assert memory floors during expert and prompt allocations. Added `--vram-cap-mode fast|quality` for miss routing. 3. **Setup Integration**: Added `--vram-cap <F>` in `setup.py`. Sizing calculations in `low_ram_vram()`, `gpu_table()`, and `amd_mem_text()` scale usable VRAM by the cap factor. 4. **Backward Compatibility**: Fully opt-in. Default behavior (`--vram-frac 1.0` or omitted) remains identical to upstream. ## Validation **Passed:** - `python tools/test_setup_vram_cap.py` - Revision: `vram-fractional-cap` (commit `4d22dd99` on top of `9f7d977d`) - Environment: Windows 11, Python 3.14, AMD Ryzen 7 5800X3D - Result: 16/16 tests passed in 1.932s. - `python tests/core/vram_cap_cli_test.py --exe J:/strata/Strata/build/strata.exe` - Revision: `vram-fractional-cap` (commit `4d22dd99`) - Environment: Windows 11, MSVC 18.11, CUDA 13.2, RTX 3080 10GB (`sm_86`) - Result: 6/6 tests passed (1 skipped by design for multi-GPU). - `python setup.py --check --vram-cap 0.8` - Result: Correctly reported `[ok] GPU: NVIDIA GeForce RTX 3080, 10.0 GB VRAM (8.0 GB usable with --vram-cap 0.8)` and sized Qwen3.8 / DeepSeek variants against 8.0 GB VRAM. - `strata.exe --pack <pack> --tokens "1,2,3" --vram-frac 0.8` - Result: CUDA telemetry confirmed 8,192 MiB cap floor and verified 0.8 VRAM ceiling with Ampere `sm_86` speed switches active. **Failed:** none observed **Not run:** - ROCm / HIP and Apple Silicon Metal builds were not run locally (Windows 11 / CUDA `sm_86` testbed only). ## Limits - `--vram-cap-mode quality` is targeted at single-GPU native configurations; multi-GPU splits fall back to fast mode. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5393
No description provided.