From 23450fb21ac255b0cf710f4ee965ee694921975d Mon Sep 17 00:00:00 2001
From: Gahow Wang <gahow.wang@gmail.com>
Date: Sun, 12 Jul 2026 13:12:52 +0800
Subject: [PATCH] Recreate scheduled torch profiler between windows

---
 vllm/v1/worker/gpu_worker.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/vllm/v1/worker/gpu_worker.py b/vllm/v1/worker/gpu_worker.py
index 5e266a3..0058f96 100644
--- a/vllm/v1/worker/gpu_worker.py
+++ b/vllm/v1/worker/gpu_worker.py
@@ -978,6 +978,10 @@ class Worker(WorkerBase):
                 logger.warning("Profiler was not started, nothing to stop.")
                 return
             self.profiler.stop()
+            # A scheduled torch.profiler.profile does not reset its schedule
+            # after stop(). Recreate it for the next /start_profile window.
+            if isinstance(self.profiler, TorchProfilerWrapper):
+                self.profiler = None
 
     def execute_dummy_batch(self) -> None:
         num_tokens = getattr(self.model_runner, "uniform_decode_query_len", 1)
-- 
2.43.0

