[Feature] OTEL tracing during loading (#31162)
This commit is contained in:
@@ -110,6 +110,10 @@ class AsyncLLM(EngineClient):
|
||||
self.model_config = vllm_config.model_config
|
||||
self.vllm_config = vllm_config
|
||||
self.observability_config = vllm_config.observability_config
|
||||
tracing_endpoint = self.observability_config.otlp_traces_endpoint
|
||||
if tracing_endpoint is not None:
|
||||
init_tracer("vllm.llm_engine", tracing_endpoint)
|
||||
|
||||
self.log_requests = log_requests
|
||||
|
||||
custom_stat_loggers = list(stat_loggers or [])
|
||||
@@ -136,10 +140,8 @@ class AsyncLLM(EngineClient):
|
||||
log_stats=self.log_stats,
|
||||
stream_interval=self.vllm_config.scheduler_config.stream_interval,
|
||||
)
|
||||
endpoint = self.observability_config.otlp_traces_endpoint
|
||||
if endpoint is not None:
|
||||
tracer = init_tracer("vllm.llm_engine", endpoint)
|
||||
self.output_processor.tracer = tracer
|
||||
if tracing_endpoint is not None:
|
||||
self.output_processor.tracing_enabled = True
|
||||
|
||||
# EngineCore (starts the engine in background process).
|
||||
self.engine_core = EngineCoreClient.make_async_mp_client(
|
||||
|
||||
@@ -24,6 +24,7 @@ from vllm.logging_utils.dump_input import dump_engine_exception
|
||||
from vllm.lora.request import LoRARequest
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
from vllm.tasks import POOLING_TASKS, SupportedTask
|
||||
from vllm.tracing import instrument, maybe_init_worker_tracer
|
||||
from vllm.transformers_utils.config import maybe_register_config_serialize_by_value
|
||||
from vllm.utils.gc_utils import (
|
||||
freeze_gc_heap,
|
||||
@@ -217,6 +218,7 @@ class EngineCore:
|
||||
# environment variable overrides after this point)
|
||||
enable_envs_cache()
|
||||
|
||||
@instrument(span_name="Prepare model")
|
||||
def _initialize_kv_caches(
|
||||
self, vllm_config: VllmConfig
|
||||
) -> tuple[int, int, KVCacheConfig]:
|
||||
@@ -658,6 +660,7 @@ class EngineCoreProc(EngineCore):
|
||||
|
||||
ENGINE_CORE_DEAD = b"ENGINE_CORE_DEAD"
|
||||
|
||||
@instrument(span_name="EngineCoreProc init")
|
||||
def __init__(
|
||||
self,
|
||||
vllm_config: VllmConfig,
|
||||
@@ -926,8 +929,18 @@ class EngineCoreProc(EngineCore):
|
||||
data_parallel = parallel_config.data_parallel_size > 1 or dp_rank > 0
|
||||
if data_parallel:
|
||||
parallel_config.data_parallel_rank_local = local_dp_rank
|
||||
maybe_init_worker_tracer(
|
||||
instrumenting_module_name="vllm.engine_core",
|
||||
process_kind="engine_core",
|
||||
process_name=f"EngineCore_DP{dp_rank}",
|
||||
)
|
||||
set_process_title("EngineCore", f"DP{dp_rank}")
|
||||
else:
|
||||
maybe_init_worker_tracer(
|
||||
instrumenting_module_name="vllm.engine_core",
|
||||
process_kind="engine_core",
|
||||
process_name="EngineCore",
|
||||
)
|
||||
set_process_title("EngineCore")
|
||||
decorate_logs()
|
||||
|
||||
@@ -956,6 +969,7 @@ class EngineCoreProc(EngineCore):
|
||||
parallel_config.data_parallel_rank = 0
|
||||
engine_core = EngineCoreProc(*args, engine_index=dp_rank, **kwargs)
|
||||
|
||||
assert engine_core is not None
|
||||
engine_core.run_busy_loop()
|
||||
|
||||
except SystemExit:
|
||||
@@ -1485,6 +1499,13 @@ class EngineCoreActorMixin:
|
||||
dp_rank: int = 0,
|
||||
local_dp_rank: int = 0,
|
||||
):
|
||||
# Initialize tracer for distributed tracing if configured.
|
||||
maybe_init_worker_tracer(
|
||||
instrumenting_module_name="vllm.engine_core",
|
||||
process_kind="engine_core",
|
||||
process_name=f"DPEngineCoreActor_DP{dp_rank}",
|
||||
)
|
||||
|
||||
self.addresses = addresses
|
||||
vllm_config.parallel_config.data_parallel_index = dp_rank
|
||||
vllm_config.parallel_config.data_parallel_rank_local = local_dp_rank
|
||||
|
||||
@@ -24,6 +24,7 @@ from vllm.envs import VLLM_ENGINE_READY_TIMEOUT_S
|
||||
from vllm.logger import init_logger
|
||||
from vllm.lora.request import LoRARequest
|
||||
from vllm.tasks import SupportedTask
|
||||
from vllm.tracing import instrument
|
||||
from vllm.utils.async_utils import in_loop
|
||||
from vllm.utils.network_utils import (
|
||||
close_sockets,
|
||||
@@ -96,6 +97,7 @@ class EngineCoreClient(ABC):
|
||||
return InprocClient(vllm_config, executor_class, log_stats)
|
||||
|
||||
@staticmethod
|
||||
@instrument(span_name="Overall Loading")
|
||||
def make_async_mp_client(
|
||||
vllm_config: VllmConfig,
|
||||
executor_class: type[Executor],
|
||||
@@ -650,6 +652,7 @@ def _process_utility_output(
|
||||
class SyncMPClient(MPClient):
|
||||
"""Synchronous client for multi-proc EngineCore."""
|
||||
|
||||
@instrument(span_name="SyncMPClient init")
|
||||
def __init__(
|
||||
self, vllm_config: VllmConfig, executor_class: type[Executor], log_stats: bool
|
||||
):
|
||||
@@ -819,6 +822,7 @@ class SyncMPClient(MPClient):
|
||||
class AsyncMPClient(MPClient):
|
||||
"""Asyncio-compatible client for multi-proc EngineCore."""
|
||||
|
||||
@instrument(span_name="AsyncMPClient init")
|
||||
def __init__(
|
||||
self,
|
||||
vllm_config: VllmConfig,
|
||||
|
||||
@@ -100,8 +100,8 @@ class LLMEngine:
|
||||
)
|
||||
endpoint = self.observability_config.otlp_traces_endpoint
|
||||
if endpoint is not None:
|
||||
tracer = init_tracer("vllm.llm_engine", endpoint)
|
||||
self.output_processor.tracer = tracer
|
||||
init_tracer("vllm.llm_engine", endpoint)
|
||||
self.output_processor.tracing_enabled = True
|
||||
|
||||
# EngineCore (gets EngineCoreRequests and gives EngineCoreOutputs)
|
||||
self.engine_core = EngineCoreClient.make_client(
|
||||
|
||||
@@ -20,7 +20,12 @@ from vllm.outputs import (
|
||||
)
|
||||
from vllm.sampling_params import RequestOutputKind
|
||||
from vllm.tokenizers import TokenizerLike
|
||||
from vllm.tracing import SpanAttributes, SpanKind, Tracer, extract_trace_context
|
||||
from vllm.tracing import (
|
||||
SpanAttributes,
|
||||
SpanKind,
|
||||
extract_trace_context,
|
||||
instrument_manual,
|
||||
)
|
||||
from vllm.utils import length_from_prompt_token_ids_or_embeds
|
||||
from vllm.v1.engine import EngineCoreOutput, EngineCoreRequest, FinishReason
|
||||
from vllm.v1.engine.detokenizer import IncrementalDetokenizer
|
||||
@@ -422,7 +427,7 @@ class OutputProcessor:
|
||||
self.parent_requests: dict[str, ParentRequest] = {}
|
||||
self.external_req_ids: defaultdict[str, list[str]] = defaultdict(list)
|
||||
self.lora_states = LoRARequestStates(log_stats)
|
||||
self.tracer: Tracer | None = None
|
||||
self.tracing_enabled: bool = False
|
||||
self._requests_drained = asyncio.Event()
|
||||
self._requests_drained.set()
|
||||
|
||||
@@ -678,7 +683,7 @@ class OutputProcessor:
|
||||
self._update_stats_from_finished(
|
||||
req_state, finish_reason, iteration_stats
|
||||
)
|
||||
if self.tracer:
|
||||
if self.tracing_enabled:
|
||||
self.do_tracing(engine_core_output, req_state, iteration_stats)
|
||||
|
||||
return OutputProcessorOutput(
|
||||
@@ -714,62 +719,59 @@ class OutputProcessor:
|
||||
) -> None:
|
||||
assert req_state.stats is not None
|
||||
assert iteration_stats is not None
|
||||
assert self.tracer is not None
|
||||
|
||||
arrival_time_nano_seconds = int(req_state.stats.arrival_time * 1e9)
|
||||
metrics = req_state.stats
|
||||
arrival_time_ns = int(metrics.arrival_time * 1e9)
|
||||
trace_context = extract_trace_context(engine_core_output.trace_headers)
|
||||
prompt_length = length_from_prompt_token_ids_or_embeds(
|
||||
req_state.prompt_token_ids, req_state.prompt_embeds
|
||||
)
|
||||
with self.tracer.start_as_current_span(
|
||||
"llm_request",
|
||||
kind=SpanKind.SERVER,
|
||||
context=trace_context,
|
||||
start_time=arrival_time_nano_seconds,
|
||||
) as span:
|
||||
metrics = req_state.stats
|
||||
e2e_time = iteration_stats.iteration_timestamp - metrics.arrival_time
|
||||
queued_time = metrics.scheduled_ts - metrics.queued_ts
|
||||
prefill_time = metrics.first_token_ts - metrics.scheduled_ts
|
||||
decode_time = metrics.last_token_ts - metrics.first_token_ts
|
||||
inference_time = metrics.last_token_ts - metrics.scheduled_ts
|
||||
span.set_attribute(
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_TO_FIRST_TOKEN,
|
||||
metrics.first_token_latency,
|
||||
)
|
||||
span.set_attribute(SpanAttributes.GEN_AI_LATENCY_E2E, e2e_time)
|
||||
span.set_attribute(SpanAttributes.GEN_AI_LATENCY_TIME_IN_QUEUE, queued_time)
|
||||
span.set_attribute(SpanAttributes.GEN_AI_USAGE_PROMPT_TOKENS, prompt_length)
|
||||
span.set_attribute(
|
||||
SpanAttributes.GEN_AI_USAGE_COMPLETION_TOKENS,
|
||||
metrics.num_generation_tokens,
|
||||
)
|
||||
span.set_attribute(
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_IN_MODEL_PREFILL, prefill_time
|
||||
)
|
||||
span.set_attribute(
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_IN_MODEL_DECODE, decode_time
|
||||
)
|
||||
span.set_attribute(
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_IN_MODEL_INFERENCE, inference_time
|
||||
)
|
||||
|
||||
# meta
|
||||
span.set_attribute(
|
||||
SpanAttributes.GEN_AI_REQUEST_ID, req_state.external_req_id
|
||||
# Calculate timing metrics
|
||||
e2e_time = iteration_stats.iteration_timestamp - metrics.arrival_time
|
||||
queued_time = metrics.scheduled_ts - metrics.queued_ts
|
||||
prefill_time = metrics.first_token_ts - metrics.scheduled_ts
|
||||
decode_time = metrics.last_token_ts - metrics.first_token_ts
|
||||
inference_time = metrics.last_token_ts - metrics.scheduled_ts
|
||||
|
||||
# Build attributes dict
|
||||
attributes: dict[str, Any] = {
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_TO_FIRST_TOKEN: (
|
||||
metrics.first_token_latency
|
||||
),
|
||||
SpanAttributes.GEN_AI_LATENCY_E2E: e2e_time,
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_IN_QUEUE: queued_time,
|
||||
SpanAttributes.GEN_AI_USAGE_PROMPT_TOKENS: prompt_length,
|
||||
SpanAttributes.GEN_AI_USAGE_COMPLETION_TOKENS: (
|
||||
metrics.num_generation_tokens
|
||||
),
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_IN_MODEL_PREFILL: prefill_time,
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_IN_MODEL_DECODE: decode_time,
|
||||
SpanAttributes.GEN_AI_LATENCY_TIME_IN_MODEL_INFERENCE: inference_time,
|
||||
SpanAttributes.GEN_AI_REQUEST_ID: req_state.external_req_id,
|
||||
}
|
||||
|
||||
# Add optional request parameters
|
||||
if req_state.top_p:
|
||||
attributes[SpanAttributes.GEN_AI_REQUEST_TOP_P] = req_state.top_p
|
||||
if req_state.max_tokens_param:
|
||||
attributes[SpanAttributes.GEN_AI_REQUEST_MAX_TOKENS] = (
|
||||
req_state.max_tokens_param
|
||||
)
|
||||
if req_state.top_p:
|
||||
span.set_attribute(SpanAttributes.GEN_AI_REQUEST_TOP_P, req_state.top_p)
|
||||
if req_state.max_tokens_param:
|
||||
span.set_attribute(
|
||||
SpanAttributes.GEN_AI_REQUEST_MAX_TOKENS, req_state.max_tokens_param
|
||||
)
|
||||
if req_state.temperature:
|
||||
span.set_attribute(
|
||||
SpanAttributes.GEN_AI_REQUEST_TEMPERATURE, req_state.temperature
|
||||
)
|
||||
if req_state.n:
|
||||
span.set_attribute(SpanAttributes.GEN_AI_REQUEST_N, req_state.n)
|
||||
if req_state.temperature:
|
||||
attributes[SpanAttributes.GEN_AI_REQUEST_TEMPERATURE] = (
|
||||
req_state.temperature
|
||||
)
|
||||
if req_state.n:
|
||||
attributes[SpanAttributes.GEN_AI_REQUEST_N] = req_state.n
|
||||
|
||||
instrument_manual(
|
||||
span_name="llm_request",
|
||||
start_time=arrival_time_ns,
|
||||
attributes=attributes,
|
||||
context=trace_context,
|
||||
kind=SpanKind.SERVER,
|
||||
)
|
||||
|
||||
def _update_stats_from_output(
|
||||
self,
|
||||
|
||||
@@ -15,6 +15,7 @@ from vllm.distributed.kv_transfer.kv_connector.v1.base import (
|
||||
from vllm.logger import init_logger
|
||||
from vllm.lora.request import LoRARequest
|
||||
from vllm.tasks import SupportedTask
|
||||
from vllm.tracing import instrument
|
||||
from vllm.utils.import_utils import resolve_obj_by_qualname
|
||||
from vllm.v1.core.sched.output import GrammarOutput, SchedulerOutput
|
||||
from vllm.v1.engine import ReconfigureDistributedRequest
|
||||
@@ -84,6 +85,7 @@ class Executor(ABC):
|
||||
)
|
||||
return executor_class
|
||||
|
||||
@instrument(span_name="Executor init")
|
||||
def __init__(
|
||||
self,
|
||||
vllm_config: VllmConfig,
|
||||
|
||||
@@ -41,6 +41,7 @@ from vllm.distributed.parallel_state import (
|
||||
)
|
||||
from vllm.envs import enable_envs_cache
|
||||
from vllm.logger import init_logger
|
||||
from vllm.tracing import instrument, maybe_init_worker_tracer
|
||||
from vllm.utils.network_utils import (
|
||||
get_distributed_init_method,
|
||||
get_loopback_ip,
|
||||
@@ -527,6 +528,7 @@ class WorkerProc:
|
||||
)
|
||||
)
|
||||
|
||||
@instrument(span_name="Worker init")
|
||||
def __init__(
|
||||
self,
|
||||
vllm_config: VllmConfig,
|
||||
@@ -740,6 +742,15 @@ class WorkerProc:
|
||||
|
||||
try:
|
||||
reader.close()
|
||||
|
||||
# Initialize tracer
|
||||
rank = kwargs.get("rank", 0)
|
||||
maybe_init_worker_tracer(
|
||||
instrumenting_module_name="vllm.worker",
|
||||
process_kind="worker",
|
||||
process_name=f"Worker_{rank}",
|
||||
)
|
||||
|
||||
worker = WorkerProc(*args, **kwargs)
|
||||
assert worker.worker_response_mq is not None
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import torch.nn as nn
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.model_loader import get_model
|
||||
from vllm.tracing import instrument
|
||||
from vllm.v1.utils import CpuGpuBuffer
|
||||
from vllm.v1.worker.gpu_model_runner import GPUModelRunner
|
||||
|
||||
@@ -51,6 +52,7 @@ class CPUModelRunner(GPUModelRunner):
|
||||
if isinstance(v, CpuGpuBuffer):
|
||||
v.gpu = v.cpu
|
||||
|
||||
@instrument(span_name="Loading (CPU)")
|
||||
def load_model(self, eep_scale_up: bool = False) -> None:
|
||||
logger.info("Starting to load model %s...", self.model_config.model)
|
||||
self.model = get_model(vllm_config=self.vllm_config)
|
||||
@@ -61,6 +63,7 @@ class CPUModelRunner(GPUModelRunner):
|
||||
def get_model(self) -> nn.Module:
|
||||
return self.model
|
||||
|
||||
@instrument(span_name="Warmup (CPU)")
|
||||
def warming_up_model(self) -> None:
|
||||
logger.info("Warming up model for the compilation...")
|
||||
# Only generate graph for the generic shape
|
||||
|
||||
@@ -93,6 +93,7 @@ from vllm.pooling_params import PoolingParams
|
||||
from vllm.sampling_params import SamplingType
|
||||
from vllm.sequence import IntermediateTensors
|
||||
from vllm.tasks import GenerationTask, PoolingTask, SupportedTask
|
||||
from vllm.tracing import instrument
|
||||
from vllm.utils import length_from_prompt_token_ids_or_embeds
|
||||
from vllm.utils.jsontree import json_map_leaves
|
||||
from vllm.utils.math_utils import cdiv, round_up
|
||||
@@ -4111,6 +4112,7 @@ class GPUModelRunner(
|
||||
new_config = update_config(config, config_overrides)
|
||||
setattr(self, config_name, new_config)
|
||||
|
||||
@instrument(span_name="Loading (GPU)")
|
||||
def load_model(self, eep_scale_up: bool = False) -> None:
|
||||
"""
|
||||
Args:
|
||||
@@ -5165,6 +5167,7 @@ class GPUModelRunner(
|
||||
self.encoder_cache.clear()
|
||||
gc.collect()
|
||||
|
||||
@instrument(span_name="Capture model")
|
||||
def capture_model(self) -> int:
|
||||
if self.compilation_config.cudagraph_mode == CUDAGraphMode.NONE:
|
||||
logger.warning(
|
||||
|
||||
@@ -42,6 +42,7 @@ from vllm.platforms import current_platform
|
||||
from vllm.profiler.wrapper import CudaProfilerWrapper, TorchProfilerWrapper
|
||||
from vllm.sequence import IntermediateTensors
|
||||
from vllm.tasks import SupportedTask
|
||||
from vllm.tracing import instrument
|
||||
from vllm.utils.mem_utils import MemorySnapshot, format_gib, memory_profiling
|
||||
from vllm.utils.torch_utils import set_random_seed
|
||||
from vllm.v1.core.sched.output import GrammarOutput, SchedulerOutput
|
||||
@@ -186,6 +187,7 @@ class Worker(WorkerBase):
|
||||
self.cache_config.num_gpu_blocks = num_gpu_blocks
|
||||
self.cache_config.num_cpu_blocks = num_cpu_blocks
|
||||
|
||||
@instrument(span_name="Init device")
|
||||
def init_device(self):
|
||||
if self.device_config.device_type == "cuda":
|
||||
# This env var set by Ray causes exceptions with graph building.
|
||||
@@ -407,6 +409,7 @@ class Worker(WorkerBase):
|
||||
self.model_runner.update_max_model_len(max_model_len)
|
||||
logger.debug("Updated max_model_len to %d", max_model_len)
|
||||
|
||||
@instrument(span_name="Allocate KV cache")
|
||||
def initialize_from_config(self, kv_cache_config: KVCacheConfig) -> None:
|
||||
"""Allocate GPU KV cache with the specified kv_cache_config."""
|
||||
|
||||
@@ -426,6 +429,7 @@ class Worker(WorkerBase):
|
||||
else:
|
||||
self.model_runner.initialize_kv_cache(kv_cache_config)
|
||||
|
||||
@instrument(span_name="Warmup (GPU)")
|
||||
def compile_or_warm_up_model(self) -> None:
|
||||
warmup_sizes = []
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ from vllm.config import VllmConfig, set_current_vllm_config
|
||||
from vllm.logger import init_logger
|
||||
from vllm.lora.request import LoRARequest
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
from vllm.tracing import instrument
|
||||
from vllm.utils.import_utils import resolve_obj_by_qualname
|
||||
from vllm.utils.system_utils import update_environment_variables
|
||||
from vllm.v1.kv_cache_interface import KVCacheSpec
|
||||
@@ -222,6 +223,7 @@ class WorkerWrapperBase:
|
||||
envs = envs_list[self.rpc_rank]
|
||||
update_environment_variables(envs)
|
||||
|
||||
@instrument(span_name="Worker init")
|
||||
def init_worker(self, all_kwargs: list[dict[str, Any]]) -> None:
|
||||
"""
|
||||
Here we inject some common logic before initializing the worker.
|
||||
|
||||
Reference in New Issue
Block a user