Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
fix(runtime): release Torch hotword and timestamp fixes as 0.1.7
zhifu gaob84e76443d66
diff --git a/.github/workflows/test-funasr-torch-package.yml b/.github/workflows/test-funasr-torch-package.ymlindex 2287de3b7..262ea3306 100644--- a/.github/workflows/test-funasr-torch-package.yml+++ b/.github/workflows/test-funasr-torch-package.yml@@ -5,12 +5,14 @@ on:paths:- "runtime/python/libtorch/**"- "tests/test_funasr_torch_package.py"+ - "tests/test_funasr_torch_installed.py"- ".github/workflows/test-funasr-torch-package.yml"push:branches: [main]paths:- "runtime/python/libtorch/**"- "tests/test_funasr_torch_package.py"+ - "tests/test_funasr_torch_installed.py"- ".github/workflows/test-funasr-torch-package.yml"permissions:@@ -62,6 +64,13 @@ jobs:assert importlib.util.find_spec("torch_quant") is Noneprint("Installed Torch runtime imports passed without ONNX Runtime or torch-quant")PY+ - name: Exercise installed wheel and sdist regressions+ run: |+ python -m pip install --no-index --no-deps --no-build-isolation --target "$RUNNER_TEMP/torch-runtime-sdist" dist/torch-runtime/*.tar.gz+ cp tests/test_funasr_torch_installed.py "$RUNNER_TEMP/test_funasr_torch_installed.py"+ cd "$RUNNER_TEMP"+ PYTHONPATH="$RUNNER_TEMP/torch-runtime-installed" python -m pytest -q test_funasr_torch_installed.py --junitxml="$GITHUB_WORKSPACE/torch-installed-wheel.xml"+ PYTHONPATH="$RUNNER_TEMP/torch-runtime-sdist" python -m pytest -q test_funasr_torch_installed.py --junitxml="$GITHUB_WORKSPACE/torch-installed-sdist.xml"- uses: actions/upload-artifact@v4if: always()with:@@ -70,4 +79,6 @@ jobs:source-commit.txtresolved-dependencies.txttorch-package-results.xml+ torch-installed-wheel.xml+ torch-installed-sdist.xmldist/torch-runtime/*diff --git a/runtime/python/libtorch/README.md b/runtime/python/libtorch/README.mdindex 00808b6ba..90de30e85 100644--- a/runtime/python/libtorch/README.md+++ b/runtime/python/libtorch/README.md@@ -1,5 +1,23 @@# Libtorch-python+## Version 0.1.7++This standalone Torch runtime release includes the already-merged fixes for+mixed-length Paraformer timestamp batches, long/empty contextual hotwords,+terminal abbreviations and rich-transcription word boundaries. Contextual and+Seaco hotwords keep their first ten characters, matching the exported embedding+width; empty whitespace entries are omitted. These limits are not configurable+recognition-quality guarantees.++Install `funasr-torch==0.1.7` in a dedicated environment. The root `funasr`+distribution and `funasr-onnx` have separate versions and do not replace this+package. Python WebSocket server-script changes are also separate.++Wheel and source-distribution installation regressions exercise native wrapper+and postprocessing behavior with synthetic acoustic outputs. Exact runtime+source is bound to previously accepted real CUDA fixture tests; this release+does not claim new pretrained ASR accuracy, performance or a full model suite.+## Export the model### Install [modelscope and funasr](https://github.com/modelscope/FunASR#installation)diff --git a/runtime/python/libtorch/setup.py b/runtime/python/libtorch/setup.pyindex be4b7e3c5..57aaa11d6 100644--- a/runtime/python/libtorch/setup.py+++ b/runtime/python/libtorch/setup.py@@ -15,7 +15,7 @@ def get_readme():setuptools.setup(name="funasr_torch",- version="0.1.6",+ version="0.1.7",platforms="Any",url="https://github.com/modelscope/FunASR.git",author="Speech Lab of DAMO Academy, Alibaba Group",diff --git a/tests/test_funasr_torch_installed.py b/tests/test_funasr_torch_installed.pynew file mode 100644index 000000000..43c0ea725--- /dev/null+++ b/tests/test_funasr_torch_installed.py@@ -0,0 +1,83 @@+"""Exercise the installed standalone package, not a source-directory import."""+import importlib.metadata+import importlib.util+from pathlib import Path+from types import SimpleNamespace+import unittest++if importlib.util.find_spec("funasr_torch") is None:+ raise unittest.SkipTest("Install the standalone funasr-torch distribution first.")++import funasr_torch+import numpy as np+import torch+from funasr_torch.paraformer_bin import ContextualParaformer, SeacoParaformer+from funasr_torch.utils.postprocess_utils import abbr_dispose, rich_transcription_postprocess+++class InstalledTorchPackageTest(unittest.TestCase):+ def test_hotwords_are_bounded_and_empty_words_are_removed(self):+ for cls in (ContextualParaformer, SeacoParaformer):+ with self.subTest(wrapper=cls.__name__):+ model = cls.__new__(cls)+ model.vocab = {"a": 3, "b": 4}+ matrix, positions = model.proc_hotword(" ab abababababab ")+ self.assertEqual(matrix.tolist(), [+ [3, 4, 0, 0, 0, 0, 0, 0, 0, 0],+ [3, 4, 3, 4, 3, 4, 3, 4, 3, 4],+ [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],+ ])+ self.assertEqual(positions.tolist(), [1, 9, 0])+ for value in ("", " \t\n"):+ matrix, positions = model.proc_hotword(value)+ self.assertEqual(matrix.tolist(), [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0]])+ self.assertEqual(positions.tolist(), [0])++ def test_batched_timestamps_ignore_padding(self):+ model = funasr_torch.Paraformer.__new__(funasr_torch.Paraformer)+ model.batch_size = 2+ model.device_id = -1+ model.device = torch.device("cpu")+ model.plot_timestamp_to = ""+ model.frontend = SimpleNamespace(opts=SimpleNamespace(+ frame_opts=SimpleNamespace(samp_freq=16000)))+ model.load_data = lambda values, fs: values+ model.extract_feat = lambda lengths: (+ torch.zeros((len(lengths), max(lengths), 4)), torch.tensor(lengths))+ model.decode = lambda scores, lens: [["\u4f60", "\u597d"] for _ in range(len(lens))]++ # Only acoustic outputs are synthetic; installed timestamp and batching+ # code must keep the shorter recording independent of padded frames.+ def infer(feats, lengths):+ peaks = torch.zeros((len(lengths), feats.shape[1] * 3))+ for row, length in enumerate(lengths.tolist()):+ positions = np.linspace(5, length * 3 - 6, 3).round().astype(int)+ peaks[row, positions] = 1+ return torch.zeros((len(lengths), 2, 4)), torch.full((len(lengths),), 2), torch.zeros_like(peaks), peaks++ model.ort_infer = infer+ single = [model([length])[0] for length in (17, 50)]+ self.assertEqual([row["timestamp"] for row in single], [+ [[70, 470], [470, 945]], [[70, 670], [1450, 2925]],+ ])+ self.assertEqual(model([17, 50]), single)++ def test_terminal_abbreviation_retains_text_and_timestamps(self):+ self.assertEqual(abbr_dispose(["a", " ", "b"]), ["AB"])+ self.assertEqual(abbr_dispose(["a", " ", "b"], [[0, 100], [100, 200]]),+ (["AB"], [[0, 200]]))+ self.assertEqual(abbr_dispose(["a", " ", "b", " ", "c"]), ["ABC"])++ def test_rich_transcription_keeps_word_boundaries(self):+ self.assertEqual(rich_transcription_postprocess("<|en|>hello<|en|>world"), "hello world")+ self.assertEqual(rich_transcription_postprocess("<|zh|>\u4f60<|zh|>\u597d"), "\u4f60\u597d")++ def test_installed_version_and_origin(self):+ distribution = importlib.metadata.distribution("funasr-torch")+ self.assertEqual(distribution.version, "0.1.7")+ self.assertEqual(Path(funasr_torch.__file__).resolve().parent,+ Path(distribution.locate_file("funasr_torch")).resolve())+++if __name__ == "__main__":+ unittest.main()diff --git a/tests/test_funasr_torch_package.py b/tests/test_funasr_torch_package.pyindex 04cdcf01f..9008dc97f 100644--- a/tests/test_funasr_torch_package.py+++ b/tests/test_funasr_torch_package.py@@ -119,12 +119,12 @@ def test_torch_package_does_not_require_unrelated_runtime_engines(distributions)}assert not names & {"torch-quant", "onnxruntime", "onnxruntime-gpu"}-def test_distribution_version_includes_cmvn_parser_fix(distributions):+def test_distribution_version_includes_hotword_and_timestamp_fixes(distributions):from packaging.version import Versionwheel, sdist = distributionsversion = metadata(wheel)["Version"]- assert Version(version) >= Version("0.1.6")+ assert Version(version) >= Version("0.1.7")with tarfile.open(sdist, "r:gz") as archive:member = next(item for item in archive.getmembers()if item.name.count("/") == 1 and item.name.endswith("/PKG-INFO"))