A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 6, 23:00 UTC
FunASR model bugfix (#36633)
Signed-off-by: zixiao <shunli.dsl@alibaba-inc.com> Co-authored-by: zixiao <shunli.dsl@alibaba-inc.com>
AllenDou committed
Mar 10, 2026 at 23:14 UTC
aefc59f088665b23c0285c7f77c32b365efaa5dc
2 files changed
+31
-50
vllm/model_executor/models/funasr.py
+2
@@ -573,6 +573,8 @@ class Transformer(nn.Module):
573
)
574
575
def forward(self, hidden_states: torch.Tensor, ilens: int = 0):
576
+ max_len = max(ilens)
577
+ hidden_states = hidden_states[:, :max_len, :]
578
batch_size, seq_len, dim = hidden_states.size()
579
chunk_num = (seq_len - 1) // self.k + 1
580
pad_num = chunk_num * self.k - seq_len
vllm/transformers_utils/processors/funasr.py
+29
-50
@@ -268,6 +268,7 @@ class FunASRFeatureExtractor(SequenceFeatureExtractor):
268
n_fft=400,
269
padding_value=0.0,
270
dither=0.0,
271
+ max_length=1000,
272
return_attention_mask=False,
273
**kwargs,
274
):
@@ -279,6 +280,7 @@ class FunASRFeatureExtractor(SequenceFeatureExtractor):
280
**kwargs,
281
)
282
self.frontend_conf = kwargs.get("frontend_conf", {})
283
+ self.max_length = max_length
284
self.n_fft = n_fft
285
self.hop_length = hop_length
286
self.chunk_length = chunk_length
@@ -329,64 +331,41 @@ class FunASRFeatureExtractor(SequenceFeatureExtractor):
331
return_token_timestamps: bool | None = None,
332
**kwargs,
333
) -> BatchFeature:
332
- is_batched = isinstance(raw_speech, (list, tuple)) and (
333
- isinstance(raw_speech[0], (np.ndarray, tuple, list))
334
- )
335
-
336
- if is_batched:
337
- raw_speech = [
338
- np.asarray([speech], dtype=np.float32).T for speech in raw_speech
339
- ]
340
- elif not is_batched and not isinstance(raw_speech, np.ndarray):
341
- raw_speech = np.asarray(raw_speech, dtype=np.float32)
342
- elif isinstance(raw_speech, np.ndarray) and raw_speech.dtype is np.dtype(
343
- np.float64
344
- ):
345
- raw_speech = raw_speech.astype(np.float32)
346
-
347
- if not is_batched:
348
- raw_speech = [np.asarray([raw_speech]).T]
349
-
350
- batched_speech = BatchFeature({"input_features": raw_speech})
334
+ frontend = WavFrontend(**self.frontend_conf, dither=self.dither)
335
352
- padded_inputs = self.pad(
353
- batched_speech,
336
+ feats = []
337
+ speech_lengths = []
338
+ fake_token_lengths = []
339
+ for speech in raw_speech:
340
+ feature, length = self.extract_fbank(
341
+ speech,
342
+ data_type=kwargs.get("data_type", "sound"),
343
+ frontend=frontend,
344
+ is_final=True,
345
+ )
346
+ feats.append(feature)
347
+ speech_lengths.append(length)
348
+ olens = 1 + (length - 3 + 2 * 1) // 2
349
+ olens = 1 + (olens - 3 + 2 * 1) // 2
350
+ fake_token_len = (olens - 1) // 2 + 1
351
+ fake_token_len = torch.clamp(fake_token_len, min=1)
352
+ fake_token_lengths.append(fake_token_len)
353
+
354
+ feats = torch.concat(feats, dim=0)
355
+ batched_speech = self.pad(
356
+ BatchFeature({"input_features": feats}),
357
padding=padding,
355
- max_length=max_length if max_length else self.n_samples,
358
+ max_length=max_length if max_length else self.max_length,
359
truncation=truncation,
360
pad_to_multiple_of=pad_to_multiple_of,
361
return_attention_mask=return_attention_mask or do_normalize,
362
)
360
-
361
- input_features = padded_inputs.get("input_features").transpose(2, 0, 1)
362
-
363
- frontend = WavFrontend(**self.frontend_conf, dither=self.dither)
364
- input_features, speech_lengths = self.extract_fbank(
365
- input_features[0],
366
- data_type=kwargs.get("data_type", "sound"),
367
- frontend=frontend,
368
- is_final=True,
369
- )
370
- olens = 1 + (speech_lengths - 3 + 2 * 1) // 2
371
- olens = 1 + (olens - 3 + 2 * 1) // 2
372
- fake_token_lengths = (olens - 1) // 2 + 1
373
- if isinstance(input_features[0], list):
374
- padded_inputs["input_features"] = [
375
- np.asarray(feature, dtype=np.float32) for feature in input_features
376
- ]
377
-
378
- else:
379
- padded_inputs["input_features"] = input_features
380
-
363
if return_tensors is not None:
382
- padded_inputs = padded_inputs.convert_to_tensors(return_tensors)
383
-
384
- fake_token_lengths = torch.clamp(fake_token_lengths, min=1)
385
-
386
- padded_inputs["speech_lengths"] = speech_lengths
387
- padded_inputs["fake_token_lengths"] = fake_token_lengths
364
+ batched_speech = batched_speech.convert_to_tensors(return_tensors)
365
389
- return padded_inputs
366
+ batched_speech["speech_lengths"] = torch.tensor(speech_lengths)
367
+ batched_speech["fake_token_lengths"] = torch.concat(fake_token_lengths)
368
+ return batched_speech
369
370
371
class FunASRProcessor(ProcessorMixin):