|
36 | 36 | def _trace_requests_enabled() -> bool: |
37 | 37 | return os.getenv("QWEN_ASR_TRACE_REQUESTS", "0").strip().lower() in {"1", "true", "yes", "y"} |
38 | 38 |
|
| 39 | + |
| 40 | +def _resolve_stop_token_ids(processor: Any) -> List[int]: |
| 41 | + tokenizer = getattr(processor, "tokenizer", None) |
| 42 | + if tokenizer is None: |
| 43 | + return [] |
| 44 | + |
| 45 | + token_ids: List[int] = [] |
| 46 | + for token in ("<|im_end|>", "<|endoftext|>"): |
| 47 | + try: |
| 48 | + token_id = tokenizer.convert_tokens_to_ids(token) |
| 49 | + except Exception: |
| 50 | + continue |
| 51 | + if isinstance(token_id, int) and token_id >= 0 and token_id not in token_ids: |
| 52 | + token_ids.append(token_id) |
| 53 | + |
| 54 | + eos_token_id = getattr(tokenizer, "eos_token_id", None) |
| 55 | + if isinstance(eos_token_id, int) and eos_token_id >= 0 and eos_token_id not in token_ids: |
| 56 | + token_ids.append(eos_token_id) |
| 57 | + |
| 58 | + pad_token_id = getattr(tokenizer, "pad_token_id", None) |
| 59 | + if isinstance(pad_token_id, int) and pad_token_id >= 0 and pad_token_id not in token_ids: |
| 60 | + token_ids.append(pad_token_id) |
| 61 | + |
| 62 | + return token_ids |
| 63 | + |
| 64 | + |
39 | 65 | from .qwen3_forced_aligner import Qwen3ForcedAligner |
40 | 66 | from .utils import ( |
41 | 67 | MAX_ASR_INPUT_SECONDS, |
@@ -291,7 +317,12 @@ def LLM( |
291 | 317 | # ASR/translation must remain deterministic: preserve the upstream |
292 | 318 | # explicit zero-temperature sampling instead of falling back to model |
293 | 319 | # generation config defaults. |
294 | | - sampling_params = SamplingParams(temperature=0.0, max_tokens=max_new_tokens) |
| 320 | + stop_token_ids = _resolve_stop_token_ids(processor) |
| 321 | + sampling_kwargs: Dict[str, Any] = {"temperature": 0.0, "max_tokens": max_new_tokens} |
| 322 | + if stop_token_ids: |
| 323 | + sampling_kwargs["stop_token_ids"] = stop_token_ids |
| 324 | + log_startup(f"vLLM stop_token_ids: {stop_token_ids}") |
| 325 | + sampling_params = SamplingParams(**sampling_kwargs) |
295 | 326 |
|
296 | 327 | forced_aligner_model = None |
297 | 328 | if forced_aligner is not None: |
@@ -333,7 +364,14 @@ def warm_up(self, *, max_new_tokens: int = 1) -> None: |
333 | 364 |
|
334 | 365 | sampling_cls = type(original_sampling_params) |
335 | 366 | try: |
336 | | - self.sampling_params = sampling_cls(temperature=0.0, max_tokens=max(1, int(max_new_tokens))) |
| 367 | + sampling_kwargs: Dict[str, Any] = { |
| 368 | + "temperature": 0.0, |
| 369 | + "max_tokens": max(1, int(max_new_tokens)), |
| 370 | + } |
| 371 | + stop_token_ids = getattr(original_sampling_params, "stop_token_ids", None) |
| 372 | + if stop_token_ids: |
| 373 | + sampling_kwargs["stop_token_ids"] = list(stop_token_ids) |
| 374 | + self.sampling_params = sampling_cls(**sampling_kwargs) |
337 | 375 | silence = np.zeros((SAMPLE_RATE // 2,), dtype=np.float32) |
338 | 376 | self.transcribe(audio=(silence, SAMPLE_RATE), language="English", return_time_stamps=False) |
339 | 377 | finally: |
|
0 commit comments