[PR #250] [MERGED] Server: unload the model after an idle time (--idle-unload / "idle_unload_s", as Strata's), off by default #425

Closed
opened 2026-10-29 21:25:16 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/250
Author: @cryptedy
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @mw00

Base: main ← Head: pr/idle-unload


📝 Commits (2)

  • 368496b Server: unload the model after an idle time (--idle-unload / "idle_unload_s", as Strata's)
  • 2cb1c04 Idle unload: tests (a lifecycle mock engine) and docs/SETUP.md

📊 Changes

3 files changed (+171 additions, -14 deletions)

View changed files

📝 docs/SETUP.md (+19 -0)
📝 serve/server.py (+82 -14)
📝 serve/test_server.py (+70 -0)

📄 Description

What

"idle_unload_s": N in the config (or --idle-unload N on the server's command line): after N seconds with no request running or waiting, the engine ends, giving back its GPU memory and its pinned RAM tier. The next request starts it again. It is Strata's idle_unload_s, for a PC that shares its GPU with other programs (another model server, games). 0 (the default): never; nothing changes.

  • Service.unload(idle_for) takes every FIFO place without waiting and refuses (busy) while a request runs or waits, a context reload is on, or a request ended less than idle_for ago. It then ends the engine with StrataEngine.close (QUIT; with STRATA_GLM_SLOT_KEEP=1 the conversation in the model is written first) and waits for the GPU memory. A thread checks every min(30, N/4) s.
  • Service.ensure_engine() starts the engine again before a request and before a picture is encoded, since the encoder borrows the engine's memory. It is the restart after a crash (#27), moved into one place.
  • While unloaded:
    • /v1/models still lists the model with "status": {"value": "unloaded"} (as Strata's);
    • /health has "unloaded": true;
    • the Monitor's live state is unloaded;
    • /props answers.
  • docs/SETUP.md: a short section.

A note on StrataEngine.stop

StrataEngine defines stop twice: stop(timeout) (QUIT, wait, then wait for the GPU memory) and later stop() (the request's STOP). The second shadows the first, so self.engine.stop() only stops the request in flight. This is why the unload uses close(). _restart_with (the dashboard's context change) also calls stop() and relies on restart() killing the process. That works, but it skips the graceful QUIT. This PR leaves it as is.

Checked

RTX 3090, Ryzen 7 9700X, Windows 11, Maya-S24, --idle-unload 60, STRATA_GLM_SLOT_KEEP=1:

  • after the idle time: VRAM 22.9 GB -> 0 MiB, the engine's RAM 79.4 GB -> 0. /v1/models lists the model as unloaded; /health says unloaded: true.
  • the next turn of the same chat: 46.8 s including the load, with 1,630 of its 1,690 prompt tokens reused from the kept conversation. The turn after it: 1.9 s.
  • a request with a picture right after an unload: 48.5 s including the load, answered correctly (the engine starts before the encoder borrows its memory).
  • started through maya.py with the config key: [maya] the model unloads after 900 s without requests.
  • serve/test_server.py gets IdleUnload (a mock engine with the lifecycle): an idle unload and the next request's start, busy while a request is recent, holds the FIFO or waits, unsupported for an engine without it.
  • check_hip_compat passes. The other Python tests show only the Windows-only errors unmodified main shows here. Not run on Linux.

🔄 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/mw00/project-maya/pull/250 **Author:** [@cryptedy](https://github.com/cryptedy) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `pr/idle-unload` --- ### 📝 Commits (2) - [`368496b`](https://github.com/mw00/project-maya/commit/368496b47ee86b4ad9acc783a2729233dd568107) Server: unload the model after an idle time (--idle-unload / "idle_unload_s", as Strata's) - [`2cb1c04`](https://github.com/mw00/project-maya/commit/2cb1c04cda65aa3ce085a535ec07756b79867704) Idle unload: tests (a lifecycle mock engine) and docs/SETUP.md ### 📊 Changes **3 files changed** (+171 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETUP.md` (+19 -0) 📝 `serve/server.py` (+82 -14) 📝 `serve/test_server.py` (+70 -0) </details> ### 📄 Description ### What `"idle_unload_s": N` in the config (or `--idle-unload N` on the server's command line): after N seconds with no request running or waiting, the engine ends, giving back its GPU memory and its pinned RAM tier. The next request starts it again. It is Strata's `idle_unload_s`, for a PC that shares its GPU with other programs (another model server, games). `0` (the default): never; nothing changes. - `Service.unload(idle_for)` takes every FIFO place without waiting and refuses (`busy`) while a request runs or waits, a context reload is on, or a request ended less than `idle_for` ago. It then ends the engine with `StrataEngine.close` (QUIT; with `STRATA_GLM_SLOT_KEEP=1` the conversation in the model is written first) and waits for the GPU memory. A thread checks every `min(30, N/4)` s. - `Service.ensure_engine()` starts the engine again before a request and **before a picture is encoded**, since the encoder borrows the engine's memory. It is the restart after a crash (#27), moved into one place. - While unloaded: - `/v1/models` still lists the model with `"status": {"value": "unloaded"}` (as Strata's); - `/health` has `"unloaded": true`; - the Monitor's live state is `unloaded`; - `/props` answers. - `docs/SETUP.md`: a short section. ### A note on `StrataEngine.stop` `StrataEngine` defines `stop` twice: `stop(timeout)` (QUIT, wait, then wait for the GPU memory) and later `stop()` (the request's STOP). The second shadows the first, so `self.engine.stop()` only stops the request in flight. This is why the unload uses `close()`. `_restart_with` (the dashboard's context change) also calls `stop()` and relies on `restart()` killing the process. That works, but it skips the graceful QUIT. This PR leaves it as is. ### Checked RTX 3090, Ryzen 7 9700X, Windows 11, Maya-S24, `--idle-unload 60`, `STRATA_GLM_SLOT_KEEP=1`: - after the idle time: VRAM 22.9 GB -> 0 MiB, the engine's RAM 79.4 GB -> 0. `/v1/models` lists the model as `unloaded`; `/health` says `unloaded: true`. - the next turn of the same chat: 46.8 s including the load, with 1,630 of its 1,690 prompt tokens reused from the kept conversation. The turn after it: 1.9 s. - a request with a picture right after an unload: 48.5 s including the load, answered correctly (the engine starts before the encoder borrows its memory). - started through `maya.py` with the config key: `[maya] the model unloads after 900 s without requests`. - `serve/test_server.py` gets `IdleUnload` (a mock engine with the lifecycle): an idle unload and the next request's start, `busy` while a request is recent, holds the FIFO or waits, `unsupported` for an engine without it. - `check_hip_compat` passes. The other Python tests show only the Windows-only errors unmodified `main` shows here. Not run on Linux. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:16 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#425
No description provided.