Skip to content

fixes for gpu monitoring#5

Merged
j4ys0n merged 2 commits into
mainfrom
claude/msquant-ui-quantization-011CUnDrUZLYgbNPBXZ8iKzY
Nov 4, 2025
Merged

fixes for gpu monitoring#5
j4ys0n merged 2 commits into
mainfrom
claude/msquant-ui-quantization-011CUnDrUZLYgbNPBXZ8iKzY

Conversation

@j4ys0n

@j4ys0n j4ys0n commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

No description provided.

Root Cause:
- The ui.select component was initialized with an empty options list
  but with value=0, causing ValueError since 0 is not in the options
- NiceGUI validates that initial value must exist in the options list

Changes:
- Removed the invalid value=0 parameter from ui.select initialization
- The value is set properly later in update_gpu_metrics() when GPUs
  are detected
- Added explicit .update() call when setting GPU select value
- Improved handling of the no-GPU case to prevent empty select errors

Impact:
- Monitor page now loads correctly without crashing
- GPU selector populates dynamically when GPUs are detected
- Better error handling when no GPUs are available
Changes:
- Added validation to ensure selected GPU index exists in current GPU list
  before attempting to update charts
- Prevents chart updates when no valid GPU is selected
- Returns early if selected GPU is invalid/missing

Prevents potential errors when:
- Initial selected_gpu_index value (0) doesn't match any GPU
- Previously selected GPU becomes unavailable
- GPU select component has no value set

This addresses user concern #5 about preventing chart updates
without a valid GPU selection.
Copilot AI review requested due to automatic review settings November 4, 2025 04:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves GPU selection handling in the monitor page to prevent errors when no GPUs are available or when the selected GPU becomes invalid. The changes add defensive checks and proper state management for GPU availability.

Key changes:

  • Removed default value initialization for the GPU selector to avoid selecting non-existent GPUs
  • Added validation to ensure selected GPU exists before updating charts
  • Implemented proper handling for GPU disconnection scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

available_gpus["list"] = gpu_options
gpu_select.options = gpu_options
# Only set value if we have GPUs and no valid selection
if selected_gpu_index["value"] not in [g.index for g in gpus]:

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list comprehension [g.index for g in gpus] is created twice in quick succession (lines 123 and 142). Consider storing it in a variable gpu_indices before line 123 to avoid redundant iteration through the GPU list.

Copilot uses AI. Check for mistakes.
# No GPUs detected
if available_gpus["list"]: # Had GPUs before but now gone
available_gpus["list"] = []
gpu_select.options = []

Copilot AI Nov 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When clearing GPU state due to no GPUs detected, selected_gpu_index['value'] should also be reset to maintain consistent state. Consider setting it to None or 0 to prevent using a stale GPU index value.

Suggested change
gpu_select.options = []
gpu_select.options = []
selected_gpu_index["value"] = None

Copilot uses AI. Check for mistakes.
@j4ys0n

j4ys0n commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

Automated review 🤖

Summary of Changes
This PR addresses issues in the GPU monitoring page by fixing GPU selection logic and preventing invalid chart updates. It ensures the UI correctly handles GPU detection changes and avoids errors when GPUs are removed or selection becomes invalid.

Key Changes & Positives

  • 🟢 Removes hardcoded default GPU selection (value=0) to allow dynamic selection
  • 🟢 Adds logic to reset GPU selection when GPUs are disconnected
  • 🟢 Prevents chart updates when selected GPU is no longer available
  • 🟢 Improves GPU list synchronization with UI dropdown

Potential Issues & Recommendations

  1. Issue / Risk: GPU selection reset logic may cause flickering or inconsistent UI state when GPUs are reconnected.
    Impact: Minor UX disruption during dynamic GPU detection changes.
    Recommendation: Add a debounce or state change guard to prevent rapid updates.
    Status: 🟡 Needs review

  2. Issue / Risk: No explicit handling for when selected_gpu_index["value"] is None or invalid.
    Impact: Could lead to unexpected behavior if initial state is not properly initialized.
    Recommendation: Add explicit null/invalid check before accessing selected_gpu_index["value"].
    Status: 🟡 Needs review

  3. Issue / Risk: gpu_select.update() is called manually, which may not be necessary in all UI frameworks.
    Impact: Potential performance or compatibility issue if framework auto-updates.
    Recommendation: Verify if manual update is required or can be removed.
    Status: 🟡 Needs review

Language/Framework Checks

  • Python/Streamlit: UI state management is handled via global variables (available_gpus, selected_gpu_index). Ensure these are properly scoped and don't cause race conditions in concurrent environments.
  • Python/Logging: No logging added; consider adding debug logs for GPU detection changes.

Security & Privacy

  • No security or privacy concerns introduced.

Build/CI & Ops

  • No build or CI changes.

Tests

  • No tests included. Consider adding unit tests for GPU selection logic and chart update conditions.

Approval Recommendation
Approve with caveats

  • Verify GPU selection reset behavior during dynamic GPU detection
  • Confirm manual gpu_select.update() is necessary for current UI framework
  • Add tests for edge cases (no GPUs, invalid selection, reconnection)

@j4ys0n
j4ys0n merged commit 691183b into main Nov 4, 2025
7 checks passed
@j4ys0n
j4ys0n deleted the claude/msquant-ui-quantization-011CUnDrUZLYgbNPBXZ8iKzY branch November 4, 2025 04:45
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.

3 participants