MCPcopy Create free account
hub / github.com/modelscope/FunASR / inference

Method inference

funasr/auto/auto_model.py:496–596  ·  view source on GitHub ↗

Run model inference on input data (internal method). Handles batching, timing, and progress reporting. Called by generate() and inference_with_vad(). Typically not called directly by users. Args: input: Audio data, file path, or text (for punc model).

(
        self,
        input,
        input_len=None,
        model=None,
        kwargs=None,
        key=None,
        progress_callback=None,
        **cfg,
    )

Source from the content-addressed store, hash-verified

494 )
495
496 def inference(
497 self,
498 input,
499 input_len=None,
500 model=None,
501 kwargs=None,
502 key=None,
503 progress_callback=None,
504 **cfg,
505 ):
506 """Run model inference on input data (internal method).
507
508 Handles batching, timing, and progress reporting. Called by generate()
509 and inference_with_vad(). Typically not called directly by users.
510
511 Args:
512 input: Audio data, file path, or text (for punc model).
513 input_len (tensor, optional): Input lengths for batch.
514 model (nn.Module, optional): Override model (used for VAD/PUNC/SPK sub-models).
515 kwargs (dict, optional): Override kwargs (used for sub-model configs).
516 key (list, optional): Sample identifiers.
517 progress_callback (callable, optional): Progress reporting function.
518 **cfg: Additional config merged into kwargs.
519
520 Returns:
521 list[dict]: Model inference results.
522 """
523 if kwargs is None:
524 self._reset_runtime_configs()
525 kwargs = self.kwargs if kwargs is None else kwargs
526 if "cache" in kwargs:
527 kwargs.pop("cache")
528 deep_update(kwargs, cfg)
529 model = self.model if model is None else model
530
531 batch_size = kwargs.get("batch_size", 1)
532 # if kwargs.get("device", "cpu") == "cpu":
533 # batch_size = 1
534
535 key_list, data_list = prepare_data_iterator(
536 input, input_len=input_len, data_type=kwargs.get("data_type", None), key=key
537 )
538
539 speed_stats = {}
540 asr_result_list = []
541 num_samples = len(data_list)
542 disable_pbar = self.kwargs.get("disable_pbar", False)
543 pbar = (
544 tqdm(colour="blue", total=num_samples, dynamic_ncols=True) if not disable_pbar else None
545 )
546 time_speech_total = 0.0
547 time_escape_total = 0.0
548 for beg_idx in range(0, num_samples, batch_size):
549 end_idx = min(num_samples, beg_idx + batch_size)
550 data_batch = data_list[beg_idx:end_idx]
551 key_batch = key_list[beg_idx:end_idx]
552 batch = {"data_in": data_batch, "key": key_batch}
553

Callers 2

generateMethod · 0.95
inference_with_vadMethod · 0.95

Calls 7

deep_updateFunction · 0.90
prepare_data_iteratorFunction · 0.85
errorMethod · 0.80
parametersMethod · 0.80
deviceMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected