[Profiler] Add minimal Triton Proton profiling backend (#48789)

Signed-off-by: Luossu <zhluosuu@outlook.com>
This commit is contained in:
鐘天楽
2026-08-11 14:51:57 -07:00
committed by GitHub
parent 61874f9842
commit a367cdbca0
7 changed files with 637 additions and 20 deletions
+23 -10
View File
@@ -55,7 +55,11 @@ from vllm.lora.request import LoRARequest
from vllm.model_executor.warmup.kernel_warmup import kernel_warmup
from vllm.multimodal.gpu_ipc_memory import reserve_mm_ipc_gpu_memory
from vllm.platforms import current_platform
from vllm.profiler.wrapper import CudaProfilerWrapper, TorchProfilerWrapper
from vllm.profiler.wrapper import (
CudaProfilerWrapper,
ProtonProfilerWrapper,
TorchProfilerWrapper,
)
from vllm.sequence import IntermediateTensors
from vllm.tasks import SupportedTask
from vllm.tracing import instrument
@@ -162,16 +166,12 @@ class Worker(WorkerBase):
self._weight_update_active = False
self._weight_update_is_draft = False
# Torch/CUDA profiler. Enabled and configured through profiler_config.
# Worker profiler. Enabled and configured through profiler_config.
# Profiler wrapper is created lazily in profile() when start is called,
# so we have all the information needed for proper trace naming.
self.profiler: Any | None = None
self.profiler_config = vllm_config.profiler_config
# Only validate profiler config is valid, don't instantiate yet
if self.profiler_config.profiler not in ("torch", "cuda", None):
raise ValueError(f"Unknown profiler type: {self.profiler_config.profiler}")
self.use_v2_model_runner = vllm_config.use_v2_model_runner
# pending non-blocking PP send work from the previous iteration
self._pp_send_work: list[Handle] = []
@@ -909,6 +909,8 @@ class Worker(WorkerBase):
return nullcontext()
self.profiler.step()
if not self.profiler.is_running:
return nullcontext()
iteration_details = compute_iteration_details(scheduler_output)
@@ -1125,6 +1127,7 @@ class Worker(WorkerBase):
)
if is_start:
profiler_type = self.profiler_config.profiler
# Generate the trace name by combining prefix with comprehensive rank suffix
from vllm.distributed.utils import get_worker_rank_suffix
@@ -1138,7 +1141,6 @@ class Worker(WorkerBase):
# Create the profiler wrapper only on the first start call
if self.profiler is None:
profiler_type = self.profiler_config.profiler
if profiler_type == "torch":
self.profiler = TorchProfilerWrapper(
self.profiler_config,
@@ -1152,20 +1154,31 @@ class Worker(WorkerBase):
elif profiler_type == "cuda":
self.profiler = CudaProfilerWrapper(self.profiler_config)
logger.debug("Starting CUDA profiler")
elif profiler_type == "proton":
self.profiler = ProtonProfilerWrapper(
self.profiler_config, worker_name=trace_name
)
logger.debug(
"Starting Proton profiler with trace name: %s", trace_name
)
else:
# Config validation should prevent this code being reached
raise ValueError(
f"Invalid profiler value of {self.profiler_config.profiler}"
)
# If profiler already initialized, restart profiling but keep
# the original trace name from the first initialization.
self.profiler.start()
else:
if self.profiler is None:
logger.warning("Profiler was not started, nothing to stop.")
return
self.profiler.stop()
try:
self.profiler.stop()
finally:
if self.profiler_config.profiler == "proton":
# Proton output names are fixed when the wrapper is constructed.
# Recreate it so the next profile_prefix is honored.
self.profiler = None
def execute_dummy_batch(self) -> None:
num_tokens = getattr(self.model_runner, "uniform_decode_query_len", 1)