Skip to content

Commit d3cc379

Browse files
authored
[Perf] Fix slow hasattr in CUDAGraphWrapper.__getattr__ (vllm-project#37425)
Signed-off-by: 智鸣 <hzm414167@alibaba-inc.com>
1 parent 354cd58 commit d3cc379

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

vllm/compilation/cuda_graph.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def __init__(
189189

190190
self.first_run_finished = False
191191
self.is_debugging_mode = envs.VLLM_LOGGING_LEVEL == "DEBUG"
192+
self._runnable_str = str(runnable) if self.is_debugging_mode else None
192193

193194
# assert runtime_mode is not NONE(no cudagraph), otherwise, we don't
194195
# need to initialize a CUDAGraphWrapper.
@@ -211,10 +212,12 @@ def __getattr__(self, key: str) -> Any:
211212
# allow accessing the attributes of the runnable.
212213
if hasattr(self.runnable, key):
213214
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
218221

219222
def unwrap(self) -> Callable[..., Any]:
220223
# in case we need to access the original runnable.

vllm/v1/worker/gpu_ubatch_wrapper.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def __init__(
119119

120120
self.sm_control = self._create_sm_control_context(vllm_config)
121121
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
122124

123125
@property
124126
def graph_pool(self):
@@ -170,10 +172,12 @@ def __getattr__(self, key: str):
170172
# allow accessing the attributes of the runnable.
171173
if hasattr(self.runnable, key):
172174
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
177181

178182
def unwrap(self) -> Callable:
179183
# in case we need to access the original runnable.

0 commit comments

Comments
 (0)