mlia 0.12.2__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 (90) hide show
  1. mlia/__init__.py +86 -0
  2. mlia/_constants.py +111 -0
  3. mlia/api.py +983 -0
  4. mlia/backend/__init__.py +13 -0
  5. mlia/backend/config.py +146 -0
  6. mlia/backend/errors.py +16 -0
  7. mlia/backend/install.py +590 -0
  8. mlia/backend/manager.py +523 -0
  9. mlia/backend/options.py +145 -0
  10. mlia/backend/registry.py +48 -0
  11. mlia/backend/repo.py +212 -0
  12. mlia/backend/vendor.py +19 -0
  13. mlia/backends.py +20 -0
  14. mlia/cli/__init__.py +3 -0
  15. mlia/cli/command_validators.py +157 -0
  16. mlia/cli/commands.py +788 -0
  17. mlia/cli/completion.py +26 -0
  18. mlia/cli/helpers.py +94 -0
  19. mlia/cli/main.py +64 -0
  20. mlia/cli/settings.py +190 -0
  21. mlia/core/__init__.py +21 -0
  22. mlia/core/advice_generation.py +155 -0
  23. mlia/core/advisor.py +93 -0
  24. mlia/core/code_line.py +127 -0
  25. mlia/core/common.py +49 -0
  26. mlia/core/context.py +205 -0
  27. mlia/core/data_analysis.py +327 -0
  28. mlia/core/data_collection.py +36 -0
  29. mlia/core/entity_collapse.py +170 -0
  30. mlia/core/entity_graph.py +250 -0
  31. mlia/core/errors.py +26 -0
  32. mlia/core/helpers.py +36 -0
  33. mlia/core/logging.py +169 -0
  34. mlia/core/metadata.py +51 -0
  35. mlia/core/mixins.py +56 -0
  36. mlia/core/output_collection.py +78 -0
  37. mlia/core/output_persistence.py +22 -0
  38. mlia/core/output_postprocessing.py +70 -0
  39. mlia/core/output_projection.py +2070 -0
  40. mlia/core/output_rendering.py +322 -0
  41. mlia/core/output_schema.py +967 -0
  42. mlia/core/output_validation.py +712 -0
  43. mlia/core/performance.py +46 -0
  44. mlia/core/reporters.py +21 -0
  45. mlia/core/reporting.py +495 -0
  46. mlia/core/settings.py +97 -0
  47. mlia/core/typing.py +7 -0
  48. mlia/core/workflow.py +124 -0
  49. mlia/plugins/__init__.py +3 -0
  50. mlia/plugins/analysis.py +80 -0
  51. mlia/plugins/plugins.py +175 -0
  52. mlia/plugins/registry.py +110 -0
  53. mlia/resources/mlia-output-schema-1.0.0.json +233 -0
  54. mlia/resources/mlia-output-schema-1.0.0.json.license +2 -0
  55. mlia/resources/mlia-output-schema-1.1.0.json +290 -0
  56. mlia/resources/mlia-output-schema-1.1.0.json.license +2 -0
  57. mlia/resources/mlia-output-schema-1.2.0.json +325 -0
  58. mlia/resources/mlia-output-schema-1.2.0.json.license +2 -0
  59. mlia/resources/mlia-target-schema-1.0.0.json +79 -0
  60. mlia/resources/mlia-target-schema-1.0.0.json.license +2 -0
  61. mlia/resources/optimization_profiles/README.md +8 -0
  62. mlia/resources/target_profiles/README.md +8 -0
  63. mlia/target/__init__.py +18 -0
  64. mlia/target/config.py +220 -0
  65. mlia/target/registry.py +280 -0
  66. mlia/target_profiles.py +20 -0
  67. mlia/targets.py +20 -0
  68. mlia/testing/README.md +81 -0
  69. mlia/testing/__init__.py +43 -0
  70. mlia/testing/e2e.py +509 -0
  71. mlia/transformers/__init__.py +9 -0
  72. mlia/transformers/error.py +9 -0
  73. mlia/transformers/registry.py +100 -0
  74. mlia/utils/__init__.py +3 -0
  75. mlia/utils/console.py +129 -0
  76. mlia/utils/download.py +94 -0
  77. mlia/utils/filesystem.py +208 -0
  78. mlia/utils/logging.py +222 -0
  79. mlia/utils/misc.py +63 -0
  80. mlia/utils/proc.py +67 -0
  81. mlia/utils/py_manager.py +80 -0
  82. mlia/utils/registry.py +48 -0
  83. mlia/utils/types.py +39 -0
  84. mlia-0.12.2.dist-info/METADATA +348 -0
  85. mlia-0.12.2.dist-info/RECORD +90 -0
  86. mlia-0.12.2.dist-info/WHEEL +4 -0
  87. mlia-0.12.2.dist-info/entry_points.txt +4 -0
  88. mlia-0.12.2.dist-info/licenses/LICENSES/Apache-2.0.txt +177 -0
  89. mlia-0.12.2.dist-info/licenses/LICENSES/MIT.txt +21 -0
  90. mlia-0.12.2.dist-info/sboms/mlia.cdx.json +35 -0
mlia/__init__.py ADDED
@@ -0,0 +1,86 @@
1
+ # SPDX-FileCopyrightText: Copyright 2022, 2026, Arm Limited and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Init of MLIA."""
4
+ # Package setup must happen before importing even the lightweight public errors.
5
+ # ruff: noqa: E402
6
+
7
+ import logging
8
+ import os
9
+ import pkgutil
10
+ from importlib import import_module
11
+ from importlib.metadata import version
12
+ from typing import Any
13
+
14
+ # redirect warnings to logging
15
+ logging.captureWarnings(True)
16
+
17
+ # Allow mlia subpackages to be provided by multiple distributions.
18
+ __path__ = pkgutil.extend_path(__path__, __name__)
19
+
20
+ # Prevent "No handler" warnings without configuring global logging.
21
+ logging.getLogger("mlia").addHandler(logging.NullHandler())
22
+
23
+
24
+ # disable TensorFlow warning messages
25
+ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
26
+
27
+ __version__ = version("mlia")
28
+
29
+ from mlia.core.errors import (
30
+ ConfigurationError,
31
+ FunctionalityNotSupportedError,
32
+ InternalError,
33
+ UnsupportedConfigurationError,
34
+ )
35
+
36
+ _LAZY_EXPORTS = {
37
+ "backends": ("mlia.backends", None),
38
+ "install_backends": ("mlia.api", "install_backends"),
39
+ "list_backend_options": ("mlia.api", "list_backend_options"),
40
+ "list_backends": ("mlia.api", "list_backends"),
41
+ "list_target_profiles": ("mlia.api", "list_target_profiles"),
42
+ "list_targets": ("mlia.api", "list_targets"),
43
+ "run_advisor": ("mlia.api", "run_advisor"),
44
+ "supported_backends": ("mlia.api", "supported_backends"),
45
+ "target_profiles": ("mlia.target_profiles", None),
46
+ "targets": ("mlia.targets", None),
47
+ "uninstall_backends": ("mlia.api", "uninstall_backends"),
48
+ "ValidationMode": ("mlia.api", "ValidationMode"),
49
+ }
50
+
51
+ __all__ = [
52
+ "backends",
53
+ "install_backends",
54
+ "uninstall_backends",
55
+ "list_backend_options",
56
+ "list_backends",
57
+ "list_target_profiles",
58
+ "list_targets",
59
+ "ConfigurationError",
60
+ "FunctionalityNotSupportedError",
61
+ "InternalError",
62
+ "UnsupportedConfigurationError",
63
+ "ValidationMode",
64
+ "run_advisor",
65
+ "supported_backends",
66
+ "target_profiles",
67
+ "targets",
68
+ ]
69
+
70
+
71
+ def __getattr__(name: str) -> Any:
72
+ """Load runtime-heavy public exports on first access."""
73
+ try:
74
+ module_name, attribute_name = _LAZY_EXPORTS[name]
75
+ except KeyError as err:
76
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from err
77
+
78
+ module = import_module(module_name)
79
+ value = module if attribute_name is None else getattr(module, attribute_name)
80
+ globals()[name] = value
81
+ return value
82
+
83
+
84
+ def __dir__() -> list[str]:
85
+ """Expose lazy public exports through standard introspection."""
86
+ return sorted(set(globals()) | set(__all__))
mlia/_constants.py ADDED
@@ -0,0 +1,111 @@
1
+ # SPDX-FileCopyrightText: Copyright 2026, Arm Limited and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """Helpers for dynamic constants modules."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import re
8
+ from collections.abc import Iterable
9
+ from dataclasses import dataclass
10
+ from functools import lru_cache
11
+
12
+ from mlia.backend.registry import registry as backend_registry
13
+ from mlia.plugins.plugins import load_backend_plugins, load_target_plugins
14
+ from mlia.target.registry import profiles_by_target
15
+ from mlia.target.registry import registry as target_registry
16
+
17
+ _IDENTIFIER_RE = re.compile(r"[^0-9A-Za-z]+")
18
+
19
+
20
+ @dataclass(frozen=True)
21
+ class ConstantEntry:
22
+ """A constant exported by a dynamic module."""
23
+
24
+ symbol: str
25
+ value: str
26
+
27
+
28
+ def normalize_constant_name(value: str) -> str:
29
+ """Convert a canonical MLIA identifier into a Python constant name."""
30
+ normalized = _IDENTIFIER_RE.sub("_", value).strip("_").upper()
31
+ if not normalized:
32
+ raise ValueError(f"Cannot derive a constant name from {value!r}.")
33
+ if normalized[0].isdigit():
34
+ normalized = f"_{normalized}"
35
+ return normalized
36
+
37
+
38
+ @lru_cache
39
+ def backend_entries() -> tuple[ConstantEntry, ...]:
40
+ """Return exported backend constants for the installed plugin set."""
41
+ load_backend_plugins(backend_registry)
42
+ return _build_entries(sorted(backend_registry.items))
43
+
44
+
45
+ @lru_cache
46
+ def target_entries() -> tuple[ConstantEntry, ...]:
47
+ """Return exported target constants for the installed plugin set."""
48
+ load_backend_plugins(backend_registry)
49
+ load_target_plugins(target_registry)
50
+ return _build_entries(sorted(target_registry.items))
51
+
52
+
53
+ @lru_cache
54
+ def target_profile_entries() -> tuple[ConstantEntry, ...]:
55
+ """Return exported target profile constants for the installed plugin set."""
56
+ load_backend_plugins(backend_registry)
57
+ load_target_plugins(target_registry)
58
+ profile_names = sorted(
59
+ profile_name
60
+ for profile_names in profiles_by_target().values()
61
+ for profile_name in profile_names
62
+ )
63
+ return _build_entries(profile_names)
64
+
65
+
66
+ @lru_cache
67
+ def exported_symbols(kind: str) -> tuple[str, ...]:
68
+ """Return exported symbol names for the requested constants kind."""
69
+ entries = _entries_for_kind(kind)
70
+ return tuple(entry.symbol for entry in entries)
71
+
72
+
73
+ @lru_cache
74
+ def exported_value(kind: str, symbol: str) -> str:
75
+ """Return the canonical value for the requested exported symbol."""
76
+ for entry in _entries_for_kind(kind):
77
+ if entry.symbol == symbol:
78
+ return entry.value
79
+ raise AttributeError(f"module has no attribute {symbol!r}")
80
+
81
+
82
+ @lru_cache
83
+ def exported_mapping(kind: str) -> dict[str, str]:
84
+ """Return the exported symbol-to-value mapping for the given kind."""
85
+ return {entry.symbol: entry.value for entry in _entries_for_kind(kind)}
86
+
87
+
88
+ def _entries_for_kind(kind: str) -> tuple[ConstantEntry, ...]:
89
+ if kind == "targets":
90
+ return target_entries()
91
+ if kind == "backends":
92
+ return backend_entries()
93
+ if kind == "target_profiles":
94
+ return target_profile_entries()
95
+ raise ValueError(f"Unknown constants kind: {kind}")
96
+
97
+
98
+ def _build_entries(values: Iterable[str]) -> tuple[ConstantEntry, ...]:
99
+ symbol_to_value: dict[str, str] = {}
100
+ for value in values:
101
+ symbol = normalize_constant_name(value)
102
+ existing = symbol_to_value.get(symbol)
103
+ if existing is not None and existing != value:
104
+ raise ValueError(
105
+ f"Constant symbol collision for {symbol!r}: {existing!r} vs {value!r}."
106
+ )
107
+ symbol_to_value[symbol] = value
108
+ return tuple(
109
+ ConstantEntry(symbol=symbol, value=value)
110
+ for symbol, value in sorted(symbol_to_value.items())
111
+ )