Files
wehub-resource-sync 94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:38:16 +08:00

163 lines
5.7 KiB
Python

from __future__ import annotations
from abc import ABC, abstractmethod
from typing import List, Optional
from sglang.srt.entrypoints.openai.protocol import (
TranscriptionRequest,
TranscriptionUsage,
TranscriptionVerboseResponse,
)
class TranscriptionAdapter(ABC):
"""Abstract base for model-specific transcription logic.
Subclass this and decorate with ``@register_transcription_adapter("Key")``
to add support for a new ASR model. See the sibling modules for
the built-in Whisper and Qwen3-ASR implementations.
"""
@abstractmethod
def build_sampling_params(self, request: TranscriptionRequest) -> dict:
"""Return the ``sampling_params`` dict for ``GenerateReqInput``."""
@property
def supports_language_detection(self) -> bool:
"""Whether this model supports automatic language detection.
When True, the adapter must implement the fused autodetect methods
and the standalone detection methods below.
"""
return False
# -- Fused detect+transcribe (used by the server) ----------------------
def build_fused_autodetect_params(self, request) -> dict:
"""Return ``sampling_params`` dict for a fused detect+transcribe request.
Uses structured generation (``regex``) to constrain the output prefix
to a valid language + task token sequence while allowing free
transcription afterwards — all in a single request.
"""
raise NotImplementedError
@staticmethod
def parse_fused_output(
text: str, *, ts_variant: bool = False
) -> tuple[Optional[str], Optional[str]]:
"""Parse the fused output into ``(language_code, user_visible_text)``.
Called by both streaming and non-streaming handlers with the same
contract. ``ts_variant`` indicates which forced-prefix shape was
requested (the caller knows from ``request.timestamp_granularities``);
adapters use it to disambiguate variants whose detokenized prefix
differs in shape from their token-id prefix.
* ``(None, None)`` — the forced prefix is not yet locatable.
Streaming callers keep buffering; non-streaming / end-of-stream
callers treat this as a parse failure and fall back to
``strip_special_tokens`` on the raw text.
* ``(lang, visible)`` — prefix parsed. ``visible`` is fully
user-visible (prefix removed, embedded special tokens scrubbed).
It must grow monotonically across cumulative streaming snapshots
so callers can compute deltas against it directly.
"""
raise NotImplementedError
@staticmethod
def strip_special_tokens(text: str) -> str:
"""Best-effort scrub of model-specific special-token strings.
Used as a fallback when ``parse_fused_output`` reports a parse
failure (e.g. FSM abort). Default is an identity pass-through;
adapters that request generation with ``skip_special_tokens=False``
should override to strip their special-token syntax.
"""
return text
@property
def supports_chunked_streaming(self) -> bool:
"""Whether this model uses chunk-based streaming instead of token-level streaming."""
return False
@property
def model_sample_rate(self) -> int:
"""Target sample rate in Hz the model expects. Realtime WS path
resamples client PCM to this rate before chunking. Default 16000
matches Whisper / Qwen3-ASR; override for models expecting other rates.
"""
return 16000
@property
def prompt_template(self) -> str:
"""Prompt template for chunked streaming requests.
Only used when ``supports_chunked_streaming`` is True.
The default returns an empty string.
"""
return ""
@property
def chunked_streaming_config(self) -> dict:
"""Parameters for ``StreamingASRState`` when using chunked streaming.
Only used when ``supports_chunked_streaming`` is True.
Keys: ``chunk_size_sec``, ``unfixed_chunk_num``, ``unfixed_token_num``.
"""
return {}
def postprocess_text(self, text: str) -> str:
"""Strip model-specific markers from raw decoded text.
The default implementation is a no-op pass-through.
"""
return text
@abstractmethod
def build_verbose_response(
self,
request: TranscriptionRequest,
text: str,
ret: dict,
tokenizer,
usage: TranscriptionUsage,
) -> TranscriptionVerboseResponse:
"""Build a ``verbose_json`` response with segments / timestamps."""
_ADAPTER_REGISTRY: dict[str, type[TranscriptionAdapter]] = {}
_DEFAULT_ADAPTER_KEY = "Whisper"
def register_transcription_adapter(
key: str,
) -> callable:
"""Class decorator that registers a ``TranscriptionAdapter`` subclass.
*key* is matched as a substring against the model's HF ``architectures``
list at init time (e.g. ``"Whisper"`` matches
``"WhisperForConditionalGeneration"``).
"""
def decorator(cls: type[TranscriptionAdapter]) -> type[TranscriptionAdapter]:
_ADAPTER_REGISTRY[key] = cls
return cls
return decorator
def resolve_adapter(architectures: List[str]) -> TranscriptionAdapter:
"""Pick the right adapter by matching architecture names against the registry."""
for arch in architectures or []:
for key, adapter_cls in _ADAPTER_REGISTRY.items():
if key in arch:
return adapter_cls()
default_cls = _ADAPTER_REGISTRY.get(_DEFAULT_ADAPTER_KEY)
if default_cls is None:
raise RuntimeError(
"No transcription adapters registered. "
"Make sure 'transcription_adapters' package is importable."
)
return default_cls()