From f354effc7241f4a2fc7b36dc8f93cbf61f5d4b53 Mon Sep 17 00:00:00 2001 From: Joseph Magly <1159087+jmagly@users.noreply.github.com> Date: Mon, 24 Aug 2026 12:51:02 -0400 Subject: [PATCH] fix(ui): refresh GPU memory gauge periodically --- app.py | 68 ++++++++++++++++++++++++-- obliteratus/ui_vram.py | 20 ++++++-- tests/conditional/test_operator_ui.py | 69 +++++++++++++++++++++++++++ tests/test_app_vram.py | 23 ++++++++- 4 files changed, 171 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index d631675..52778c4 100644 --- a/app.py +++ b/app.py @@ -59,7 +59,12 @@ import gradio as gr import torch from obliteratus import device as dev from obliteratus.credential_sources import resolve_first, resolve_secret, secret_available -from obliteratus.ui_vram import render_vram_html +from obliteratus.ui_vram import ( + DEFAULT_VRAM_REFRESH_INTERVAL, + VRAM_REFRESH_CHOICES, + render_vram_html, + resolve_vram_refresh_interval, +) from obliteratus.model_load_settings import ( DTYPE_CHOICES, QUANTIZATION_CHOICES, @@ -3957,6 +3962,28 @@ html:not(.dark) body::after { display: none; } margin-bottom: 8px; } +/* ---- GPU MEMORY MONITOR ---- */ +.vram-monitor-row { align-items: flex-end !important; } +.vram-display { flex-grow: 1 !important; } +.vram-refresh-control { + max-width: 108px !important; + margin-left: auto !important; + opacity: 0.72; +} +.vram-refresh-control:hover, +.vram-refresh-control:focus-within { opacity: 1; } +.vram-refresh-control label span { + font-size: 0.62rem !important; + letter-spacing: 0.06em !important; +} +.vram-refresh-control .wrap { min-height: 30px !important; } +@media (max-width: 640px) { + .vram-refresh-control { + max-width: 100px !important; + margin-left: auto !important; + } +} + /* ---- TAB STYLING ---- */ .tabs { border-bottom: 1px solid #1a1f2e !important; } button.tab-nav { @@ -4207,8 +4234,24 @@ with gr.Blocks(title="OBLITERATUS", fill_height=True) as demo: """) - # GPU VRAM monitor — refreshed on page load and after key operations - vram_display = gr.HTML(value=_get_vram_html()) + # GPU VRAM monitor — periodically refreshed and updated after key operations + with gr.Row(elem_classes=["vram-monitor-row"]): + vram_display = gr.HTML( + value=_get_vram_html(), + scale=12, + elem_classes=["vram-display"], + ) + vram_refresh_interval = gr.Dropdown( + choices=VRAM_REFRESH_CHOICES, + value=DEFAULT_VRAM_REFRESH_INTERVAL, + label="GPU refresh", + filterable=False, + allow_custom_value=False, + scale=1, + min_width=96, + elem_classes=["vram-refresh-control"], + ) + vram_refresh_timer = gr.Timer(value=DEFAULT_VRAM_REFRESH_INTERVAL, active=True) # ZeroGPU info — only shown when running on HF Spaces with ZeroGPU if _ZEROGPU_AVAILABLE: @@ -5497,6 +5540,25 @@ Built on the shoulders of: # Refresh VRAM on page load demo.load(fn=_get_vram_html, outputs=[vram_display]) + # Poll independently of long-running queued model work. Updating the one + # timer's interval avoids accumulating polling loops when the selector changes. + vram_refresh_timer.tick( + fn=_get_vram_html, + outputs=[vram_display], + queue=False, + concurrency_limit=1, + concurrency_id="vram-refresh", + api_visibility="private", + ) + vram_refresh_interval.change( + fn=resolve_vram_refresh_interval, + inputs=[vram_refresh_interval], + outputs=[vram_refresh_timer], + queue=False, + show_progress="hidden", + api_visibility="private", + ) + # --------------------------------------------------------------------------- # Launch diff --git a/obliteratus/ui_vram.py b/obliteratus/ui_vram.py index ad67c83..a3e265a 100644 --- a/obliteratus/ui_vram.py +++ b/obliteratus/ui_vram.py @@ -5,14 +5,24 @@ from __future__ import annotations from typing import Any +VRAM_REFRESH_CHOICES = (("10 sec", 10.0), ("30 sec", 30.0), ("1 min", 60.0)) +DEFAULT_VRAM_REFRESH_INTERVAL = 30.0 + + +def resolve_vram_refresh_interval(value: float) -> float: + """Return a supported VRAM polling interval, falling back to the default.""" + allowed = {interval for _label, interval in VRAM_REFRESH_CHOICES} + return value if value in allowed else DEFAULT_VRAM_REFRESH_INTERVAL + + def render_vram_html(device: Any) -> str: """Return per-device GPU/accelerator memory usage as styled bars.""" - if not device.is_gpu_available(): - return ( - '