mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
fix(engine): probe nvidia-smi for actual VRAM before falling back to heuristic
On NVIDIA systems, spawns nvidia-smi once (cached) to read actual GPU memory. Uses real VRAM for the Chrome GPU budget instead of guessing from total system RAM. Falls back to total/2 on non-NVIDIA systems or when nvidia-smi is unavailable. No other headless Chrome renderer probes GPU memory — Remotion, Puppeteer, and Playwright all ignore --force-gpu-mem-available-mb entirely.
This commit is contained in:
@@ -480,7 +480,32 @@ function getTotalMemMb(): number {
|
||||
return Math.floor(totalmem() / (1024 * 1024));
|
||||
}
|
||||
|
||||
let _cachedVramMb: number | null = null;
|
||||
|
||||
function probeNvidiaVramMb(): number | null {
|
||||
if (_cachedVramMb !== null) return _cachedVramMb;
|
||||
try {
|
||||
const { execSync } = require("child_process") as typeof import("child_process");
|
||||
const out = execSync("nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits", {
|
||||
timeout: 3000,
|
||||
encoding: "utf-8",
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
}).trim();
|
||||
const mb = parseInt(out.split("\n")[0] ?? "", 10);
|
||||
if (Number.isFinite(mb) && mb > 0) {
|
||||
_cachedVramMb = mb;
|
||||
return mb;
|
||||
}
|
||||
} catch {
|
||||
// nvidia-smi not available or no NVIDIA GPU
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getGpuMemBudgetMb(): number {
|
||||
const vram = probeNvidiaVramMb();
|
||||
if (vram) return Math.min(vram, 65536);
|
||||
|
||||
const total = getTotalMemMb();
|
||||
if (total < 4096) return 512;
|
||||
if (total < 8192) return 1024;
|
||||
|
||||
Reference in New Issue
Block a user