Skip to main content
The GPU Memory Profiler includes a Textual-based terminal user interface (TUI) that provides interactive monitoring, profiling, and diagnostics without leaving your terminal.

Installation

Install with TUI support:
pip install "gpu-memory-profiler[tui]"
For development, TUI dependencies are included in requirements-dev.txt.

Launch the TUI

Start the interactive dashboard:
gpu-profiler
The TUI opens in your terminal with multiple tabs for different workflows.

Interface overview

The TUI provides six main tabs:
Live system summary showing:
  • Platform information (OS, Python version)
  • PyTorch/TensorFlow versions
  • GPU availability and configuration
  • Current memory snapshot
  • Backend detection (CUDA, ROCm, MPS, CPU)
Keyboard shortcut: Press r to refresh
╭─────────────────── System Overview ───────────────────╮
│ Platform: Linux-5.15.0-x86_64                         │
│ Python: 3.10.12                                       │
│ PyTorch: 2.1.0+cu121                                  │
│ TensorFlow: 2.15.0                                    │
│                                                        │
│ GPU 0: NVIDIA A100-SXM4-40GB                          │
│   Total: 40.00 GB                                     │
│   Allocated: 2.45 GB (6.1%)                           │
│   Reserved: 3.12 GB (7.8%)                            │
│   Backend: cuda                                       │
╰────────────────────────────────────────────────────────╯

Keyboard shortcuts

Global shortcuts available in all tabs:
KeyAction
rRefresh overview tab
fFocus the log panel
gLog gpumemprof info output
tLog tfmemprof info output
qQuit the TUI

Live tracking workflow

1

Navigate to Monitoring tab

Switch to the Monitoring tab using mouse or keyboard navigation.
2

Configure thresholds

Adjust warning and critical thresholds using the sliders:
  • Warning threshold: Default 80%
  • Critical threshold: Default 95%
These trigger alerts in the event log.
3

Enable auto cleanup (optional)

Toggle Auto Cleanup to enable MemoryWatchdog:
  • Monitors memory thresholds
  • Triggers torch.cuda.empty_cache() on warnings
  • Runs garbage collection on critical alerts
Manual cleanup buttons:
  • Force Cleanup: Clear CUDA cache
  • Aggressive Cleanup: Cache clear + GC
4

Start tracking

Click Start Live Tracking button.The TUI:
  1. Creates MemoryTracker instance
  2. Begins sampling at configured interval
  3. Streams events to log panel
  4. Updates statistics table
Events appear as:
[14:23:45] allocation: Allocated 512 MB
[14:23:46] peak: New peak memory: 2.45 GB
[14:23:52] memory_warning_percent: 82.3%
5

Monitor in real-time

Watch the stats table update every second:
  • Current memory allocation
  • Peak memory reached
  • Utilization percentage
  • Total alert count
The event log scrolls automatically with new events.
6

Export data

While tracking is active or after stopping:
  • Export CSV: Save to ./exports/tracking_TIMESTAMP.csv
  • Export JSON: Save to ./exports/tracking_TIMESTAMP.json
Files include all captured events with telemetry metadata.
7

Stop tracking

Click Stop Tracking to end the session.Final statistics remain visible for review.

Visualization workflow

1

Navigate to Visualizations tab

Switch to the Visualizations tab.
2

Refresh timeline

Click Refresh Timeline to generate ASCII visualization:
  • Reads current tracking session data
  • Renders memory timeline as text graph
  • Shows summary statistics
Requires active or completed tracking session.
3

Generate static plot

Click Generate PNG Plot to create Matplotlib visualization:
  • Saves to ./visualizations/memory_timeline_TIMESTAMP.png
  • Includes allocated and reserved memory
  • High-resolution (300 DPI)
Example plot:
  • X-axis: Time (seconds)
  • Y-axis: Memory (GB)
  • Two subplots: Allocated vs Reserved
4

Generate interactive plot

Click Generate HTML Plot for Plotly dashboard:
  • Saves to ./visualizations/dashboard_TIMESTAMP.html
  • Interactive hover tooltips
  • Zoom and pan controls
  • Multiple subplots with linked axes
Requires pip install "gpu-memory-profiler[viz]"

CLI automation workflow

1

Navigate to CLI & Actions tab

Switch to the CLI & Actions tab.
2

Use quick actions

Click preset buttons:Diagnose:
gpumemprof diagnose --duration 0 --output ./diag_bundle
Generates diagnostic bundle in seconds.OOM Scenario:
python -m examples.oom_scenario --mode simulated
Runs safe OOM flight recorder test.Capability Matrix:
python -m examples.cli.capability_matrix --mode smoke --skip-tui
Executes smoke test suite.
3

Run custom commands

Enter command in text input:
gpumemprof track --duration 10 --output /tmp/test.json
Click Run to execute. Output streams to RichLog.
4

Cancel long-running commands

Click Cancel Command to terminate:
  • Sends SIGTERM to subprocess
  • Displays cancellation in log
  • Cleans up resources

Profile inspection workflow

1

Run profiled code

In your terminal, execute code with profiling decorators:
from gpumemprof import profile_function

@profile_function
def train_step(model, data):
    output = model(data)
    loss = criterion(output)
    loss.backward()
    return loss

# Run training
for batch in dataloader:
    train_step(model, batch)
2

Refresh profiles in TUI

Switch to PyTorch or TensorFlow tab and click Refresh Profiles.The TUI queries global profiler instances used by decorators.
3

Review profiling results

Profile table shows:
  • Function name from decorator
  • Peak memory during execution
  • Memory delta (allocated - freed)
  • Average execution duration
Sorted by peak memory descending.
4

Clear profiles

Click Clear Profiles to reset profiling history.Useful when starting new profiling sessions.

GPU-less environments

The TUI gracefully handles systems without GPU:
When no GPU is detected:
  • Overview tab shows “GPU Available: No”
  • Displays CPU count and memory instead
  • Monitoring tab uses CPUMemoryTracker
  • CLI commands automatically use CPU mode
Example:
╭─────────── System Overview ───────────╮
│ GPU Available: No                     │
│ CPU Count: 8 physical / 16 logical    │
│ Total Memory: 32.00 GB                │
│ Available: 24.56 GB                   │
│ Backend: cpu                          │
╰───────────────────────────────────────╯
On macOS with Apple Silicon:
  • Detects MPS backend availability
  • Shows Metal plugin installation status
  • Provides installation hints if missing
  • Uses single logical device
Example:
╭─────────── Backend Info ──────────╮
│ Apple Silicon: Yes                │
│ MPS Available: Yes                │
│ PyTorch MPS: Available            │
│ TensorFlow Metal: Not Installed   │
│                                   │
│ Install for TensorFlow GPU:       │
│ pip install tensorflow-metal      │
╰───────────────────────────────────╯
For AMD GPUs with ROCm:
  • Detects ROCm backend
  • Shows ROCm version
  • Full profiling support
  • Same interface as CUDA
The TUI automatically uses the correct backend.

Terminal requirements

For optimal TUI experience:
  • Minimum size: 100x30 characters
  • Color support: 256 colors or true color
  • Unicode support: UTF-8 encoding
  • Terminal: Modern terminal emulators
    • iTerm2 (macOS)
    • Windows Terminal
    • GNOME Terminal
    • Alacritty
    • Kitty
Textual adapts to smaller windows but layout may be compressed.

Troubleshooting

ModuleNotFoundError: No module named 'textual'
Solution:
pip install "gpu-memory-profiler[tui]"
Overview shows “GPU Available: No” incorrectly.Check:
  1. CUDA/ROCm drivers installed
  2. PyTorch compiled with CUDA support:
    import torch
    print(torch.cuda.is_available())
    
  3. Visible devices:
    nvidia-smi  # or rocm-smi
    
TUI layout appears compressed.Solution:
  • Maximize terminal window
  • Zoom out (Cmd/Ctrl + -)
  • Use fullscreen mode
  • Minimum recommended: 100x30
“Start Live Tracking” button doesn’t respond.Check:
  1. PyTorch installed correctly
  2. No other profilers running
  3. Check error in log panel
  4. Restart TUI

Next steps

CLI usage

Learn command-line profiling tools

Visualization

Generate plots outside the TUI

PyTorch guide

PyTorch profiling APIs

TensorFlow guide

TensorFlow profiling APIs

Build docs developers (and LLMs) love