A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 6, 10:45 UTC
[Perf] Fix slow hasattr in CUDAGraphWrapper.__getattr__ (#37425)
Signed-off-by: 智鸣 <hzm414167@alibaba-inc.com>
Ziming Huang committed
Mar 19, 2026 at 15:43 UTC
d3cc379567cdf8787b1e9e688536cdf7c179f474
2 files changed
+15
-8
vllm/compilation/cuda_graph.py
+7
-4
@@ -189,6 +189,7 @@ class CUDAGraphWrapper:
189
190
self.first_run_finished = False
191
self.is_debugging_mode = envs.VLLM_LOGGING_LEVEL == "DEBUG"
192
+ self._runnable_str = str(runnable) if self.is_debugging_mode else None
193
194
# assert runtime_mode is not NONE(no cudagraph), otherwise, we don't
195
# need to initialize a CUDAGraphWrapper.
@@ -211,10 +212,12 @@ class CUDAGraphWrapper:
212
# allow accessing the attributes of the runnable.
213
if hasattr(self.runnable, key):
214
return getattr(self.runnable, key)
214
- raise AttributeError(
215
- f"Attribute {key} not exists in the runnable of "
216
- f"cudagraph wrapper: {self.runnable}"
217
- )
215
+ if self.is_debugging_mode:
216
+ raise AttributeError(
217
+ f"Attribute {key} not exists in the runnable of "
218
+ f"cudagraph wrapper: {self._runnable_str}"
219
+ )
220
+ raise AttributeError
221
222
def unwrap(self) -> Callable[..., Any]:
223
# in case we need to access the original runnable.
vllm/v1/worker/gpu_ubatch_wrapper.py
+8
-4
@@ -119,6 +119,8 @@ class UBatchWrapper:
119
120
self.sm_control = self._create_sm_control_context(vllm_config)
121
self.device = device
122
+ self.is_debugging_mode = envs.VLLM_LOGGING_LEVEL == "DEBUG"
123
+ self._runnable_str = str(runnable) if self.is_debugging_mode else None
124
125
@property
126
def graph_pool(self):
@@ -170,10 +172,12 @@ class UBatchWrapper:
172
# allow accessing the attributes of the runnable.
173
if hasattr(self.runnable, key):
174
return getattr(self.runnable, key)
173
- raise AttributeError(
174
- f"Attribute {key} not exists in the runnable of "
175
- f"cudagraph wrapper: {self.runnable}"
176
- )
175
+ if self.is_debugging_mode:
176
+ raise AttributeError(
177
+ f"Attribute {key} not exists in the runnable of "
178
+ f"cudagraph wrapper: {self._runnable_str}"
179
+ )
180
+ raise AttributeError
181
182
def unwrap(self) -> Callable:
183
# in case we need to access the original runnable.