@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 13e6b1b908
Fork 0

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 5, 08:30 UTC

[BugFix][CPU] Add CPU profiler summary file output (#38366)

Signed-off-by: Elham Harirpoush <elham.harirpoush@arm.com>

Elham committed Apr 10, 2026 at 01:41 UTC 13e6b1b90831770d41efd506615373e6bb350271
1 file changed +33 -15
vllm/profiler/wrapper.py
+33 -15
@@ -240,6 +240,28 @@ class TorchProfilerWrapper(WorkerProfiler):
240 0,
241 )
242
243 + def _build_profiler_table(
244 + self,
245 + sort_key: str,
246 + row_limit: int | None = None,
247 + ) -> str:
248 + if row_limit is None: # use profiler default row limit of 100
249 + return self.profiler.key_averages().table(sort_by=sort_key)
250 + return self.profiler.key_averages().table(
251 + sort_by=sort_key,
252 + row_limit=row_limit,
253 + )
254 +
255 + def _write_profiler_table(self, rank: int, table: str) -> None:
256 + profiler_dir = self.profiler_config.torch_profiler_dir
257 +
258 + # Skip file write for URI paths (gs://, s3://, etc.)
259 + # as standard file I/O doesn't work with URI schemes
260 + if not _is_uri_path(profiler_dir):
261 + profiler_out_file = f"{profiler_dir}/profiler_out_{rank}.txt"
262 + with open(profiler_out_file, "w") as f:
263 + print(table, file=f)
264 +
265 @override
266 def _start(self) -> None:
267 self.profiler.start()
@@ -251,26 +273,22 @@ class TorchProfilerWrapper(WorkerProfiler):
273 profiler_config = self.profiler_config
274 rank = self.local_rank
275 if profiler_config.torch_profiler_dump_cuda_time_total:
254 - profiler_dir = profiler_config.torch_profiler_dir
255 - sort_key = "self_cuda_time_total"
256 - table = self.profiler.key_averages().table(sort_by=sort_key)
257 -
258 - # Skip file write for URI paths (gs://, s3://, etc.)
259 - # as standard file I/O doesn't work with URI schemes
260 - if not _is_uri_path(profiler_dir):
261 - profiler_out_file = f"{profiler_dir}/profiler_out_{rank}.txt"
262 - with open(profiler_out_file, "w") as f:
263 - print(table, file=f)
276 + table = self._build_profiler_table(sort_key="self_cuda_time_total")
277 + self._write_profiler_table(rank, table)
278
279 # only print profiler results on rank 0
280 if rank == 0:
281 print(table)
268 - if self.dump_cpu_time_total and rank == 0:
269 - logger.info(
270 - self.profiler.key_averages().table(
271 - sort_by="self_cpu_time_total", row_limit=50
272 - )
282 +
283 + if self.dump_cpu_time_total:
284 + table = self._build_profiler_table(
285 + sort_key="self_cpu_time_total", row_limit=50
286 )
287 + self._write_profiler_table(rank, table)
288 +
289 + # only print profiler results on rank 0
290 + if rank == 0:
291 + print(table)
292
293 @override
294 def _profiler_step(self) -> bool: