mblt-npu-python 0.0.1__tar.gz → 0.0.2__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.
Files changed (20) hide show
  1. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/PKG-INFO +1 -1
  2. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu/__init__.py +1 -1
  3. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu/npu_backend.py +3 -3
  4. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu/npu_target.py +22 -1
  5. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu_python.egg-info/PKG-INFO +1 -1
  6. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/tests/test_target_device.py +36 -0
  7. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/LICENSE +0 -0
  8. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/README.md +0 -0
  9. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu/core_mode.py +0 -0
  10. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu/logging.py +0 -0
  11. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu/onnx_backend.py +0 -0
  12. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu/pytest_plugin.py +0 -0
  13. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu_python.egg-info/SOURCES.txt +0 -0
  14. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu_python.egg-info/dependency_links.txt +0 -0
  15. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu_python.egg-info/requires.txt +0 -0
  16. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/mblt_npu_python.egg-info/top_level.txt +0 -0
  17. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/pyproject.toml +0 -0
  18. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/setup.cfg +0 -0
  19. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/tests/test_npu_backend_multi_slot.py +0 -0
  20. {mblt_npu_python-0.0.1 → mblt_npu_python-0.0.2}/tests/test_onnx_backend.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mblt-npu-python
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Shared NPU access for the Mobilint Python packages
5
5
  Author: Mobilint
6
6
  License: BSD-3-Clause
@@ -22,7 +22,7 @@ from .npu_backend import (
22
22
  from .logging import log_model_details
23
23
  from .onnx_backend import ONNXBackend
24
24
 
25
- __version__ = "0.0.1"
25
+ __version__ = "0.0.2"
26
26
 
27
27
  __all__ = [
28
28
  "BACKEND_CLASSES",
@@ -31,7 +31,7 @@ import math
31
31
  import os
32
32
  import re
33
33
  import sys
34
- from typing import Any, Dict, List, Literal, Optional, Union
34
+ from typing import Any, Dict, List, Literal, Optional, Sequence, Union
35
35
 
36
36
  from huggingface_hub import HfApi, hf_hub_download
37
37
  from huggingface_hub.errors import EntryNotFoundError
@@ -211,7 +211,7 @@ class MobilintNPUBackend:
211
211
  dev_no: Optional[Union[int, List[int]]] = None,
212
212
  core_mode: CoreMode = "single",
213
213
  target_cores: Optional[List[Union[str, "CoreId"]]] = None,
214
- target_clusters: Optional[List[Union[int, str, "Cluster"]]] = None,
214
+ target_clusters: Optional[Sequence[Union[int, str, "Cluster"]]] = None,
215
215
  revision: Optional[str] = None,
216
216
  commit_hash: Optional[str] = None,
217
217
  target_device: Optional[str] = None,
@@ -1350,7 +1350,7 @@ class MobilintNPUBackend:
1350
1350
  return result
1351
1351
 
1352
1352
  @target_clusters.setter
1353
- def target_clusters(self, values: List[Union[int, str, "Cluster"]]) -> None:
1353
+ def target_clusters(self, values: Sequence[Union[int, str, "Cluster"]]) -> None:
1354
1354
  """Record a raw ``target_clusters`` override on the pending accumulator.
1355
1355
 
1356
1356
  Normalization (legacy migration, grain fold/unfold, device-set
@@ -52,11 +52,32 @@ from .core_mode import CoreMode, normalize_core_mode
52
52
  # Default device index for ``dev_no`` when the caller does not pin one.
53
53
  _DEFAULT_DEV_NO: int = 0
54
54
 
55
+
55
56
  # Sentinel used to distinguish "field not overridden this session" from
56
57
  # "field explicitly set to None/empty". Kept module-private and reused by
57
58
  # both :class:`NPUTargetSpec` (single-call ``_with`` shim) and
58
59
  # :class:`NPUTargetSpecPending` (accumulator).
59
- _UNSET: Any = object()
60
+ #
61
+ # Identity, not equality, is what every ``raw_* is not _UNSET`` check relies
62
+ # on. A bare ``object()`` does not survive ``copy.deepcopy`` as the same
63
+ # instance, and upstream ``transformers.PretrainedConfig.to_dict()`` runs
64
+ # ``copy.deepcopy(self.__dict__)`` on every config it serializes -- including
65
+ # nested sub-configs whose ``npu_backend`` still holds a pending spec with
66
+ # unresolved ``_UNSET`` slots. That deep-copied sentinel then fails every
67
+ # ``is not _UNSET`` check, so callers see a bogus "overridden" field. Make the
68
+ # sentinel copy/deepcopy to itself so its identity survives that path.
69
+ class _UnsetType:
70
+ def __repr__(self) -> str:
71
+ return "_UNSET"
72
+
73
+ def __copy__(self) -> "_UnsetType":
74
+ return self
75
+
76
+ def __deepcopy__(self, memo: Dict[int, Any]) -> "_UnsetType":
77
+ return self
78
+
79
+
80
+ _UNSET: Any = _UnsetType()
60
81
 
61
82
 
62
83
  cluster_map: Dict[int, "Cluster"] = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mblt-npu-python
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Shared NPU access for the Mobilint Python packages
5
5
  Author: Mobilint
6
6
  License: BSD-3-Clause
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import copy
5
6
  from pathlib import Path
6
7
  from typing import Any, cast
7
8
 
@@ -9,6 +10,7 @@ import pytest
9
10
 
10
11
  from mblt_npu import MobilintAriesBackend, MobilintNPUBackend, MobilintRegulusBackend
11
12
  import mblt_npu.npu_backend as npu_backend
13
+ from mblt_npu.npu_target import _UNSET
12
14
 
13
15
 
14
16
  @pytest.mark.parametrize(
@@ -31,6 +33,40 @@ def test_target_device_selects_the_product_backend(
31
33
  assert backend.to_dict()["target_device"] == target_device
32
34
 
33
35
 
36
+ def test_unset_sentinel_survives_deepcopy() -> None:
37
+ """Keep the ``_UNSET`` sentinel's identity across ``copy.deepcopy``.
38
+
39
+ ``transformers.PretrainedConfig.to_dict()`` runs ``copy.deepcopy(self.__dict__)``
40
+ on every config it serializes, including nested sub-configs whose
41
+ ``npu_backend`` still holds unresolved ``_UNSET`` slots. A bare ``object()``
42
+ sentinel would be reconstructed as a distinct instance there, so every
43
+ ``is not _UNSET`` override check on the copy would wrongly report the
44
+ field as overridden.
45
+ """
46
+
47
+ assert copy.deepcopy(_UNSET) is _UNSET
48
+ assert copy.copy(_UNSET) is _UNSET
49
+
50
+
51
+ def test_backend_survives_deepcopy_before_finalization() -> None:
52
+ """Finalize identically after a deepcopy taken before the next ``_spec`` read.
53
+
54
+ Reproduces the HF ``PretrainedConfig.to_dict()`` path: overriding one field
55
+ (``target_clusters``) invalidates ``_finalized`` without touching the other
56
+ fields' still-``_UNSET`` raw slots. Deep-copying the backend in that state
57
+ (as upstream does for nested sub-configs, before their own ``to_dict()``
58
+ ever ran) must not corrupt those slots when the copy is finalized.
59
+ """
60
+
61
+ backend = MobilintAriesBackend()
62
+ backend.target_clusters = [0, 1]
63
+ assert backend._finalized is None
64
+
65
+ copied = copy.deepcopy(backend)
66
+
67
+ assert copied.to_dict() == backend.to_dict()
68
+
69
+
34
70
  def test_default_target_device_is_aries_rb() -> None:
35
71
  """Use Aries RB when callers do not declare a board."""
36
72
 
File without changes