Add VLLM_NVTX_SCOPES_FOR_PROFILING=1 to enable nvtx.annotate scopes (#25501)

Signed-off-by: Corey Lowman <clowman1993@gmail.com>
This commit is contained in:
Corey Lowman
2025-09-23 22:50:09 +00:00
committed by GitHub
parent abad204be6
commit c85d75cf08
2 changed files with 22 additions and 3 deletions
+17 -3
View File
@@ -375,8 +375,22 @@ def report_usage_stats(
})
_PROFILER_FUNC = None
def record_function_or_nullcontext(name: str) -> AbstractContextManager:
global _PROFILER_FUNC
# fast path assume it is set
if _PROFILER_FUNC is not None:
return _PROFILER_FUNC(name)
func = contextlib.nullcontext
if envs.VLLM_CUSTOM_SCOPES_FOR_PROFILING:
return record_function(name)
else:
return contextlib.nullcontext()
func = record_function
elif envs.VLLM_NVTX_SCOPES_FOR_PROFILING:
import nvtx
func = nvtx.annotate
_PROFILER_FUNC = func
return func(name)