[Refactor] Centralize metrics related helpers to metrics/ (#5168)
This commit is contained in:
1 parent
e9a06d5bdc
commit
778959797c
9 files changed
+480
-259
No files matched your search
@@ -104,37 +104,6 @@ def _build_terminal_empty_output(
|
||||
)
|
||||
|
||||
|
||||
def _coerce_int_scalar(value: Any) -> int:
|
||||
if value is None:
|
||||
return 0
|
||||
if isinstance(value, (list, tuple)):
|
||||
for item in value:
|
||||
coerced = _coerce_int_scalar(item)
|
||||
if coerced > 0:
|
||||
return coerced
|
||||
return 0
|
||||
if hasattr(value, "item"):
|
||||
value = value.item()
|
||||
try:
|
||||
coerced = int(value)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
return coerced if coerced > 0 else 0
|
||||
|
||||
|
||||
def _infer_stage_audio_sample_rate(stage_pool: StagePool, default: int = 24000) -> int:
|
||||
"""Infer the final audio stage sample rate from stage metadata when possible."""
|
||||
sample_rate_attrs = ("audio_sample_rate", "sample_rate", "sampling_rate", "output_sample_rate", "sr")
|
||||
stage_client = getattr(stage_pool, "stage_client", None)
|
||||
stage_config = getattr(stage_pool, "_stage_vllm_config", None)
|
||||
for source in (stage_client, stage_config):
|
||||
for attr in sample_rate_attrs:
|
||||
sample_rate = _coerce_int_scalar(getattr(source, attr, None))
|
||||
if sample_rate > 0:
|
||||
return sample_rate
|
||||
return default
|
||||
|
||||
|
||||
def build_engine_core_request_from_tokens(
|
||||
request_id: str,
|
||||
prompt: dict[str, Any],
|
||||
@@ -1909,7 +1878,7 @@ class Orchestrator:
|
||||
terminal_output = _build_terminal_empty_output(
|
||||
req_id,
|
||||
final_output_type=final_output_type,
|
||||
audio_sample_rate=_infer_stage_audio_sample_rate(final_pool),
|
||||
audio_sample_rate=final_pool._infer_audio_sample_rate(),
|
||||
)
|
||||
submit_ts = _time.time()
|
||||
req_state.stage_submit_ts[final_stage_id] = submit_ts
|
||||
|
||||
Reference in new issue
Block a user