mblt-npu-python 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mblt_npu_python-0.0.0/LICENSE +28 -0
- mblt_npu_python-0.0.0/PKG-INFO +121 -0
- mblt_npu_python-0.0.0/README.md +93 -0
- mblt_npu_python-0.0.0/mblt_npu/__init__.py +36 -0
- mblt_npu_python-0.0.0/mblt_npu/logging.py +54 -0
- mblt_npu_python-0.0.0/mblt_npu/npu_backend.py +632 -0
- mblt_npu_python-0.0.0/mblt_npu/onnx_backend.py +90 -0
- mblt_npu_python-0.0.0/mblt_npu/pytest_plugin.py +218 -0
- mblt_npu_python-0.0.0/mblt_npu_python.egg-info/PKG-INFO +121 -0
- mblt_npu_python-0.0.0/mblt_npu_python.egg-info/SOURCES.txt +15 -0
- mblt_npu_python-0.0.0/mblt_npu_python.egg-info/dependency_links.txt +1 -0
- mblt_npu_python-0.0.0/mblt_npu_python.egg-info/requires.txt +8 -0
- mblt_npu_python-0.0.0/mblt_npu_python.egg-info/top_level.txt +1 -0
- mblt_npu_python-0.0.0/pyproject.toml +58 -0
- mblt_npu_python-0.0.0/setup.cfg +4 -0
- mblt_npu_python-0.0.0/tests/test_onnx_backend.py +69 -0
- mblt_npu_python-0.0.0/tests/test_target_device.py +282 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Mobilint, Inc.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mblt-npu-python
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Shared NPU access for the Mobilint Python packages
|
|
5
|
+
Author: Mobilint
|
|
6
|
+
License: BSD-3-Clause
|
|
7
|
+
Project-URL: Home, https://www.mobilint.com/
|
|
8
|
+
Project-URL: Repository, https://github.com/mobilint/mblt-npu-python
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: <3.13,>=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: mobilint-qb-runtime>=1.0.0
|
|
22
|
+
Requires-Dist: huggingface-hub
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest; extra == "test"
|
|
25
|
+
Provides-Extra: onnxruntime
|
|
26
|
+
Requires-Dist: onnxruntime; extra == "onnxruntime"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# Mobilint NPU Python
|
|
30
|
+
|
|
31
|
+
Shared runtime support for applications that run MXQ models on Mobilint NPUs or ONNX models through ONNX Runtime.
|
|
32
|
+
`mblt-npu-python` provides the common backend, device-selection rules, Hugging Face
|
|
33
|
+
artifact resolution, and model-detail logging used by Mobilint Python packages. It
|
|
34
|
+
is a library dependency, rather than an end-user model catalog.
|
|
35
|
+
|
|
36
|
+
Version `0.0.0` is the initial standalone release.
|
|
37
|
+
|
|
38
|
+
`logging` ships here rather than with its only caller because the two are mutually
|
|
39
|
+
dependent — `npu_backend` imports `log_model_details`, and `log_model_details` reads
|
|
40
|
+
a `MobilintNPUBackend`'s fields.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install mblt-npu-python
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This package requires a supported Linux environment with
|
|
49
|
+
[`mobilint-qb-runtime`](https://pypi.org/project/mobilint-qb-runtime/) available
|
|
50
|
+
and Python 3.10 through 3.12.
|
|
51
|
+
|
|
52
|
+
## Public API
|
|
53
|
+
|
|
54
|
+
Import the backend from `mblt_npu`:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from mblt_npu import MobilintNPUBackend
|
|
58
|
+
|
|
59
|
+
backend = MobilintNPUBackend(
|
|
60
|
+
mxq_path="model.mxq",
|
|
61
|
+
core_mode="single",
|
|
62
|
+
)
|
|
63
|
+
backend.create()
|
|
64
|
+
try:
|
|
65
|
+
backend.launch()
|
|
66
|
+
outputs = backend.mxq_model.infer([input_tensor])
|
|
67
|
+
finally:
|
|
68
|
+
backend.dispose()
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`MobilintNPUBackend` selects the appropriate implementation from
|
|
72
|
+
`target_device` (default: `"aries-rb"`). `"aries-rb"` selects
|
|
73
|
+
`MobilintAriesBackend`; `"regulus-ra"` and `"regulus-rb"` select
|
|
74
|
+
`MobilintRegulusBackend`. The former generic values `"aries"` and `"regulus"`
|
|
75
|
+
remain accepted when loading older configurations.
|
|
76
|
+
`backend_class_for()` and `BACKEND_CLASSES` are available for integrations that
|
|
77
|
+
need to inspect the supported targets.
|
|
78
|
+
|
|
79
|
+
For ONNX inference, install the optional runtime extra and use `ONNXBackend`:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install "mblt-npu-python[onnxruntime]"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from mblt_npu import ONNXBackend
|
|
87
|
+
|
|
88
|
+
backend = ONNXBackend("model.onnx")
|
|
89
|
+
backend.create()
|
|
90
|
+
outputs = backend({"images": input_array})
|
|
91
|
+
backend.dispose()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`ONNXBackend` imports `onnxruntime` only when it creates a session.
|
|
95
|
+
|
|
96
|
+
Most users should access the backend through a model package such as
|
|
97
|
+
[`mblt-vision-python`](https://github.com/mobilint/mblt-vision-python), which owns
|
|
98
|
+
model configuration, preprocessing, and postprocessing.
|
|
99
|
+
|
|
100
|
+
## Testing helpers
|
|
101
|
+
|
|
102
|
+
The optional `test` extra provides a shared pytest plugin with NPU options and the
|
|
103
|
+
`npu_params` fixture used by Mobilint package test suites:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
pip install "mblt-npu-python[test]"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Import `mblt_npu.pytest_plugin` from a repository's root `tests/conftest.py` to
|
|
110
|
+
register its options. The plugin is intentionally not auto-registered, so projects
|
|
111
|
+
control when those command-line options are exposed.
|
|
112
|
+
|
|
113
|
+
## Support and issues
|
|
114
|
+
|
|
115
|
+
For installation, runtime, or integration support, visit the
|
|
116
|
+
[Mobilint forum](https://discuss.mobilint.com/). Report reproducible package issues in the
|
|
117
|
+
[mblt-npu-python issue tracker](https://github.com/mobilint/mblt-npu-python/issues).
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
Distributed under the [BSD 3-Clause License](LICENSE).
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Mobilint NPU Python
|
|
2
|
+
|
|
3
|
+
Shared runtime support for applications that run MXQ models on Mobilint NPUs or ONNX models through ONNX Runtime.
|
|
4
|
+
`mblt-npu-python` provides the common backend, device-selection rules, Hugging Face
|
|
5
|
+
artifact resolution, and model-detail logging used by Mobilint Python packages. It
|
|
6
|
+
is a library dependency, rather than an end-user model catalog.
|
|
7
|
+
|
|
8
|
+
Version `0.0.0` is the initial standalone release.
|
|
9
|
+
|
|
10
|
+
`logging` ships here rather than with its only caller because the two are mutually
|
|
11
|
+
dependent — `npu_backend` imports `log_model_details`, and `log_model_details` reads
|
|
12
|
+
a `MobilintNPUBackend`'s fields.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install mblt-npu-python
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
This package requires a supported Linux environment with
|
|
21
|
+
[`mobilint-qb-runtime`](https://pypi.org/project/mobilint-qb-runtime/) available
|
|
22
|
+
and Python 3.10 through 3.12.
|
|
23
|
+
|
|
24
|
+
## Public API
|
|
25
|
+
|
|
26
|
+
Import the backend from `mblt_npu`:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from mblt_npu import MobilintNPUBackend
|
|
30
|
+
|
|
31
|
+
backend = MobilintNPUBackend(
|
|
32
|
+
mxq_path="model.mxq",
|
|
33
|
+
core_mode="single",
|
|
34
|
+
)
|
|
35
|
+
backend.create()
|
|
36
|
+
try:
|
|
37
|
+
backend.launch()
|
|
38
|
+
outputs = backend.mxq_model.infer([input_tensor])
|
|
39
|
+
finally:
|
|
40
|
+
backend.dispose()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`MobilintNPUBackend` selects the appropriate implementation from
|
|
44
|
+
`target_device` (default: `"aries-rb"`). `"aries-rb"` selects
|
|
45
|
+
`MobilintAriesBackend`; `"regulus-ra"` and `"regulus-rb"` select
|
|
46
|
+
`MobilintRegulusBackend`. The former generic values `"aries"` and `"regulus"`
|
|
47
|
+
remain accepted when loading older configurations.
|
|
48
|
+
`backend_class_for()` and `BACKEND_CLASSES` are available for integrations that
|
|
49
|
+
need to inspect the supported targets.
|
|
50
|
+
|
|
51
|
+
For ONNX inference, install the optional runtime extra and use `ONNXBackend`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install "mblt-npu-python[onnxruntime]"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from mblt_npu import ONNXBackend
|
|
59
|
+
|
|
60
|
+
backend = ONNXBackend("model.onnx")
|
|
61
|
+
backend.create()
|
|
62
|
+
outputs = backend({"images": input_array})
|
|
63
|
+
backend.dispose()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`ONNXBackend` imports `onnxruntime` only when it creates a session.
|
|
67
|
+
|
|
68
|
+
Most users should access the backend through a model package such as
|
|
69
|
+
[`mblt-vision-python`](https://github.com/mobilint/mblt-vision-python), which owns
|
|
70
|
+
model configuration, preprocessing, and postprocessing.
|
|
71
|
+
|
|
72
|
+
## Testing helpers
|
|
73
|
+
|
|
74
|
+
The optional `test` extra provides a shared pytest plugin with NPU options and the
|
|
75
|
+
`npu_params` fixture used by Mobilint package test suites:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install "mblt-npu-python[test]"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Import `mblt_npu.pytest_plugin` from a repository's root `tests/conftest.py` to
|
|
82
|
+
register its options. The plugin is intentionally not auto-registered, so projects
|
|
83
|
+
control when those command-line options are exposed.
|
|
84
|
+
|
|
85
|
+
## Support and issues
|
|
86
|
+
|
|
87
|
+
For installation, runtime, or integration support, visit the
|
|
88
|
+
[Mobilint forum](https://discuss.mobilint.com/). Report reproducible package issues in the
|
|
89
|
+
[mblt-npu-python issue tracker](https://github.com/mobilint/mblt-npu-python/issues).
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
Distributed under the [BSD 3-Clause License](LICENSE).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Shared NPU access for the mblt Python packages.
|
|
2
|
+
|
|
3
|
+
`MobilintNPUBackend` is defined exactly once, here, because the alternative
|
|
4
|
+
was a copy in each of mblt-vision-python, mblt-transformers-python and
|
|
5
|
+
mblt-MeloTTS-python that nothing would keep in sync.
|
|
6
|
+
|
|
7
|
+
`logging` lives here too rather than in vision, its only caller, because the
|
|
8
|
+
two are mutually dependent: npu_backend imports log_model_details and
|
|
9
|
+
log_model_details reads a MobilintNPUBackend's fields.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from .npu_backend import (
|
|
13
|
+
BACKEND_CLASSES,
|
|
14
|
+
DEFAULT_TARGET_DEVICE,
|
|
15
|
+
MobilintAriesBackend,
|
|
16
|
+
MobilintNPUBackend,
|
|
17
|
+
MobilintRegulusBackend,
|
|
18
|
+
backend_class_for,
|
|
19
|
+
normalize_target_device,
|
|
20
|
+
)
|
|
21
|
+
from .logging import log_model_details
|
|
22
|
+
from .onnx_backend import ONNXBackend
|
|
23
|
+
|
|
24
|
+
__version__ = "0.0.0"
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"BACKEND_CLASSES",
|
|
28
|
+
"DEFAULT_TARGET_DEVICE",
|
|
29
|
+
"MobilintAriesBackend",
|
|
30
|
+
"MobilintNPUBackend",
|
|
31
|
+
"MobilintRegulusBackend",
|
|
32
|
+
"ONNXBackend",
|
|
33
|
+
"backend_class_for",
|
|
34
|
+
"log_model_details",
|
|
35
|
+
"normalize_target_device",
|
|
36
|
+
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import os
|
|
3
|
+
from typing import TYPE_CHECKING, Optional
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from .npu_backend import MobilintNPUBackend
|
|
7
|
+
|
|
8
|
+
_VERBOSE_TRUE_VALUES = {"1", "true", "yes", "on"}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _is_verbose_enabled() -> bool:
|
|
12
|
+
return os.getenv("MBLT_MODEL_ZOO_VERBOSE", "").lower() in _VERBOSE_TRUE_VALUES
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _md5_hash_from_file(file_path: str) -> str:
|
|
16
|
+
hash_md5 = hashlib.md5()
|
|
17
|
+
with open(file_path, "rb") as file_handle:
|
|
18
|
+
for chunk in iter(lambda: file_handle.read(8192), b""):
|
|
19
|
+
hash_md5.update(chunk)
|
|
20
|
+
return hash_md5.hexdigest()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def log_model_details(
|
|
24
|
+
model_path: str, npu_backend: Optional["MobilintNPUBackend"] = None
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Print model metadata when verbose logging is enabled."""
|
|
27
|
+
if not _is_verbose_enabled():
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
print("Model Initialized")
|
|
31
|
+
print(f"Model Size: {os.path.getsize(model_path) / 1024 / 1024:.2f} MB")
|
|
32
|
+
print(f"Model Hash: {_md5_hash_from_file(model_path)}")
|
|
33
|
+
|
|
34
|
+
if npu_backend is not None:
|
|
35
|
+
print(f"Device Number: {npu_backend.dev_no}")
|
|
36
|
+
print(f"Core Mode: {npu_backend.core_mode}")
|
|
37
|
+
if npu_backend.core_mode == "single":
|
|
38
|
+
print(f"Target Cores: {npu_backend.target_cores}")
|
|
39
|
+
else:
|
|
40
|
+
print(f"Target Clusters: {npu_backend.target_clusters}")
|
|
41
|
+
if npu_backend.mxq_model.get_num_model_variants() == 1:
|
|
42
|
+
print(f"Model Input Shape: {npu_backend.mxq_model.get_model_input_shape()}")
|
|
43
|
+
print(
|
|
44
|
+
f"Model Output Shape: {npu_backend.mxq_model.get_model_output_shape()}"
|
|
45
|
+
)
|
|
46
|
+
else:
|
|
47
|
+
for i in range(npu_backend.mxq_model.get_num_model_variants()):
|
|
48
|
+
print(f"Model Variant {i}")
|
|
49
|
+
print(
|
|
50
|
+
f"\tInput Shape: {npu_backend.mxq_model.get_model_variant_handle(i).get_model_input_shape()}"
|
|
51
|
+
)
|
|
52
|
+
print(
|
|
53
|
+
f"\tOutput Shape: {npu_backend.mxq_model.get_model_variant_handle(i).get_model_output_shape()}"
|
|
54
|
+
)
|