mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1853] Feature Request: API for temporary VRAM offloading (sleep/wake endpoints) for single-GPU orchestration #731
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#731
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?
Originally created by @Mikhai133 on GitHub (Oct 10, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1853
TL;DR
Requesting a pair of HTTP endpoints — POST /release_memory_occupation and POST /resume_memory_occupation — that would allow Strata to gracefully free GPU VRAM (by paging weights to Host RAM) without killing the process. This would enable zero-restart, low-latency GPU handoff between Strata and other engines (like ComfyUI) on a single GPU, dramatically improving UX for single-GPU workstations.
Context & Problem Statement
I run a local AI stack orchestrating two engines on the same GPU (RTX 5090, 32 GB):
ComfyUI for image/video generation (LTX-2.5, Qwen-Image-Edit, etc.).
Strata for LLM inference (planning to migrate to Strata + Qwen3.8-Flash-Next-125B).
My manager service arbitrates the GPU. Before a ComfyUI job, it needs the LLM engine to sleep. When SGLang is used, this relies on its memory-occupation API (release_memory_occupation), which takes under 5 seconds because it moves weights to host RAM.
Currently, Strata has no equivalent. The only way to free VRAM for ComfyUI is to kill the process and restart it. While cold starts have improved massively in v0.1.40/41 (~70s for Q2_0 262K context, thank you!), a process restart is still an order of magnitude slower than a RAM-to-VRAM wake cycle. In reverse handoffs, an external report measured ~5 minutes to fully hand the GPU back to an LLM engine using process-level control.
On a 32GB card, this is the difference between "chat feels instant" and "chat feels like a batch job". Tools like T8mars/Comfyui-Strata-T8 exist but rely on process killing, meaning every transition costs a full cold start.
Proposed Solution
Add optional endpoints to the Strata server (e.g., gated behind STRATA_ENABLE_MEMORY_OCCUPATION_API=1):
Behavior: Move all resident hot-experts, KV-cache, and vision encoder weights from VRAM to Host RAM (not disk). Keep the process alive. Flush the CUDA allocator pool so nvidia-smi shows freed VRAM. Block incoming inference requests with 503 Service Unavailable.
Optional Payload: Allow surgical offloading.
{
"offload_targets": ["experts", "vision", "kv_cache"],
"keep_in_vram_mib": 2048
}
Return: 200 OK once VRAM is freed (or 503 if it cannot be freed within a timeout).
Behavior: Move weights back from RAM to VRAM. Recompute the optimal resident-expert set. Unblock inference.
Return: 200 OK once ready to serve.
Return: {"status": "parked", "vram_used_mib": N, "ram_pinned_mib": N, "ready_for_inference": false}. Allows orchestrators to make decisions without scraping nvidia-smi.
Technical Considerations / Implementation Ideas
Since Strata's core architecture already handles hot/cold expert paging, this shouldn't require rewriting the inference engine. It could be implemented as a "forced parking" mode over the existing memory manager:
Pinned Memory: Allocate a pool of Page-Locked (Pinned) Memory in Host RAM at startup. Using DMA for PCIe transfers could drop the offload/restore times for a 125B MoE model to just a few seconds on PCIe 4.0/5.0.
MoE Manager Hook: A global is_parked flag that intercepts the scheduler, forcing all hot experts to be marked as cold and paged to the RAM pool.
KV-Cache: Either copy KV blocks to RAM, or optionally quantize them on the fly (e.g., FP8/INT8) to halve the PCIe transfer time before parking.
Alternatives Considered
Process-level handoff (Process Kill): Works (e.g., T8mars nodes), but every transition triggers a 70s+ cold start.
Reduced Residency (--vram-reserve-mib, --resident-experts): Helps for light ComfyUI workloads, but breaks down completely when ComfyUI needs 20+ GB for video generation models.
Two GPUs: The correct long-term answer, but not an option for the vast majority of single-GPU users.
OS-level SIGSTOP: Doesn't work because the NVIDIA driver holds the CUDA context and VRAM allocations until the process dies or explicitly calls cudaFree.
Environment
Hardware: RTX 5090 (32 GB VRAM), 128 GB Host RAM
OS: Linux (Ubuntu 24.04)
Strata Version: v0.1.41
I am more than happy to test a beta build, provide detailed timing numbers, or help profile the PCIe transfer bottlenecks if this aligns with your roadmap. Thanks for the incredible work on v0.1.40/41 — the CPU-assisted prefill and multi-GPU concurrency improvements are excellent!
@GonzMartinez commented on GitHub (Oct 10, 2026):
There's already something like this but for only one GPU. I sloped it to two GPUs, next week i'll raise a pr. My use case is the same as you describe, leaving room for qwen image without killing strata and it is working well although i didn't use it extensively.
@Mikhai133 commented on GitHub (Oct 10, 2026):
This is fantastic news — and especially that your use case matches mine almost exactly (leaving VRAM headroom for Qwen-Image / LTX-2.5 while Strata stays alive).
Two quick questions while you're still shaping the PR, so I can pre-wire my orchestrator to match your API on day one:
Endpoint shape. Are you exposing it as POST /release_memory_occupation + POST /resume_memory_occupation (SGLang-compatible), or something Strata-specific? If it's the latter, what are the paths and payloads? I'd rather adopt your naming than have you accommodate mine.
What gets parked where. On release, do the experts/KV/vision weights stay in host RAM (fast resume, SGLang-style), or get written back to disk? And on resume, does the resident-expert set get recomputed from scratch, or does it restore the previous hot set?
Not asking for guarantees — just enough to know whether my wake path should budget 5 seconds or 50.
Offer: if you push the branch (even as a draft PR or a WIP tag), I'll wire it into my proxy and run it against a 5090 / 32 GB / 192 GB RAM on Ubuntu 24.04. I can share concrete latency numbers for both directions (ComfyUI→Strata and Strata→ComfyUI) within a day or two of getting a build. Happy to be an early test case — the more eyes on the two-GPU path before merge, the better.
Thanks again for the speed on this.
@GonzMartinez commented on GitHub (Oct 10, 2026):
I won't have access to the pc for some days, so I can't push till monday night. The endpoint I used already existed, I don't remember the exact name. You tell it how much VRAM you want to free on a specific GPU (its single GPU in upstream). I assume the experts go to RAM since it works quite fast to reclaim. Since I had not planned to post it yet I didn't review the code lol. My setup is similar to yours but with 2x3090s
@Mikhai133 commented on GitHub (Oct 10, 2026):
We implemented memory switching by changing the GPU ownership between Strata and ComfyUI.
Strata runs locally on port 8080.
The following options are enabled in the config:
vram_elastic: true
slot_save_path
--session-save-reclaim
--session-min-free-mib
Before a ComfyUI task, the manager calls sleep_agent_for_job().
For regular tasks — image, edit, short video:
http
POST /v1/vram
{"reserve_mib": 26000}
Strata shrinks, and ComfyUI gets the main VRAM.
After the task:
http
POST /v1/vram
{"reserve_mib": null}
For heavy tasks — long video, avatar quality, upscale ×1.8+:
http
POST /v1/vram {"reserve_mib": null}
POST /slots/0?action=save
POST /unload
... ComfyUI runs ...
http
POST /load
POST /slots/0?action=restore
After any ComfyUI task, the manager calls wake_agent_after_job().
The vision_proxy checks Strata’s state before the user’s request and wakes it up via:
/v1/vram, if the agent was compressed;
/load + /slots/0?action=restore, if the agent was unloaded.
Shell scripts for starting and stopping control the Strata process via the PID file and port 8080.
The watchdog restarts run-iq3_xxs.sh if the process crashes or the HTTP service stops responding.
For ComfyUI, the manager injects memory for diffusion.
Although SGLang’s speed with Qwen3.8‑27B‑NVFP4 was higher — both in model response time and in container‑switching speed — I’m confident that over time we’ll be able to find another solution or optimize this to achieve hot switching. My DDR5 and PCI‑E5 hardware is capable of more.
@NerdyShawn commented on GitHub (Oct 11, 2026):
Same single-GPU arbitration problem, but our two engines are both Strata servers (two 24 GiB quants on a 5090,
:8080/:8081), orchestrated by reciprocal/unloadhooks in each server'sbefore_load. Evidence that kill-and-reload handoff works but is expensive and has a sharp edge:/unload{"status":"busy"}answer during an active turn is advisory only —ensure_loadedignores the hook's exit code and loads anyway, which co-loads two 24 GiB quants and kills one engine (exit code 1). We documented the whole failure mode in #1997 (ignoredbefore_loadfailure → co-load crash) and shipped a poll-until-truly-unloaded hook as the workaround.Two design inputs for the PR you're shaping:
POST /v1/vramwith{"reserve_mib": ...}(vram_elastic, semantics now documented per #1034) be the non-kill primitive for dual-Strata handoff — sleep weights to RAM in both directions, process stays alive, no engine-restart cliff? If yes, that removes our worst failure mode entirely and seems strictly better than/unloadfor orchestration; we'd happily switch our hooks to it.We have a
SOAK_MINUTES=3contention-replay harness (chatter + big-prefill sessions + parallel bursts against the lane pair) and can smoke-test the new endpoint against it before you finalize semantics, if a second integration data point beyond the ComfyUI case is useful.@Niko1221 commented on GitHub (Oct 13, 2026):
Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.
If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
@kamedesuyo commented on GitHub (Oct 25, 2026):
I'd like to help with an opt-in implementation of this, following the scope-agreement requirement in CONTRIBUTING. The existing expert-cache resize in #533 is useful, but it does not release the dense weights, active session buffers, or draft/head allocations.
Local evidence: on Windows 11, an RTX 5060 Ti 16 GB, 96 GB host RAM, Qwen3.8-Flash-Next IQ3_S, 262144 context / int8 KV / 32768 resident cells, the current
--vram-elasticshrink leaves 7,450 MiB free out of 16,311 MiB. The expert cache reaches its 1,024 MiB floor. This is a local zapabob 0.3.1 build reporting engine 0.1.49.2, not a benchmark of current upstream main. I inspected upstream4b9e05a2a806a3fe24f7b2560d98626c37dade35(engine 0.1.51); I have not yet built or run that revision.I also built and ran a standalone CUDA Driver VMM probe, independently of Strata, on both GPUs in this machine. It reserves an address range, maps 64 MiB, creates a graph containing a kernel that changes every word, copies the data to host RAM, unmaps/releases the physical allocation, and restores into the same reserved address. It also allocates and overwrites another 64 MiB region while the first is asleep. The original graph is then replayed without reinstantiation.
MSVC 19.43 / CUDA 12.4 Driver API headers, a small PTX kernel JIT-compiled by the installed driver. Wrong-context wake was refused and a subsequent wake in the correct context succeeded. These are 64 MiB mechanism tests only: they do not establish full-engine correctness, multi-GiB latency, or the amount of VRAM Strata could release. The 4060's driver free-memory counter increased by 64 MiB each cycle; the 5060 Ti counter also includes unrelated desktop/device activity and is not a per-process measurement.
Proposed first scope:
Would this narrower scope be acceptable as an extension of the current VRAM controls, or is there an existing branch we should collaborate on? I can prepare a draft PR after agreeing the allocation/lifecycle boundary. No full-engine implementation or performance claim is being submitted here. Design/code preparation was assisted by Codex; the probe results above came from actual runs on the stated hardware.