[Profiler] Add per-session profiling controls to Python and Rust frontends (#57875)
Signed-off-by: czhu <conway.zhu@cohere.com> Signed-off-by: Conway Zhu <conway.zhu@cohere.com> Co-authored-by: aoshen02 <aoshen@inferact.ai>
This commit is contained in:
@@ -12,9 +12,14 @@ from typing_extensions import TypeVar
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm.config import ParallelConfig, VllmConfig
|
||||
from vllm.config.profiler import (
|
||||
validate_profile_iteration_bounds,
|
||||
validate_profile_prefix,
|
||||
)
|
||||
from vllm.distributed import stateless_destroy_torch_distributed_process_group
|
||||
from vllm.distributed.parallel_state import get_dp_group
|
||||
from vllm.engine.arg_utils import EngineArgs
|
||||
from vllm.exceptions import ProfilerAlreadyActiveError
|
||||
from vllm.inputs import EngineInput, PromptType
|
||||
from vllm.logger import configure_logging_if_needed, init_logger
|
||||
from vllm.lora.request import LoRARequest
|
||||
@@ -116,6 +121,7 @@ class LLMEngine:
|
||||
log_stats=self.log_stats,
|
||||
renderer=renderer,
|
||||
)
|
||||
self._profile_session_active = False
|
||||
|
||||
self.logger_manager: StatLoggerManager | None = None
|
||||
if self.log_stats:
|
||||
@@ -358,11 +364,33 @@ class LLMEngine:
|
||||
|
||||
return processed_outputs.request_outputs
|
||||
|
||||
def start_profile(self, profile_prefix: str | None = None):
|
||||
self.engine_core.profile(True, profile_prefix)
|
||||
def start_profile(
|
||||
self,
|
||||
profile_prefix: str | None = None,
|
||||
*,
|
||||
delay_iterations: int | None = None,
|
||||
max_iterations: int | None = None,
|
||||
):
|
||||
if self._profile_session_active:
|
||||
raise ProfilerAlreadyActiveError()
|
||||
validate_profile_prefix(profile_prefix)
|
||||
validate_profile_iteration_bounds(delay_iterations, max_iterations)
|
||||
|
||||
self._profile_session_active = True
|
||||
try:
|
||||
self.engine_core.profile(
|
||||
True,
|
||||
profile_prefix,
|
||||
delay_iterations,
|
||||
max_iterations,
|
||||
)
|
||||
except BaseException:
|
||||
self._profile_session_active = False
|
||||
raise
|
||||
|
||||
def stop_profile(self):
|
||||
self.engine_core.profile(False)
|
||||
self._profile_session_active = False
|
||||
|
||||
def reset_mm_cache(self):
|
||||
# Join the background MM warmup first: the mm_processor_cache is not
|
||||
|
||||
Reference in New Issue
Block a user