File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,32 @@ def __init__(
179179 self .cache_engine : List [CPUCacheEngine ]
180180 self .cpu_cache : List [List [torch .Tensor ]]
181181
182+ # Torch profiler. Enabled and configured through env vars:
183+ # VLLM_TORCH_PROFILER_DIR=/path/to/save/trace
184+ if envs .VLLM_TORCH_PROFILER_DIR :
185+ torch_profiler_trace_dir = envs .VLLM_TORCH_PROFILER_DIR
186+ logger .info ("Profiling enabled. Traces will be saved to: %s" ,
187+ torch_profiler_trace_dir )
188+ self .profiler = torch .profiler .profile (
189+ activities = [
190+ torch .profiler .ProfilerActivity .CPU ,
191+ ],
192+ with_stack = True ,
193+ on_trace_ready = torch .profiler .tensorboard_trace_handler (
194+ torch_profiler_trace_dir , use_gzip = True ))
195+ else :
196+ self .profiler = None
197+
198+ def start_profile (self ):
199+ if self .profiler is None :
200+ raise RuntimeError ("Profiler is not enabled." )
201+ self .profiler .start ()
202+
203+ def stop_profile (self ):
204+ if self .profiler is None :
205+ raise RuntimeError ("Profiler is not enabled." )
206+ self .profiler .stop ()
207+
182208 def init_device (self ) -> None :
183209 if self .local_omp_cpuid != "all" :
184210 torch .ops ._C_utils .init_cpu_threads_env (self .local_omp_cpuid )
You can’t perform that action at this time.
0 commit comments