Skip to content

fix(daemon): report engine vram on amd through drm fdinfo - #947

Open
ahmadbbi wants to merge 1 commit into
FlashML-org:mainfrom
ahmadbbi:fix/daemon-amd-vram
Open

ahmadbbi wants to merge 1 commit into
FlashML-org:mainfrom
ahmadbbi:fix/daemon-amd-vram

Conversation

@ahmadbbi

Copy link
Copy Markdown

Closes #946

On AMD (ROCm) the daemon's GET /engine/metrics always reported vramBytes: 0: daemon/metrics.py asks pynvml, then nvidia-smi, and returned 0 when neither exists.

When both give nothing, vram_bytes_for_pids now reads the kernel's DRM fdinfo (/proc/<pid>/fdinfo/*) for the serve tree's pids and sums drm-resident-vram (drm-memory-vram on older kernels), counting each (drm-pdev, drm-client-id) once so forked workers and dup'ed fds are not double counted. Stdlib only, no subprocess. The NVIDIA path is unchanged: the fallback runs only where the old code returned 0.

Testing

Hardware: Radeon RX 7800 XT (gfx1101, 16 GB), Ubuntu 26.04.1, kernel 7.0.0-44, in-tree amdgpu.
Software: main at 4237991 plus this change, torch 2.14.1+rocm7.14, Python 3.12.
Checkpoint: Qwen2.5-Coder-3B-Instruct, Q4_K_M GGUF (the Ollama qwen2.5-coder:3b blob).

ft serve --model models/qwen2.5-coder-3b-q4_k_m.gguf --port 1929
python -c "from freetoken.daemon.metrics import engine_footprint; print(engine_footprint(<serve pgid>))"
amd-smi process --json
  • engine_footprint reported vramBytes 15,395,758,080 across the 4 serve pids; amd-smi process showed 15,034,640 KiB (15,395,471,360 bytes) for the same process.
  • pytest tests/daemon -q: 39 passed.

Not tested: an NVIDIA machine (that path is not touched), and the value as rendered by the Desktop app.

Test added

tests/daemon/test_daemon_metrics.py. Every probe in this module answers 0 on failure, so a regression in the fdinfo path would raise nothing and an AMD engine would just show as using no VRAM. The test feeds a fake /proc and checks the per-client dedup, the pid filter, the older key spelling, and the unit handling.

@ahmadbbi ahmadbbi mentioned this pull request Nov 22, 2026
2 of 29 tasks

This branch has not been deployed

No deployments
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.

daemon: report engine VRAM on AMD (ROCm) in /engine/metrics

1 participant