Skip to content

Commit

Permalink
[misc] Add Torch profiler support for CPU-only devices (vllm-project#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonFool authored Aug 23, 2024
1 parent fc5ebbd commit faeddb5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions vllm/worker/cpu_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,32 @@ def __init__(
self.cache_engine: List[CPUCacheEngine]
self.cpu_cache: List[List[torch.Tensor]]

# Torch profiler. Enabled and configured through env vars:
# VLLM_TORCH_PROFILER_DIR=/path/to/save/trace
if envs.VLLM_TORCH_PROFILER_DIR:
torch_profiler_trace_dir = envs.VLLM_TORCH_PROFILER_DIR
logger.info("Profiling enabled. Traces will be saved to: %s",
torch_profiler_trace_dir)
self.profiler = torch.profiler.profile(
activities=[
torch.profiler.ProfilerActivity.CPU,
],
with_stack=True,
on_trace_ready=torch.profiler.tensorboard_trace_handler(
torch_profiler_trace_dir, use_gzip=True))
else:
self.profiler = None

def start_profile(self):
if self.profiler is None:
raise RuntimeError("Profiler is not enabled.")
self.profiler.start()

def stop_profile(self):
if self.profiler is None:
raise RuntimeError("Profiler is not enabled.")
self.profiler.stop()

def init_device(self) -> None:
if self.local_omp_cpuid != "all":
torch.ops._C_utils.init_cpu_threads_env(self.local_omp_cpuid)
Expand Down

0 comments on commit faeddb5

Please sign in to comment.