-
Notifications
You must be signed in to change notification settings - Fork 2k
Release funasr-onnx 0.4.2 without Torch runtime dependency #3242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| name: Validate funasr-onnx package | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - ".github/workflows/test-funasr-onnx-package.yml" | ||
| - "runtime/python/onnxruntime/**" | ||
| - "tests/test_funasr_onnx_release.py" | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - ".github/workflows/test-funasr-onnx-package.yml" | ||
| - "runtime/python/onnxruntime/**" | ||
| - "tests/test_funasr_onnx_release.py" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| package-smoke: | ||
| name: Python ${{ matrix.python-version }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| python-version: | ||
| - "3.11" | ||
| - "3.12" | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v7 | ||
|
|
||
| - uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| cache: pip | ||
|
|
||
| - name: Install build tooling | ||
| run: python -m pip install --upgrade pip build twine | ||
|
|
||
| - name: Check release contract | ||
| run: python tests/test_funasr_onnx_release.py | ||
|
|
||
| - name: Build wheel and source distribution | ||
| run: python -m build runtime/python/onnxruntime --outdir dist/funasr-onnx | ||
|
|
||
| - name: Check distribution metadata | ||
| run: python -m twine check dist/funasr-onnx/* | ||
|
|
||
| - name: Install built wheel | ||
| run: python -m pip install --force-reinstall dist/funasr-onnx/*.whl | ||
|
|
||
| - name: Verify clean ONNX install | ||
| run: | | ||
| python -m pip check | ||
| python - <<'PY' | ||
| import importlib.util | ||
| from importlib.metadata import requires, version | ||
|
|
||
| assert version("funasr-onnx") == "0.4.2" | ||
| assert importlib.util.find_spec("torch") is None | ||
|
|
||
| requirements = requires("funasr-onnx") or [] | ||
| normalized = {item.lower().replace("_", "-") for item in requirements} | ||
| assert any(item.startswith("jieba") for item in normalized) | ||
| assert not any(item.startswith("torch") for item in normalized) | ||
|
|
||
| from funasr_onnx import CT_Transformer, Fsmn_vad, Paraformer, SenseVoiceSmall | ||
|
|
||
| assert all( | ||
| entrypoint is not None | ||
| for entrypoint in (Paraformer, Fsmn_vad, CT_Transformer, SenseVoiceSmall) | ||
| ) | ||
| PY | ||
|
|
||
| - name: Upload release candidate | ||
| if: matrix.python-version == '3.12' | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: funasr-onnx-0.4.2 | ||
| path: dist/funasr-onnx/* | ||
| if-no-files-found: error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import ast | ||
| from pathlib import Path | ||
| import re | ||
| import unittest | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
| PACKAGE_ROOT = ROOT / "runtime" / "python" / "onnxruntime" | ||
| SETUP_PATH = PACKAGE_ROOT / "setup.py" | ||
| EXPECTED_VERSION = "0.4.2" | ||
| REQUIREMENT_NAME_PATTERN = re.compile(r"^\s*([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)") | ||
|
|
||
|
|
||
| def read_setup_tree(): | ||
| return ast.parse(SETUP_PATH.read_text(encoding="utf-8"), filename=str(SETUP_PATH)) | ||
|
|
||
|
|
||
| def assigned_literal(tree, name): | ||
| for node in tree.body: | ||
| if not isinstance(node, ast.Assign): | ||
| continue | ||
| if any(isinstance(target, ast.Name) and target.id == name for target in node.targets): | ||
| return ast.literal_eval(node.value) | ||
| raise AssertionError(f"{name} is not assigned in {SETUP_PATH}") | ||
|
|
||
|
|
||
| def setup_keyword_literal(tree, name): | ||
| for node in ast.walk(tree): | ||
| if not isinstance(node, ast.Call): | ||
| continue | ||
| if not isinstance(node.func, ast.Attribute) or node.func.attr != "setup": | ||
| continue | ||
| for keyword in node.keywords: | ||
| if keyword.arg == name: | ||
| return ast.literal_eval(keyword.value) | ||
| raise AssertionError(f"setuptools.setup() has no {name!r} keyword") | ||
|
|
||
|
|
||
| def normalized_requirement_name(requirement): | ||
| match = REQUIREMENT_NAME_PATTERN.match(requirement) | ||
| if match is None: | ||
| raise AssertionError(f"Unable to parse requirement name from {requirement!r}") | ||
| return re.sub(r"[-_.]+", "-", match.group(1)).lower() | ||
|
|
||
|
|
||
| class FunASROnnxReleaseContractTest(unittest.TestCase): | ||
| def test_release_version_is_0_4_2(self): | ||
| self.assertEqual(assigned_literal(read_setup_tree(), "VERSION_NUM"), EXPECTED_VERSION) | ||
|
|
||
| def test_runtime_dependencies_keep_onnx_install_torch_free(self): | ||
| requirements = setup_keyword_literal(read_setup_tree(), "install_requires") | ||
| names = {normalized_requirement_name(requirement) for requirement in requirements} | ||
| self.assertIn("jieba", names) | ||
| self.assertNotIn("torch", names) | ||
|
|
||
| def test_requirement_name_parser_handles_pep508_forms(self): | ||
| cases = { | ||
| "torch!=2.0": "torch", | ||
| "Torch_CUDA~=2.0": "torch-cuda", | ||
| 'torch[distributed]>=2.0; python_version >= "3.11"': "torch", | ||
| "torch @ https://example.invalid/torch.whl": "torch", | ||
| } | ||
| for requirement, expected in cases.items(): | ||
| with self.subTest(requirement=requirement): | ||
| self.assertEqual(normalized_requirement_name(requirement), expected) | ||
|
|
||
| def test_package_source_has_no_torch_imports(self): | ||
| offenders = [] | ||
| package_dir = PACKAGE_ROOT / "funasr_onnx" | ||
| for source_path in sorted(package_dir.rglob("*.py")): | ||
| tree = ast.parse(source_path.read_text(encoding="utf-8"), filename=str(source_path)) | ||
| for node in ast.walk(tree): | ||
| if isinstance(node, ast.Import): | ||
| modules = [alias.name for alias in node.names] | ||
| elif isinstance(node, ast.ImportFrom): | ||
| modules = [node.module or ""] | ||
| else: | ||
| continue | ||
| if any(module == "torch" or module.startswith("torch.") for module in modules): | ||
| offenders.append(f"{source_path.relative_to(ROOT)}:{node.lineno}") | ||
| self.assertEqual(offenders, []) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.