Skip to content

Check free VRAM before starting the engine, with a system protection setting (D-58) - #40

Merged
eddybean merged 1 commit into
mainfrom
feat/memory-guard
Nov 28, 2026
Merged

eddybean merged 1 commit into
mainfrom
feat/memory-guard

Conversation

@eddybean

Copy link
Copy Markdown
Owner

What

Before engine_start stops the running worker and starts the new one, it checks that the model will fit in the free memory of the device it loads on (src-tauri/src/memguard.rs, D-58).

  • Free memory: speech devices --json (about 0.15 s) with the profile's speech.exe and device (auto/empty → first GPU, else CPU; gpu; cpu; a name). A CPU profile is checked against main memory.
  • Need: estimated from the model file's size, file × 1.1 + 512 MiB (Drama-3 Q4_K: 20.8 GiB file → 23.4 GiB; measured about 23.5 GiB).
  • What the running engine holds on the same device counts as free, since it stops first. It is measured after each start (free before minus after), with the estimate as a fallback.
  • 設定 → システム保護 (memoryGuard in settings.json; an unknown value reads as standard):
    • オフ: no check
    • 弱: asks when the model file alone does not fit
    • 標準 (default): asks when the estimate does not fit
    • 強: refuses unless the estimate plus 1.5 GiB is free
  • engine_start now returns {status: "started" | "confirm" | "blocked", check} and takes confirmed. The UI asks with confirm() and starts again on yes. blocked ignores confirmed and shows a notice.
  • The モデル screen's "必要VRAM 目安" uses the same estimate.

Why

The user wants to avoid freezing the PC by loading a model over VRAM another program is using, without refusing loads that would fit. So the estimate stays close to the measured figure, a shortfall asks instead of refusing below 強, and the strength is a setting.

Notes for review

  • If the check can't be made (speech devices fails, the device isn't listed, the file can't be read), it is skipped and the engine starts as before.
  • Drama-3 with experts_on_cpu may still run when the estimate doesn't fit (some experts are computed on the CPU); 標準 then asks first.
  • Not tried in the app, or on a GPU that is really short of memory: the logic is covered by unit tests (memguard.rs: 5, src/store/app.test.ts: 4). npm run check passes.

🤖 Generated with Claude Code

…setting (D-58)

engine_start now compares the model's estimated memory (file x 1.1 + 512 MiB)
with the free memory of the device it loads on (speech devices --json), counting
what the running engine holds as free. 設定 → システム保護 picks the strength:
off, low (file size only), standard (estimate, default) and strict (estimate +
1.5 GiB). Below strict a shortfall asks before starting instead of refusing, so
a load that would fit is never blocked outright.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eddybean
eddybean enabled auto-merge (squash) November 28, 2026 09:35
@eddybean
eddybean merged commit fe929b7 into main Nov 28, 2026
7 checks passed
@eddybean
eddybean deleted the feat/memory-guard branch November 28, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant