transformers-mblt 0.0.0__py3-none-any.whl

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 (109) hide show
  1. transformers_mblt/__init__.py +32 -0
  2. transformers_mblt/_npu.py +43 -0
  3. transformers_mblt/_registry.py +92 -0
  4. transformers_mblt/cli/__init__.py +3 -0
  5. transformers_mblt/cli/__main__.py +4 -0
  6. transformers_mblt/cli/chat.py +38 -0
  7. transformers_mblt/cli/list.py +56 -0
  8. transformers_mblt/cli/main.py +51 -0
  9. transformers_mblt/cli/tps.py +5275 -0
  10. transformers_mblt/cli/tps_table.py +1086 -0
  11. transformers_mblt/cli/transformers_compat.py +272 -0
  12. transformers_mblt/models/__init__.py +0 -0
  13. transformers_mblt/models/aya_vision/__init__.py +20 -0
  14. transformers_mblt/models/aya_vision/configuration_aya_vision.py +40 -0
  15. transformers_mblt/models/aya_vision/modeling_aya_vision.py +204 -0
  16. transformers_mblt/models/aya_vision/proxy_aya_vision.py +27 -0
  17. transformers_mblt/models/bert/__init__.py +20 -0
  18. transformers_mblt/models/bert/configuration_bert.py +23 -0
  19. transformers_mblt/models/bert/modeling_bert.py +200 -0
  20. transformers_mblt/models/bert/proxy_bert.py +27 -0
  21. transformers_mblt/models/blip/__init__.py +20 -0
  22. transformers_mblt/models/blip/configuration_blip.py +76 -0
  23. transformers_mblt/models/blip/modeling_blip.py +166 -0
  24. transformers_mblt/models/blip/modeling_blip_text.py +218 -0
  25. transformers_mblt/models/blip/proxy_blip.py +27 -0
  26. transformers_mblt/models/cohere2/__init__.py +20 -0
  27. transformers_mblt/models/cohere2/configuration_cohere2.py +42 -0
  28. transformers_mblt/models/cohere2/modeling_cohere2.py +102 -0
  29. transformers_mblt/models/cohere2/proxy_cohere2.py +27 -0
  30. transformers_mblt/models/exaone/__init__.py +20 -0
  31. transformers_mblt/models/exaone/configuration_exaone.py +15 -0
  32. transformers_mblt/models/exaone/modeling_exaone.py +126 -0
  33. transformers_mblt/models/exaone/original/__init__.py +15 -0
  34. transformers_mblt/models/exaone/original/configuration_exaone.py +182 -0
  35. transformers_mblt/models/exaone/proxy_exaone.py +27 -0
  36. transformers_mblt/models/exaone4/__init__.py +20 -0
  37. transformers_mblt/models/exaone4/configuration_exaone4.py +15 -0
  38. transformers_mblt/models/exaone4/modeling_exaone4.py +87 -0
  39. transformers_mblt/models/exaone4/proxy_exaone4.py +27 -0
  40. transformers_mblt/models/llama/__init__.py +20 -0
  41. transformers_mblt/models/llama/configuration_llama.py +69 -0
  42. transformers_mblt/models/llama/modeling_llama.py +89 -0
  43. transformers_mblt/models/llama/proxy_llama.py +27 -0
  44. transformers_mblt/models/llama_eagle3/__init__.py +29 -0
  45. transformers_mblt/models/llama_eagle3/configuration_llama_eagle3.py +39 -0
  46. transformers_mblt/models/llama_eagle3/modeling_llama_eagle3.py +119 -0
  47. transformers_mblt/models/llama_eagle3/proxy_llama_eagle3.py +28 -0
  48. transformers_mblt/models/qwen2/__init__.py +20 -0
  49. transformers_mblt/models/qwen2/configuration_qwen2.py +15 -0
  50. transformers_mblt/models/qwen2/modeling_qwen2.py +87 -0
  51. transformers_mblt/models/qwen2/proxy_qwen2.py +27 -0
  52. transformers_mblt/models/qwen2_eagle3/__init__.py +29 -0
  53. transformers_mblt/models/qwen2_eagle3/configuration_qwen2_eagle3.py +40 -0
  54. transformers_mblt/models/qwen2_eagle3/modeling_qwen2_eagle3.py +124 -0
  55. transformers_mblt/models/qwen2_eagle3/proxy_qwen2_eagle3.py +28 -0
  56. transformers_mblt/models/qwen2_vl/__init__.py +20 -0
  57. transformers_mblt/models/qwen2_vl/configuration_qwen2_vl.py +50 -0
  58. transformers_mblt/models/qwen2_vl/modeling_qwen2_vl.py +680 -0
  59. transformers_mblt/models/qwen2_vl/processing_qwen2_vl.py +121 -0
  60. transformers_mblt/models/qwen2_vl/proxy_qwen2_vl.py +33 -0
  61. transformers_mblt/models/qwen3/__init__.py +20 -0
  62. transformers_mblt/models/qwen3/configuration_qwen3.py +15 -0
  63. transformers_mblt/models/qwen3/modeling_qwen3.py +86 -0
  64. transformers_mblt/models/qwen3/proxy_qwen3.py +27 -0
  65. transformers_mblt/models/qwen3_asr/__init__.py +51 -0
  66. transformers_mblt/models/qwen3_asr/_errors.py +31 -0
  67. transformers_mblt/models/qwen3_asr/configuration_qwen3_asr.py +341 -0
  68. transformers_mblt/models/qwen3_asr/modeling_qwen3_asr.py +814 -0
  69. transformers_mblt/models/qwen3_asr/processing_qwen3_asr.py +17 -0
  70. transformers_mblt/models/qwen3_asr/proxy_qwen3_asr.py +62 -0
  71. transformers_mblt/models/qwen3_eagle3/__init__.py +29 -0
  72. transformers_mblt/models/qwen3_eagle3/configuration_qwen3_eagle3.py +40 -0
  73. transformers_mblt/models/qwen3_eagle3/modeling_qwen3_eagle3.py +119 -0
  74. transformers_mblt/models/qwen3_eagle3/proxy_qwen3_eagle3.py +28 -0
  75. transformers_mblt/models/qwen3_vl/__init__.py +25 -0
  76. transformers_mblt/models/qwen3_vl/configuration_qwen3_vl.py +96 -0
  77. transformers_mblt/models/qwen3_vl/modeling_qwen3_vl.py +2109 -0
  78. transformers_mblt/models/qwen3_vl/processing_qwen3_vl.py +1192 -0
  79. transformers_mblt/models/qwen3_vl/proxy_qwen3_vl.py +60 -0
  80. transformers_mblt/models/siglip/__init__.py +20 -0
  81. transformers_mblt/models/siglip/configuration_siglip.py +14 -0
  82. transformers_mblt/models/siglip/modeling_siglip.py +32 -0
  83. transformers_mblt/models/whisper/__init__.py +30 -0
  84. transformers_mblt/models/whisper/configuration_whisper.py +15 -0
  85. transformers_mblt/models/whisper/modeling_whisper.py +819 -0
  86. transformers_mblt/models/whisper/processing_whisper.py +73 -0
  87. transformers_mblt/models/whisper/proxy_whisper.py +40 -0
  88. transformers_mblt/py.typed +0 -0
  89. transformers_mblt/utils/__init__.py +3 -0
  90. transformers_mblt/utils/api.py +175 -0
  91. transformers_mblt/utils/base_utils.py +68 -0
  92. transformers_mblt/utils/benchmark_cli_common.py +709 -0
  93. transformers_mblt/utils/benchmark_utils.py +2677 -0
  94. transformers_mblt/utils/cache_utils.py +1050 -0
  95. transformers_mblt/utils/configuration_utils.py +1305 -0
  96. transformers_mblt/utils/core_mode.py +78 -0
  97. transformers_mblt/utils/eagle3/__init__.py +1 -0
  98. transformers_mblt/utils/eagle3/decoding.py +20 -0
  99. transformers_mblt/utils/eagle3/eagle3_utils.py +1184 -0
  100. transformers_mblt/utils/eagle3/tree_decoding.py +671 -0
  101. transformers_mblt/utils/generation_utils.py +1258 -0
  102. transformers_mblt/utils/modeling_utils.py +1754 -0
  103. transformers_mblt/utils/multi_slot_dispatch.py +534 -0
  104. transformers_mblt-0.0.0.dist-info/METADATA +212 -0
  105. transformers_mblt-0.0.0.dist-info/RECORD +109 -0
  106. transformers_mblt-0.0.0.dist-info/WHEEL +5 -0
  107. transformers_mblt-0.0.0.dist-info/entry_points.txt +2 -0
  108. transformers_mblt-0.0.0.dist-info/licenses/LICENSE +28 -0
  109. transformers_mblt-0.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,32 @@
1
+ """Mobilint NPU integrations for Hugging Face Transformers.
2
+
3
+ Import :mod:`transformers_mblt` and call :func:`register` to make the ``mobilint-*`` model types resolvable by the
4
+ ``transformers`` Auto classes, or load ``mobilint/*`` Hub models with ``trust_remote_code=True``.
5
+ """
6
+
7
+ from typing import TYPE_CHECKING
8
+
9
+ __version__ = "0.0.0"
10
+
11
+ if TYPE_CHECKING:
12
+ from . import models, utils
13
+ from ._registry import register
14
+ from .utils.api import list_models, list_tasks
15
+
16
+ __all__ = ["__version__", "list_models", "list_tasks", "models", "register", "utils"]
17
+
18
+
19
+ def __getattr__(name: str):
20
+ import importlib
21
+
22
+ if name in {"list_models", "list_tasks"}:
23
+ return getattr(importlib.import_module(".utils.api", __name__), name)
24
+ if name == "register":
25
+ return importlib.import_module("._registry", __name__).register
26
+ if name in {"models", "utils"}:
27
+ return importlib.import_module(f".{name}", __name__)
28
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
29
+
30
+
31
+ def __dir__() -> list[str]:
32
+ return sorted(set(globals()) | set(__all__))
@@ -0,0 +1,43 @@
1
+ """NPU backend exports used by the Transformers integration.
2
+
3
+ The backend implementation is maintained by ``mblt-npu-python`` (:mod:`mblt_npu`). This module adds the
4
+ multi-slot ``dispatcher`` property that the Transformers models rely on, without coupling the NPU wheel to
5
+ ``transformers``.
6
+ """
7
+
8
+ from mblt_npu import (
9
+ BACKEND_CLASSES,
10
+ DEFAULT_TARGET_DEVICE,
11
+ MobilintAriesBackend,
12
+ MobilintBackendAllocError,
13
+ MobilintNPUBackend,
14
+ MobilintRegulusBackend,
15
+ backend_class_for,
16
+ )
17
+
18
+
19
+ def _get_transformers_dispatcher(backend: MobilintNPUBackend):
20
+ """Return the backend's lazily created :class:`MultiSlotDispatcher`."""
21
+ # Attribute name is shared with mblt-model-zoo so a backend keeps one dispatcher when both packages are installed.
22
+ dispatcher = getattr(backend, "_mblt_model_zoo_dispatcher", None)
23
+ if dispatcher is None:
24
+ from .utils.multi_slot_dispatch import MultiSlotDispatcher
25
+
26
+ dispatcher = MultiSlotDispatcher(backend)
27
+ backend._mblt_model_zoo_dispatcher = dispatcher
28
+ return dispatcher
29
+
30
+
31
+ # Guarded so installing alongside mblt-model-zoo (which installs the same property) never overrides an existing one.
32
+ if not hasattr(MobilintNPUBackend, "dispatcher"):
33
+ MobilintNPUBackend.dispatcher = property(_get_transformers_dispatcher)
34
+
35
+ __all__ = [
36
+ "BACKEND_CLASSES",
37
+ "DEFAULT_TARGET_DEVICE",
38
+ "MobilintBackendAllocError",
39
+ "MobilintAriesBackend",
40
+ "MobilintNPUBackend",
41
+ "MobilintRegulusBackend",
42
+ "backend_class_for",
43
+ ]
@@ -0,0 +1,92 @@
1
+ """Explicit registration of Mobilint architectures with the ``transformers`` Auto classes.
2
+
3
+ Every ``configuration_*``, ``modeling_*`` and ``processing_*`` module calls ``AutoConfig.register`` /
4
+ ``AutoModel*.register`` / ``AutoProcessor.register`` at import time. :func:`register` imports them all so
5
+ ``AutoModel*.from_pretrained("mobilint/...")`` resolves the ``mobilint-*`` model types locally, without executing
6
+ the Hub ``proxy_*.py`` remote code.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import importlib
12
+ import importlib.util
13
+ import warnings
14
+
15
+ _ARCHITECTURES: tuple[str, ...] = (
16
+ "llama",
17
+ "qwen2",
18
+ "qwen3",
19
+ "exaone",
20
+ "exaone4",
21
+ "cohere2",
22
+ "bert",
23
+ "siglip",
24
+ "blip",
25
+ "aya_vision",
26
+ "qwen2_vl",
27
+ "qwen3_vl",
28
+ "whisper",
29
+ "qwen3_asr",
30
+ "llama_eagle3",
31
+ "qwen2_eagle3",
32
+ "qwen3_eagle3",
33
+ )
34
+ _MODULE_KINDS: tuple[str, ...] = ("configuration", "modeling", "processing")
35
+
36
+ # The Auto registries (CONFIG_MAPPING and the model/processor mappings) live in `transformers.models.auto.*` and are
37
+ # shared by every `transformers` top-level module object, including the fresh `_LazyModule` that Transformers'
38
+ # lazy imports can bind to sys.modules["transformers"] mid-process, so one registration serves them all.
39
+ # Only successfully imported architectures are cached; skipped ones are retried on every call so a later
40
+ # ``register(strict=True)`` still raises for them (and succeeds once their dependency is installed).
41
+ _registered: dict[str, list[str]] = {}
42
+ _warned_skips: set[str] = set()
43
+
44
+
45
+ def _architecture_modules(arch: str) -> list[str]:
46
+ """Return the importable registration modules for ``arch`` in dependency order."""
47
+ package = importlib.import_module(f"{__package__}.models.{arch}")
48
+ names = []
49
+ for kind in _MODULE_KINDS:
50
+ module_name = f"{package.__name__}.{kind}_{arch}"
51
+ if importlib.util.find_spec(module_name) is not None:
52
+ names.append(module_name)
53
+ return names
54
+
55
+
56
+ def register(*, strict: bool = False) -> dict[str, list[str]]:
57
+ """Import every Mobilint architecture module so the Auto classes know the ``mobilint-*`` model types.
58
+
59
+ Architectures that were already registered are not imported again. Architectures that failed to import are
60
+ retried on every call, so a strict call is never satisfied by an earlier non-strict partial result.
61
+
62
+ Args:
63
+ strict: Re-raise the first import failure instead of warning and skipping that architecture. Architectures
64
+ such as Qwen3-VL and Qwen3-ASR require newer ``transformers`` releases or optional extras and are
65
+ skipped otherwise. Each skip is warned about once per process.
66
+
67
+ Returns:
68
+ Mapping of architecture name to the module names that were imported. The same mapping object is returned
69
+ by every call and grows as previously skipped architectures become importable.
70
+ """
71
+ for arch in _ARCHITECTURES:
72
+ if arch in _registered:
73
+ continue
74
+ try:
75
+ modules = _architecture_modules(arch)
76
+ for module_name in modules:
77
+ importlib.import_module(module_name)
78
+ except ImportError as exc:
79
+ if strict:
80
+ raise
81
+ if arch not in _warned_skips:
82
+ _warned_skips.add(arch)
83
+ warnings.warn(f"Skipping Mobilint architecture '{arch}': {exc}", RuntimeWarning, stacklevel=2)
84
+ continue
85
+ _registered[arch] = modules
86
+
87
+ return _registered
88
+
89
+
90
+ def registered_architectures() -> tuple[str, ...]:
91
+ """Return every architecture name :func:`register` attempts to import."""
92
+ return _ARCHITECTURES
@@ -0,0 +1,3 @@
1
+ from .main import main
2
+
3
+ __all__ = ["main"]
@@ -0,0 +1,4 @@
1
+ from .main import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())
@@ -0,0 +1,38 @@
1
+ from argparse import Namespace
2
+
3
+
4
+ def register_mobilint_models(args: Namespace, transformers):
5
+ """Register Mobilint model classes using the active CLI trust and revision settings."""
6
+ revision = getattr(args, "model_revision", None)
7
+ trust_remote_code = getattr(args, "trust_remote_code", False)
8
+ config = transformers.AutoConfig.from_pretrained(
9
+ args.model_name_or_path_or_address,
10
+ revision=revision,
11
+ trust_remote_code=trust_remote_code,
12
+ )
13
+
14
+ model_type = getattr(config, "model_type", "")
15
+ arch_name = config.architectures[0] if getattr(config, "architectures", None) else ""
16
+
17
+ if model_type.startswith("mobilint-") or arch_name.startswith("Mobilint"):
18
+ original_model_type = model_type[len("mobilint-") :] if model_type.startswith("mobilint-") else model_type
19
+ module_model_type = original_model_type.replace("-", "_")
20
+
21
+ import importlib
22
+
23
+ module = importlib.import_module(f"transformers_mblt.models.{module_model_type}.modeling_{module_model_type}")
24
+ # Importing the modeling module already registers its Auto classes. The class injection and task-mapping
25
+ # patch below need a concrete architecture name, so skip them when the config omits `architectures`.
26
+ if not arch_name:
27
+ return
28
+ setattr(transformers, arch_name, module.__dict__[arch_name])
29
+
30
+ MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = transformers.models.auto.modeling_auto.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
31
+ MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES = (
32
+ transformers.models.auto.modeling_auto.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES
33
+ )
34
+
35
+ if arch_name.endswith("CausalLM"):
36
+ MODEL_FOR_CAUSAL_LM_MAPPING_NAMES[model_type] = arch_name
37
+ elif arch_name.endswith("ConditionalGeneration"):
38
+ MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES[model_type] = arch_name
@@ -0,0 +1,56 @@
1
+ """``transformers-mblt list`` command: list Mobilint Transformers models and tasks."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ from typing import Any
8
+
9
+
10
+ def add_list_parser(subparsers: Any) -> argparse.ArgumentParser:
11
+ """Register the ``list`` subcommand."""
12
+ from ..utils.api import list_tasks
13
+
14
+ parser = subparsers.add_parser(
15
+ "list",
16
+ help="List Mobilint models on the Hugging Face Hub (falls back to the local cache)",
17
+ description=(
18
+ "List Mobilint Transformers models grouped by pipeline task. Queries the Hugging Face Hub and falls "
19
+ "back to the local Hugging Face cache when the Hub is unreachable."
20
+ ),
21
+ )
22
+ parser.add_argument(
23
+ "--task",
24
+ action="append",
25
+ choices=list_tasks(),
26
+ default=None,
27
+ help="Pipeline task to list. Repeat to list several tasks. Default: every supported task.",
28
+ )
29
+ parser.add_argument(
30
+ "--include-private",
31
+ action="store_true",
32
+ help="Include private repositories visible to the current Hugging Face token.",
33
+ )
34
+ parser.add_argument("--json", action="store_true", help="Print the result as JSON.")
35
+ parser.add_argument("--tasks", action="store_true", help="Only print the supported task names.")
36
+ parser.set_defaults(_handler=_cmd_list)
37
+ return parser
38
+
39
+
40
+ def _cmd_list(args: argparse.Namespace) -> int:
41
+ from ..utils.api import list_models, list_tasks
42
+
43
+ if args.tasks:
44
+ tasks = list_tasks()
45
+ print(json.dumps(tasks, indent=2) if args.json else "\n".join(tasks))
46
+ return 0
47
+
48
+ models = list_models(args.task or list_tasks(), include_private=args.include_private)
49
+ if args.json:
50
+ print(json.dumps(models, indent=2))
51
+ return 0
52
+ for task, model_ids in models.items():
53
+ print(f"{task} ({len(model_ids)})")
54
+ for model_id in model_ids:
55
+ print(f" {model_id}")
56
+ return 0
@@ -0,0 +1,51 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import sys
5
+
6
+ from .list import add_list_parser
7
+ from .tps import add_tps_parser
8
+ from .transformers_compat import dispatch_transformers_cli, is_transformers_cli_command
9
+
10
+
11
+ def build_parser() -> argparse.ArgumentParser:
12
+ parser = argparse.ArgumentParser(
13
+ prog="transformers-mblt",
14
+ description=(
15
+ "Mobilint NPU helpers for Hugging Face Transformers. Upstream Transformers commands such as "
16
+ "`chat`, `serve`, `download`, `env`, and `version` are delegated to the installed `transformers` "
17
+ "package with Mobilint models registered."
18
+ ),
19
+ )
20
+ parser.add_argument("--version", action="version", version=f"%(prog)s {_package_version()}")
21
+ commands_parser = parser.add_subparsers(help="transformers-mblt command helpers")
22
+
23
+ add_list_parser(commands_parser)
24
+ add_tps_parser(commands_parser)
25
+
26
+ return parser
27
+
28
+
29
+ def _package_version() -> str:
30
+ from .. import __version__
31
+
32
+ return __version__
33
+
34
+
35
+ def main() -> int:
36
+ # Upstream Transformers commands own their argument parsing, so delegate before argparse sees them.
37
+ if is_transformers_cli_command(sys.argv):
38
+ return dispatch_transformers_cli(sys.argv)
39
+
40
+ parser = build_parser()
41
+ args = parser.parse_args()
42
+
43
+ if hasattr(args, "_handler"):
44
+ return args._handler(args)
45
+
46
+ parser.print_help()
47
+ return 1
48
+
49
+
50
+ if __name__ == "__main__":
51
+ raise SystemExit(main())