vllm.utils.gpu_memory_monitor ¶
GPU memory monitoring and warning system.
GPUMemoryMonitor ¶
Monitors GPU memory usage and emits warnings when threshold exceeded.
This is an opt-in monitoring system that helps prevent OOM crashes by warning users when GPU memory usage is high. It has zero overhead when disabled (default).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold | float | Memory usage ratio (0.0-1.0) that triggers warnings. Default is 0.90 (90%). | 0.9 |
check_interval | float | Minimum seconds between memory checks. Default is 5.0 seconds. | 5.0 |
enabled | bool | Whether monitoring is enabled. Default is False. | False |
warning_cooldown | float | Minimum seconds between warning messages to avoid log spam. Default is 60.0 seconds. | 60.0 |
Example
monitor = GPUMemoryMonitor(enabled=True, threshold=0.85) monitor.check_and_warn() # Call periodically
Source code in vllm/utils/gpu_memory_monitor.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
__init__ ¶
__init__(
threshold: float = 0.9,
check_interval: float = 5.0,
enabled: bool = False,
warning_cooldown: float = 60.0,
)
Source code in vllm/utils/gpu_memory_monitor.py
_check_device ¶
Check memory usage for a specific GPU device.
Source code in vllm/utils/gpu_memory_monitor.py
_emit_warning ¶
_emit_warning(
device_id: int,
usage_ratio: float,
memory_allocated: int,
memory_reserved: int,
memory_total: int,
) -> None
Emit structured warning about high GPU memory usage.
Source code in vllm/utils/gpu_memory_monitor.py
check_and_warn ¶
Check GPU memory usage and emit warning if threshold exceeded.
This method is designed to be called frequently (e.g., after each model execution step) but will only perform actual checks based on check_interval to minimize overhead.
Warnings are rate-limited by warning_cooldown to avoid log spam.
Source code in vllm/utils/gpu_memory_monitor.py
get_memory_stats ¶
Get current memory statistics for a GPU device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_id | int | GPU device ID to query. Default is 0. | 0 |
Returns:
| Name | Type | Description |
|---|---|---|
dict | None | Dictionary with memory statistics, or None if CUDA unavailable. | |
Keys | dict | None | allocated_gb, reserved_gb, total_gb, usage_ratio |