fix(System): correct NVIDIA VRAM in Graphics card (#835)

PR #804 added pciutils to the admin image so AMD detection could fall
back to lspci. Side effect for NVIDIA: si.graphics() now finds the card
via lspci but reads the BAR0 region size (16-32 MiB on most NVIDIA
cards) as VRAM, since nvidia-smi isn't installed in the admin image to
enrich the result. A GTX 1050 Ti showed 32 MB instead of 4096.

The nvidia-smi-via-Ollama and Ollama log probes already give the right
number, but they only ran when graphics.controllers came back empty.
Extend the trigger so they also run when the only entries are NVIDIA
controllers reporting under 256 MiB (no real dGPU has that little). If
the probes can't reach a value either (Ollama not installed, passthrough
broken), VRAM now falls back to N/A instead of the bogus 32.

Verified locally on an RTX 4070 Ti by simulating the container condition
(lspci available, nvidia-smi unreachable). Before the fix: vram 32, model
"AD104 [GeForce RTX 4070 Ti]". After: vram 12288, model "NVIDIA GeForce
RTX 4070 Ti", from the Ollama inference-compute log line. Also confirmed
the same result inside the actual admin Docker image.
This commit is contained in:
Ben Gauger 2026-05-07 18:39:58 -06:00 committed by Jake Turner
parent 59bb405ff4
commit 6c799dd602
1 changed files with 32 additions and 3 deletions

View File

@ -399,9 +399,38 @@ export class SystemService {
os.kernel = dockerInfo.KernelVersion
}
// If si.graphics() returned no controllers (common inside Docker),
// fall back to runtime + Ollama log probe to figure out what's accessible.
if (!graphics.controllers || graphics.controllers.length === 0) {
// si.graphics() in the admin container uses lspci (pciutils ships in
// the image for AMD detection). lspci has no real VRAM info for NVIDIA
// cards, so systeminformation parses the first PCI memory Region (BAR0,
// 16-32 MiB on most NVIDIA cards) as `vram`. nvidia-smi enrichment also
// can't run since the binary isn't in the admin image. No real dGPU
// has under 256 MiB, so any NVIDIA controller below that needs the
// probes below to give us real data.
const NVIDIA_BOGUS_VRAM_THRESHOLD_MIB = 256
const isBogusNvidiaVram = (c: { vendor?: string; vram?: number | null }) =>
/nvidia/i.test(c.vendor || '') &&
typeof c.vram === 'number' &&
c.vram < NVIDIA_BOGUS_VRAM_THRESHOLD_MIB
// Clear the bogus value up front. If a probe replaces the entry below
// we get the real VRAM; if no probe succeeds (Ollama not installed,
// passthrough_failed) the UI falls back to "N/A" instead of showing
// "32 MB". The lspci model/vendor strings stay since they're still
// useful for identifying the card.
const hasLspciBogusNvidiaVram = (graphics.controllers || []).some(isBogusNvidiaVram)
if (hasLspciBogusNvidiaVram) {
for (const c of graphics.controllers) {
if (isBogusNvidiaVram(c)) c.vram = null
}
}
// Run the probes when controllers are empty (common inside Docker) or
// when lspci gave us bogus NVIDIA BAR0 values that need replacing.
if (
!graphics.controllers ||
graphics.controllers.length === 0 ||
hasLspciBogusNvidiaVram
) {
const runtimes = dockerInfo.Runtimes || {}
gpuHealth.hasNvidiaRuntime = 'nvidia' in runtimes