Pull requests / #2851

#2851 --keep-awake N: hold the system awake while the engine serves (#1727)

closed · @suprfire · 0 コメント · GitHub で見る

Server & APIAMD / HIPNVIDIA / CUDAModels & quantsWindows

本文

Closes #1727 (the feature request for a native prevent-sleep option during active inference on Windows).

## What it changes

A new opt-in engine flag, `--keep-awake N` (an argument in the config's `args`):

- `0` (or no flag) - off.
- `1` - hold the system awake for as long as the engine runs (armed at `READY`).
- `2` - hold it only while a request runs (request start to `DONE`/`STOP`/`ERR`), and hold the display too.

It calls `SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED [| ES_DISPLAY_REQUIRED])` on the serving thread and clears back to `ES_CONTINUOUS` when the arm ends. Windows only; a no-op elsewhere. `--keep-awake` without `--serve` is refused with a message.

## What it leaves alone

No default changes: with the flag absent nothing calls `SetThreadExecutionState`, so the default path is byte-identical. No new dependency (`windows.h` was already included). The `2` arm hooks the existing `BusyScope` (busy from a request's start to the end of its iteration), so `QUIT` and the between-request commands (`SAVE`/`RESTORE`/`VRAM`) do not arm it.

## Why

Windows counts a CPU-bound server as idle. Nothing in the engine asked the system to stay up, so a long prompt read can run into the display and sleep timers, and an S3 sleep kills the running request (the expert arena survives in RAM, so the model does not reload - the request is what is lost).

## How I checked it

RTX 3080 Ti 12 GB + Ryzen 9 5900X + 64 GB DDR4, Windows 11 (10.0.26200), engine built from this commit (CUDA 13.4, sm_86), Swift IQ3_XXS, `--keep-awake 1`:

- The start block shows `--keep-awake: SetThreadExecutionState(0x80000001) -> 0x80000000 (error 0)` - the return is the previous state, so the request was accepted.
- `powercfg /requests` (elevated) lists the engine under SYSTEM while it serves.
- With the AC sleep timer at **60 s** the machine stayed up **4.5+ minutes** with the engine serving and its uptime never reset; the same machine slept inside a minute with the flag off (Kernel-Power 42 and `powercfg /lastwake` confirm the off-case sleeps).
- The flag is refused without `--serve`, and `--help` lists the three values.

## What I did not test

- The `2` arm (only `1` was measured) and its display hold.
- A machine whose sleep state is S0 low-power idle rather than S3 (this box is S3).
- HIP/SYCL: the change is inside `#ifdef _WIN32` and compiles out on those backends.

関連リンク

インストール・モデル・リリースへの站内リンク。