mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4094
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2522
Author: @GonzMartinez
Created: 10/15/2026
Status: 🔄 Open
Base:
main← Head:feature/vram-split-reserve📝 Commits (9)
61a47c7engine, server: #533 elastic VRAM per GPU of a layer split (VRAM <reserve_mib> [device])fe1c2f1engine, server: #533 the per-card handoff works: VRAM - [device], and the reserve lands67f3a50engine, server: #533 the two points from the branch review8a3e31cdocs: the per-card handoff on a layer split, and the slot rows measured on 2x RTX 3090e3388d2sycl: parse 'VRAM - [device]' as the CUDA engine does9e31bb8server: label POST /v1/vram's GPUs in the engine's card order and count one replica's cards069a8b4engine: the VRAM command's error paths upload the residency table and relend the prompt's loan0fb5ad9verify: revert #2522's refresh_residency and the ungated refresh_ar9a54a13engine, docs, tools: #533 the dash gives each card its own start reserve📊 Changes
15 files changed (+1135 additions, -192 deletions)
View changed files
📝
docs/BATCHING.md(+22 -0)📝
docs/DETAILS.md(+18 -4)📝
docs/MULTI_GPU.md(+37 -0)📝
docs/VRAM_ELASTIC.md(+9 -6)📝
include/strata/core/expert_cache.hpp(+4 -0)➕
include/strata/program/vram_rules.hpp(+63 -0)📝
serve/runconfig.py(+4 -0)📝
serve/server.py(+118 -44)📝
serve/test_server.py(+24 -10)📝
serve/test_vram.py(+184 -21)📝
src/core/expert_cache.cpp(+8 -0)📝
src/program/generate.cpp(+219 -97)📝
sycl/src/program/generate.cpp(+43 -9)📝
tests/core/expert_cache_segmented_test.cpp(+110 -1)➕
tools/comfy_vram_handoff.py(+272 -0)📄 Description
Problem and result
#533sizes the VRAM reserve once at start and gives the whole run one number, so on a layer split there is no way to hand one card's experts to another program while the run keeps serving: the other program takes the VRAM and the engine's decode collapses (the eviction case in #516). This makes the reserve per card on a split.Result on this box (2x RTX 3090, Swift 1.5 IQ3_XXS, layers 0-23 / 24-47,
"parallel": 2,--vram-reserve-mib 700, 512-token greedy decode):"vram_elastic": trueandfalsegive the same cache (20 091 slots, 33 037 MiB) and 106.6 vs 106.4 tok/s - the segments cost nothing while nothing is handed away.torch.cuda.init()and its first tensor took the card from 23505 to 23810 MiB used); it fails incuDevicePrimaryCtxRetainwith CUDA_ERROR_OUT_OF_MEMORY at 80 MiB free and attaches at 613.Approach
--vram-elasticno longer refuses a layer split; every card's expert cache is segmented (512 MiB), andVRAM <reserve_mib> [device]moves one card's cache (device = the engine's number, 0 = the main card, the--split-devicenumbering) or every card of the run. Shrink/grow run on that card against its own free VRAM, the eviction scan is scoped to that stage's layers (slot numbers are per cache), and the prompt loan is re-lent at the largest chunk every card can still lend. One report line per card, thenVRAM-DONE.include/strata/program/vram_rules.hppholds the rules so the test can drive them).main's. The branch had addedVerifier::refresh_residencyand ungatedrefresh_ar(); that moves the default path of every run, also with--vram-elasticoff (measured by TacoTakumi on 2x RTX 3090: the branch prints "have experts out of VRAM" for both stages with the flag off, the reverted build prints nothing).mainalready handles a shrink per window - each window'srefresh_ar()(#871) reads the host residency table, so a stage that was 100% resident at init switches to the doorbell graph once the table shows an expert out of VRAM - soverify.cpp,verify.hppand the handler's call are gone. qiuzan2001's point 1 is given back with them.POST /v1/vramtakesgpu(validated against the run's cards), answers with one entry per card ingpusplus the totals over them, and still works with an engine that answers one line and noVRAM-DONE. With no device it sends a bareVRAM, so it keeps working against an engine from before this change (qiuzan2001's point 2); the dash is sent only when a device follows.min_free_vram_mibreads every card the run will use and names the busy ones. The numbers it prints are the engine's own card order (ordered_gpus, the faster card last), and with replicas they are one engine's cards, not every replica's (TacoTakumi's finding 4).VRAM - 1): a number in the first slot IS the reserve, soreserve_mib: nullwith agpuused to sendVRAM 1- a 1 MiB reserve on EVERY card, not the start's reserve on GPU 1.VRAM -1is still refused. On a split the dash now means each card's OWN start reserve ---vram-reserve-mibfor the main card,--vram-reserve-later-mibfor the later ones, the rule the sizing at start already uses - so a bareVRAMgives every card back its own number (ca22c998).shrinkkeeps whole segments and rounds its keep UP, so a reserve asked for arrived up to one segment short and a need under one segment freed nothing at all;segment_floorrounds the keep DOWN to a segment boundary (12000 asked from 8292 free lands 12384, not 11872).VRAM - 1parses there as it does on CUDA (TacoTakumi's finding 3); the segmented cache stays CUDA-only, so it refuses the resize. Its copy drives one cache, so the per-card rule is nothing to do there: that card's start reserve is its own.vram_elasticandvram_segment_mibare editable keys (from the next start), andtools/comfy_vram_handoff.pydrives the whole handoff: reserve, queue, wait, /free, restore.What it leaves alone. The default path is byte-identical to the last release:
vram_elasticis opt-in, and with it off a split runs as before. Single-card runs, the helper caches,--peer-deviceand the resident low-RAM mode are untouched. The split itself never moves: a card keeps its dense weights, its session and its KV, and nothing is reloaded.Related discussion
https://github.com/Niko1221/Strata/issues/533 - closed 2026-10-04 with the single-GPU form; this is the per-card extension for a layer split, with #516 as the same pain on Linux. No maintainer agreement on scope for this branch. The branch review (qiuzan2001, 2026-10-15) raised the two points; its comment is read-only ("the engine was not built or run"), and the measurements here are ours on this box.
The four findings in the thread (TacoTakumi, 2026-10-25) are taken as their own commits, with them as the author: the verify revert, the error-path guard, the SYCL parse and the server card order. i-Vladimir-i's note about #2398 and its HIP parent #2399 is not implemented here: the admission guard still requires a segmented cache, so a shared
--kv-growarena and this path stay separate; their reading was marked static analysis and the combination is untested here.Validation
Rebased on the latest
main(v0.2.11+ 3 =9f7d977d); the head is nowb817ab7c. The rows that nameeccbb0d0,ca22c998ande76b2724were run there - the two builds, the SYCL build, the gate and the hardware runs of 2026-10-26, -27 and -30; the top block below was run onb817ab7con this box. Environment for everything run on this box: 2x RTX 3090 (PCIe, sm_86), Linux, driver 595.71.05. The measurements in Problem and result are from the pre-rebase branchfaef4490on this box, on the model named there; they have not been re-run on this revision.Passed:
CUDA build on
b817ab7con this box (arch 86, setup's pinned flagsSTRATA_MMQ_KQUANTSandSTRATA_Q6K_EXPERTS, CUDA 13.0 nvcc): 578/578 targets, configures and links clean.python -m unittest serve.test_vramonb817ab7c: 18 tests OK;python tools/test_setup_config.py: 16 tests OK.python -m unittest serve.test_serveronb817ab7c: 374 tests, one failure -GpuChoice.test_hip_ordinal, which fails the same way on cleanmainbuilt with the same flags, checked in a second worktree, so it is not this change. Two of its#4352tests patchfree_vram_miband now give it the card index, because the guard reads every card the run will use; the file's other mocks already did, and the test that checks a two-card run is this branch's own.the ctest tier for the code this branch touches on
b817ab7c(-DSTRATA_BUILD_TESTS=ONon the same flags):expert_cache_per_layer_test,expert_cache_segmented_test,expert_cache_slot_guard_test,expert_profile_save_test,expert_profile_version_test- 5 of 5, including the segmented test's injected fill failure and sync failure, which check the device table against the host table. The other names thev0.2.6row lists are no longer registered on this base; the tier is whatmainhas.the GPU parity/residency tier on
b817ab7c, both arms, same flags, one run each, the box's lease held for the window: 11 of 12 on this branch and 11 of 12 on cleanmain- the one failure isexpert_parityon both arms (itspack/full/experts.binis not in the worktree), so it is the box, not the patch.pdl_parity,dma_batch_parity,decode_cluster_parity,fusions_parity,batch_rows_parity,cuda_device_selftest,verify_parity,spec_verify_parity,route_resident_parity,resident_plan_parity,verify_batch_paritypass on both arms.the changed path re-run on the hardware on the canary at
b817ab7c(the tree's config:vram_elastic: true,gpu [0, 1],layer_split auto,parallel 2, this box's model):{"reserve_mib": 8192, "gpu": 1}moved only GPU 1 (7682 -> 3986 slots, 8580 MiB free, one report line for that card); a bare{}gave each card its own start reserve - GPU 0 reported 896 (1135 MiB free) and GPU 1 reported 1134 (1378 MiB free);{"reserve_mib": null, "gpu": 1}alone reported 1134; the tool'svram 12288 --gpu 1moved GPU 1 alone (1987 slots, the prompt chunk 8192 -> 4096); a second per-card call and a second bare call answered the same. A request answered after each of the six calls.the staged gate on the rebased tree, on
b817ab7cagainst live prod (bench-0210-ab1e574e), both on this box: PASS (reportresults/gate/2026-11-05-1445-44) - canary loaded in 24 s, speed 122.5 tok/s median of 113/122.8/122.5 against prod's live column (median 118.8, stored clean baseline 108.2, floor 86.6) - inside the ~8% noise floor this box has between the gate's two columns, so: no change measured; cache hit 99.1% on the branch, 98.4% on prod's column; needle 3/3 at 32k, depths 10/50/90; probes 10/10 correct in every run, every probe its own majority (2 of 3); 0 fatal lines. Verdict PASS, prod restored.CUDA build on
eccbb0d0on this box (sm_86, setup's pinned flagsSTRATA_MMQ_KQUANTSandSTRATA_Q6K_EXPERTS): configures and links clean; the binary measured below isbe2545581066....SYCL build on
eccbb0d0in thestrata-sycl-devimage per docs/INTEL.md (SPIR-V, no AOT): configure and build clean -BUILD EXIT 0,errors: 0, 134 targets, linkedstrata.python -m unittest serve.test_vramonca22c998: 18 tests OK in 4.3 s - the line with a device, the bare line with no device, per-card aggregation, the old engine, refusals, the route, a reserve kept for an unloaded engine, and the two tests from the fork (a reorderedgpulist, two replicas).python -m unittest serve.test_serveronca22c998: 353 tests, one failure -GpuChoice.test_hip_ordinal, which fails the same way on cleanmainon this box (checked in a second worktree), so it is not this change. Its free-VRAM guard takes the per-card reading and checks a two-card run.python tools/test_setup_config.pyonca22c998: 16 tests OK (vram_elasticandvram_segment_mibare editable keys).ctest --test-dir build-tests -R '^(expert_cache_per_layer_test|expert_cache_segmented_test|expert_cache_slot_guard_test|vmm_test|host_graph_launch_test|batch_telemetry_test|batch_read_test|adapt_async_default_test|split_ring_test|batch_rows_test|batch_groups_test)$'(built with-DSTRATA_BUILD_TESTS=ON): 11 of 11 passed, oneccbb0d0and again onca22c998, including the segmented test's injected fill failure and sync failure, which check the device table against the host table.the residency and verify parity tests on
ca22c998: 6 of 7 passed (verify_parity,spec_verify_parity,route_resident_parity,resident_plan_parity,verify_batch_parity,dma_batch_parity); the one failure is under Failed. Oneccbb0d0it was 5 of 7, the second failure the same out-of-memory kind.the canary gate on
eccbb0d0against the shipping release (bench-0231-b9a2f398), both on this box: speed 107.6 tok/s median of 99.4/107.6/122 against a clean baseline of 116.4 (floor 93.1; one sample retried because a second request ran with it) - inside the ~8% noise floor this box has between the gate's two columns, so: no change measured; cache hit 99.6% on both columns; needle 3/3 at 32k, depths 10/50/90; probes 10/10 correct in every run, every probe its own majority (2 of 3); 0 fatal lines. Verdict PASS, prod restored.the changed path run on the hardware, on the canary at
eccbb0d0(the tree's config:vram_elastic: true,gpu [0, 1],layer_split auto,parallel 2, this box's model):{"reserve_mib": 8192, "gpu": 1}moved only GPU 1 (7820 -> 3986 of 7820 slots, 8610 MiB free, 32 ms, one report line for that card);{"reserve_mib": null, "gpu": 1}grew only GPU 1 back (3986 -> 7480 slots, 567 ms);{"reserve_mib": 4000, "gpu": 5}answered 400 with the run's card count; the tool'svram 12288 --gpu 1moved GPU 1 alone (7480 -> 1987 slots, the prompt chunk 8192 -> 4096, 46 ms);{"reserve_mib": null}with nogpumoved both cards, one line each (GPU 0 9179 -> 8883 slots, GPU 1 1987 -> 7480, 894 ms). A request answered after each of the five calls.the dash on
ca22c998, same box and config:{"reserve_mib": 8192, "gpu": 1}moved only GPU 1 (3986 of 7819 slots, 8406 MiB free) and reported 8192; a bare{}then gave each card its own start reserve - GPU 0 reported 896 (8883 of 9177 slots, 995 MiB free) and GPU 1 reported 1134 (7480 of 7819, 1238 MiB free);{"reserve_mib": null, "gpu": 1}alone reported 1134 on GPU 1. Both calls repeated and answered the same, and a request answered after them.POST /v1/vramwith nogpuagainst an engine from before this change is pinned byserve/test_vram.py(the bare line); it was not run against a real older engine here.Failed:
batch_rows_parity(malloc: out of memory) on this box with the server holding both cards and the RAM (45 GiB free of 156); it says nothing about the change and was not run on the pre-rebase branch either.dma_batch_parity, which failed the same way oneccbb0d0, passed onca22c998. Both pass onb817ab7c, on this branch and on cleanmain.Not run:
src/files here are unverified on HIP.tools/test_setup_golden.py: not run on this revision; it fails 48 tests on a clean checkout on this box, so it says nothing here.Limits
--peer-device, no resident low-RAM mode, NVIDIA only.tools/comfy_vram_handoff.pywaits for the queue to empty before it asks for the reserve; a busy run will not hand anything away.ca22c998the dash left GPU 0 at 995 MiB free against the 896 asked and GPU 1 at 1238 against 1134.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.