[Profiler] Add Proton CUDA graph attribution for MRV2 (#51084)
Signed-off-by: Luossu <zhluosuu@outlook.com> Signed-off-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ from collections.abc import Callable
|
||||
from contextlib import AbstractContextManager, contextmanager, nullcontext
|
||||
from datetime import timedelta
|
||||
from types import NoneType
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
import numpy as np
|
||||
import regex as re
|
||||
@@ -64,6 +64,7 @@ from vllm.profiler.wrapper import (
|
||||
CudaProfilerWrapper,
|
||||
ProtonProfilerWrapper,
|
||||
TorchProfilerWrapper,
|
||||
create_graph_capture_profiler,
|
||||
)
|
||||
from vllm.sequence import IntermediateTensors
|
||||
from vllm.tasks import SupportedTask
|
||||
@@ -142,6 +143,7 @@ def maybe_rocm_profiling_fallback(profile_result: MemoryProfilingResult) -> int
|
||||
if TYPE_CHECKING:
|
||||
from vllm.device_allocator.sleep_mode_backend import SleepModeBackend
|
||||
from vllm.model_executor.model_loader.tensorizer import TensorizerConfig
|
||||
from vllm.v1.worker.gpu.model_runner import GPUModelRunner as GPUModelRunnerV2
|
||||
from vllm.v1.worker.gpu_model_runner import GPUModelRunner
|
||||
|
||||
|
||||
@@ -810,7 +812,8 @@ class Worker(WorkerBase):
|
||||
|
||||
cuda_graph_memory_bytes = 0
|
||||
if not self.model_config.enforce_eager:
|
||||
cuda_graph_memory_bytes = self.model_runner.capture_model()
|
||||
with self._get_cudagraph_capture_context():
|
||||
cuda_graph_memory_bytes = self.model_runner.capture_model()
|
||||
|
||||
# Compare actual vs estimated CUDA graph memory (if we did profiling)
|
||||
if (
|
||||
@@ -949,6 +952,21 @@ class Worker(WorkerBase):
|
||||
encoder=self.compilation_config.encoder_compilation_time,
|
||||
)
|
||||
|
||||
def _get_cudagraph_capture_context(self) -> AbstractContextManager[None]:
|
||||
"""Let the configured profiler observe CUDA graph capture."""
|
||||
if not self.use_v2_model_runner:
|
||||
return nullcontext()
|
||||
if self.profiler is None:
|
||||
model_runner = cast("GPUModelRunnerV2", self.model_runner)
|
||||
if not model_runner.needs_cudagraph_capture():
|
||||
return nullcontext()
|
||||
self.profiler = create_graph_capture_profiler(
|
||||
self.profiler_config, global_rank=self.rank
|
||||
)
|
||||
if self.profiler is None:
|
||||
return nullcontext()
|
||||
return self.profiler.capture_cuda_graphs()
|
||||
|
||||
def reset_mm_cache(self) -> None:
|
||||
self.model_runner.reset_mm_cache()
|
||||
|
||||
@@ -1248,6 +1266,9 @@ class Worker(WorkerBase):
|
||||
else:
|
||||
trace_name = rank_suffix
|
||||
|
||||
if profiler_type == "proton" and self.profiler is not None:
|
||||
self.profiler.set_output_name(trace_name)
|
||||
|
||||
# Create the profiler wrapper only on the first start call
|
||||
if self.profiler is None:
|
||||
if profiler_type == "torch":
|
||||
@@ -1284,7 +1305,9 @@ class Worker(WorkerBase):
|
||||
try:
|
||||
self.profiler.stop()
|
||||
finally:
|
||||
if self.profiler_config.profiler == "proton":
|
||||
if self.profiler_config.profiler == "proton" and not (
|
||||
self.profiler.has_cuda_graph_session
|
||||
):
|
||||
# Proton output names are fixed when the wrapper is constructed.
|
||||
# Recreate it so the next profile_prefix is honored.
|
||||
self.profiler = None
|
||||
|
||||
Reference in New Issue
Block a user