autofusex 0.2.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 (188) hide show
  1. afx/__init__.py +5 -0
  2. afx/__main__.py +5 -0
  3. autofusex/__init__.py +4 -0
  4. autofusex/__main__.py +5 -0
  5. autofusex/adapters/__init__.py +59 -0
  6. autofusex/adapters/base.py +44 -0
  7. autofusex/adapters/detection.py +59 -0
  8. autofusex/adapters/inductor_autofuse.py +38 -0
  9. autofusex/adapters/jax.py +20 -0
  10. autofusex/adapters/pytorch.py +635 -0
  11. autofusex/adapters/tensorflow.py +20 -0
  12. autofusex/agent.py +282 -0
  13. autofusex/artifact_io.py +56 -0
  14. autofusex/autofuse_graph.py +239 -0
  15. autofusex/camodel.py +86 -0
  16. autofusex/cli.py +599 -0
  17. autofusex/compare.py +1394 -0
  18. autofusex/fuzz/__init__.py +1 -0
  19. autofusex/fuzz/__main__.py +3 -0
  20. autofusex/fuzz/client/__init__.py +8 -0
  21. autofusex/fuzz/client/backend_names.py +3 -0
  22. autofusex/fuzz/client/backends/__init__.py +14 -0
  23. autofusex/fuzz/client/backends/autofuse_coverage.py +102 -0
  24. autofusex/fuzz/client/backends/base.py +36 -0
  25. autofusex/fuzz/client/backends/device_lease.py +51 -0
  26. autofusex/fuzz/client/backends/mlir_capability.py +49 -0
  27. autofusex/fuzz/client/backends/torch.py +196 -0
  28. autofusex/fuzz/client/case_spec.py +78 -0
  29. autofusex/fuzz/client/cli.py +275 -0
  30. autofusex/fuzz/client/config.py +169 -0
  31. autofusex/fuzz/client/contracts.py +200 -0
  32. autofusex/fuzz/client/core_logs.py +135 -0
  33. autofusex/fuzz/client/diagnostics.py +128 -0
  34. autofusex/fuzz/client/environment.py +68 -0
  35. autofusex/fuzz/client/execution.py +147 -0
  36. autofusex/fuzz/client/failure_details.py +90 -0
  37. autofusex/fuzz/client/generation/__init__.py +26 -0
  38. autofusex/fuzz/client/generation/categories.py +37 -0
  39. autofusex/fuzz/client/generation/fingerprint.py +16 -0
  40. autofusex/fuzz/client/generation/nnsmith_dynamic.py +65 -0
  41. autofusex/fuzz/client/generation/nnsmith_sampled.py +198 -0
  42. autofusex/fuzz/client/generation/operator_catalog.py +46 -0
  43. autofusex/fuzz/client/generation/runtime.py +20 -0
  44. autofusex/fuzz/client/generation/sampling.py +100 -0
  45. autofusex/fuzz/client/generation/torch_dialect.py +99 -0
  46. autofusex/fuzz/client/help.py +31 -0
  47. autofusex/fuzz/client/limits.py +7 -0
  48. autofusex/fuzz/client/nnsmith/__init__.py +5 -0
  49. autofusex/fuzz/client/nnsmith/aten_catalog.py +272 -0
  50. autofusex/fuzz/client/nnsmith/aten_dialect.py +335 -0
  51. autofusex/fuzz/client/resources.py +229 -0
  52. autofusex/fuzz/client/runtime.py +124 -0
  53. autofusex/fuzz/client/scheduling/__init__.py +1 -0
  54. autofusex/fuzz/client/scheduling/artifacts.py +97 -0
  55. autofusex/fuzz/client/scheduling/budgets.py +133 -0
  56. autofusex/fuzz/client/scheduling/campaign.py +70 -0
  57. autofusex/fuzz/client/scheduling/cli.py +156 -0
  58. autofusex/fuzz/client/scheduling/devices.py +24 -0
  59. autofusex/fuzz/client/scheduling/hosting.py +208 -0
  60. autofusex/fuzz/client/scheduling/ledger.py +201 -0
  61. autofusex/fuzz/client/scheduling/ownership.py +25 -0
  62. autofusex/fuzz/client/scheduling/placement.py +45 -0
  63. autofusex/fuzz/client/scheduling/pool.py +216 -0
  64. autofusex/fuzz/client/scheduling/stage_worker.py +191 -0
  65. autofusex/fuzz/client/scheduling/staged.py +470 -0
  66. autofusex/fuzz/client/scheduling/stages.py +65 -0
  67. autofusex/fuzz/client/scheduling/supervisor.py +314 -0
  68. autofusex/fuzz/client/scheduling/worker.py +72 -0
  69. autofusex/fuzz/client/storage/__init__.py +4 -0
  70. autofusex/fuzz/client/storage/comparison.py +31 -0
  71. autofusex/fuzz/client/storage/lifecycle.py +72 -0
  72. autofusex/fuzz/client/storage/queries.py +275 -0
  73. autofusex/fuzz/client/storage/records.py +102 -0
  74. autofusex/fuzz/client/storage/repository.py +181 -0
  75. autofusex/fuzz/client/storage/schema.py +47 -0
  76. autofusex/fuzz/client/storage/sqlite_utils.py +23 -0
  77. autofusex/fuzz/client/storage/stage_facts.py +129 -0
  78. autofusex/fuzz/client/storage/transfer.py +176 -0
  79. autofusex/fuzz/client/sync/__init__.py +1 -0
  80. autofusex/fuzz/client/sync/client.py +166 -0
  81. autofusex/fuzz/client/sync/daemon.py +8 -0
  82. autofusex/fuzz/client/sync/facts.py +182 -0
  83. autofusex/fuzz/client/sync/outbox.py +91 -0
  84. autofusex/fuzz/client/sync/retests.py +241 -0
  85. autofusex/fuzz/client/telemetry.py +27 -0
  86. autofusex/fuzz/client/tensors.py +34 -0
  87. autofusex/fuzz/daemon/__init__.py +24 -0
  88. autofusex/fuzz/daemon/client_update.py +4 -0
  89. autofusex/fuzz/daemon/management/__init__.py +1 -0
  90. autofusex/fuzz/daemon/management/agent_api.py +253 -0
  91. autofusex/fuzz/daemon/management/artifacts.py +158 -0
  92. autofusex/fuzz/daemon/management/cancellation.py +12 -0
  93. autofusex/fuzz/daemon/management/central.py +294 -0
  94. autofusex/fuzz/daemon/management/cli.py +366 -0
  95. autofusex/fuzz/daemon/management/client_updates.py +64 -0
  96. autofusex/fuzz/daemon/management/config.py +179 -0
  97. autofusex/fuzz/daemon/management/environments.py +184 -0
  98. autofusex/fuzz/daemon/management/operations.py +99 -0
  99. autofusex/fuzz/daemon/management/provenance.py +27 -0
  100. autofusex/fuzz/daemon/management/results.py +29 -0
  101. autofusex/fuzz/daemon/management/store.py +106 -0
  102. autofusex/fuzz/daemon/management/task_worker.py +63 -0
  103. autofusex/fuzz/daemon/management/tasks.py +148 -0
  104. autofusex/fuzz/daemon/management/updates.py +69 -0
  105. autofusex/fuzz/daemon/management/uploads.py +35 -0
  106. autofusex/fuzz/daemon/onboarding.py +53 -0
  107. autofusex/fuzz/daemon/runtime.py +255 -0
  108. autofusex/fuzz/daemon/supervisor.py +57 -0
  109. autofusex/fuzz/server/__init__.py +6 -0
  110. autofusex/fuzz/server/central/__init__.py +1 -0
  111. autofusex/fuzz/server/central/backup.py +28 -0
  112. autofusex/fuzz/server/central/cache.py +149 -0
  113. autofusex/fuzz/server/central/cleanup.py +56 -0
  114. autofusex/fuzz/server/central/control_api.py +195 -0
  115. autofusex/fuzz/server/central/issue_groups.py +320 -0
  116. autofusex/fuzz/server/central/maintenance.py +76 -0
  117. autofusex/fuzz/server/central/repairs.py +230 -0
  118. autofusex/fuzz/server/central/repository.py +203 -0
  119. autofusex/fuzz/server/central/retests.py +414 -0
  120. autofusex/fuzz/server/central/runtime.py +208 -0
  121. autofusex/fuzz/server/central/server.py +294 -0
  122. autofusex/fuzz/server/central/sessions.py +59 -0
  123. autofusex/fuzz/server/reporting/__init__.py +1 -0
  124. autofusex/fuzz/server/reporting/cases.py +171 -0
  125. autofusex/fuzz/server/reporting/compact.py +20 -0
  126. autofusex/fuzz/server/reporting/efficiency.py +98 -0
  127. autofusex/fuzz/server/reporting/failure_origin.py +197 -0
  128. autofusex/fuzz/server/reporting/incremental.py +251 -0
  129. autofusex/fuzz/server/reporting/index.py +169 -0
  130. autofusex/fuzz/server/reporting/materialized.py +217 -0
  131. autofusex/fuzz/server/reporting/outcomes.py +30 -0
  132. autofusex/fuzz/server/reporting/report.py +23 -0
  133. autofusex/fuzz/server/reporting/search.py +136 -0
  134. autofusex/fuzz/server/reporting/shared_content.py +16 -0
  135. autofusex/fuzz/server/reporting/statistics.py +131 -0
  136. autofusex/fuzz/server/view/__init__.py +1 -0
  137. autofusex/fuzz/server/view/server.py +139 -0
  138. autofusex/fuzz/server/view/static/app.js +581 -0
  139. autofusex/fuzz/server/view/static/charts.js +267 -0
  140. autofusex/fuzz/server/view/static/favicon.svg +8 -0
  141. autofusex/fuzz/server/view/static/index.html +137 -0
  142. autofusex/fuzz/server/view/static/issues.css +1 -0
  143. autofusex/fuzz/server/view/static/issues.js +55 -0
  144. autofusex/fuzz/server/view/static/manage.css +2 -0
  145. autofusex/fuzz/server/view/static/manage.html +1 -0
  146. autofusex/fuzz/server/view/static/manage.js +70 -0
  147. autofusex/fuzz/server/view/static/retests.css +22 -0
  148. autofusex/fuzz/server/view/static/retests.js +148 -0
  149. autofusex/fuzz/server/view/static/runtime.js +113 -0
  150. autofusex/fuzz/server/view/static/session.js +70 -0
  151. autofusex/fuzz/server/view/static/style.css +492 -0
  152. autofusex/graph.py +227 -0
  153. autofusex/html.py +3293 -0
  154. autofusex/inductor_autofuse.py +1586 -0
  155. autofusex/normalization.py +289 -0
  156. autofusex/npu_examples.py +1088 -0
  157. autofusex/platform/__init__.py +6 -0
  158. autofusex/platform/aggregates.py +160 -0
  159. autofusex/platform/auth.py +148 -0
  160. autofusex/platform/backup.py +161 -0
  161. autofusex/platform/cli.py +126 -0
  162. autofusex/platform/client.py +879 -0
  163. autofusex/platform/ingest.py +568 -0
  164. autofusex/platform/issues.py +620 -0
  165. autofusex/platform/knowledge.py +231 -0
  166. autofusex/platform/ops.py +175 -0
  167. autofusex/platform/profile.py +172 -0
  168. autofusex/platform/queries.py +283 -0
  169. autofusex/platform/regression.py +223 -0
  170. autofusex/platform/retests.py +307 -0
  171. autofusex/platform/schema.py +535 -0
  172. autofusex/platform/search.py +209 -0
  173. autofusex/platform/server.py +520 -0
  174. autofusex/platform/static/app.css +338 -0
  175. autofusex/platform/static/app.js +1398 -0
  176. autofusex/platform/static/favicon.svg +1 -0
  177. autofusex/platform/static/index.html +34 -0
  178. autofusex/platform/store.py +175 -0
  179. autofusex/progress.py +94 -0
  180. autofusex/runner.py +79 -0
  181. autofusex/script_runner.py +233 -0
  182. autofusex/shell_entry.py +298 -0
  183. autofusex/torch_model.py +1300 -0
  184. autofusex-0.2.0.dist-info/METADATA +241 -0
  185. autofusex-0.2.0.dist-info/RECORD +188 -0
  186. autofusex-0.2.0.dist-info/WHEEL +5 -0
  187. autofusex-0.2.0.dist-info/entry_points.txt +2 -0
  188. autofusex-0.2.0.dist-info/top_level.txt +2 -0
afx/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Public package for the afx command. Importing it has no runtime side effects."""
2
+
3
+ from autofusex import __version__
4
+
5
+ __all__ = ["__version__"]
afx/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ from autofusex.cli import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ raise SystemExit(main())
autofusex/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ """Autofuse debugging helpers. Importing the package has no runtime side effects."""
2
+
3
+ __all__ = ["__version__"]
4
+ __version__ = "0.2.0"
autofusex/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ from autofusex.cli import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ raise SystemExit(main())
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ from autofusex.adapters.base import BackendAdapter, CapturedInvocation, FrameworkAdapter
4
+ from autofusex.adapters.detection import detect_framework, find_cann_ge_root
5
+ from autofusex.adapters.jax import JaxAdapter
6
+ from autofusex.adapters.inductor_autofuse import InductorAutofuseBackend
7
+ from autofusex.adapters.pytorch import PyTorchAdapter
8
+ from autofusex.adapters.tensorflow import TensorFlowAdapter
9
+
10
+
11
+ _FRAMEWORK_ADAPTERS: dict[str, type[FrameworkAdapter]] = {
12
+ "pytorch": PyTorchAdapter,
13
+ "tensorflow": TensorFlowAdapter,
14
+ "jax": JaxAdapter,
15
+ }
16
+
17
+ _BACKEND_ADAPTERS: dict[str, type[BackendAdapter]] = {
18
+ "inductor_autofuse": InductorAutofuseBackend,
19
+ }
20
+
21
+
22
+ def framework_names() -> tuple[str, ...]:
23
+ return tuple(_FRAMEWORK_ADAPTERS)
24
+
25
+
26
+ def get_framework_adapter(name: str) -> FrameworkAdapter:
27
+ resolved = "pytorch" if name == "auto" else name
28
+ adapter_type = _FRAMEWORK_ADAPTERS.get(resolved)
29
+ if adapter_type is None:
30
+ raise ValueError(f"unsupported framework: {name}")
31
+ return adapter_type()
32
+
33
+
34
+ def backend_names() -> tuple[str, ...]:
35
+ return tuple(_BACKEND_ADAPTERS)
36
+
37
+
38
+ def get_backend_adapter(name: str) -> BackendAdapter:
39
+ adapter_type = _BACKEND_ADAPTERS.get(name)
40
+ if adapter_type is None:
41
+ raise ValueError(f"unsupported backend: {name}")
42
+ return adapter_type()
43
+
44
+
45
+ __all__ = [
46
+ "BackendAdapter",
47
+ "CapturedInvocation",
48
+ "FrameworkAdapter",
49
+ "JaxAdapter",
50
+ "InductorAutofuseBackend",
51
+ "PyTorchAdapter",
52
+ "TensorFlowAdapter",
53
+ "backend_names",
54
+ "detect_framework",
55
+ "find_cann_ge_root",
56
+ "framework_names",
57
+ "get_backend_adapter",
58
+ "get_framework_adapter",
59
+ ]
@@ -0,0 +1,44 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import ABC, abstractmethod
4
+ from dataclasses import dataclass, field
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class CapturedInvocation:
11
+ framework: str
12
+ model: Any
13
+ args: tuple[Any, ...]
14
+ kwargs: dict[str, Any]
15
+ name: str
16
+ metadata: dict[str, Any] = field(default_factory=dict)
17
+
18
+
19
+ class FrameworkAdapter(ABC):
20
+ name: str
21
+ implemented: bool = False
22
+
23
+ @abstractmethod
24
+ def capture(
25
+ self,
26
+ *,
27
+ script: str | Path,
28
+ script_args: tuple[str, ...] = (),
29
+ capture_call: int = 0,
30
+ module_pattern: str | None = None,
31
+ ) -> CapturedInvocation:
32
+ raise NotImplementedError
33
+
34
+
35
+ class BackendAdapter(ABC):
36
+ name: str
37
+ supported_frameworks: tuple[str, ...]
38
+
39
+ def supports(self, framework: str) -> bool:
40
+ return framework in self.supported_frameworks
41
+
42
+ @abstractmethod
43
+ def run(self, invocation: CapturedInvocation, **kwargs: Any) -> dict[str, Any]:
44
+ raise NotImplementedError
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+
3
+ import ast
4
+ from pathlib import Path
5
+
6
+
7
+ _FRAMEWORK_MODULES = {
8
+ "torch": "pytorch",
9
+ "torch_npu": "pytorch",
10
+ "torchair": "pytorch",
11
+ "inductor_npu_ext": "pytorch",
12
+ "tensorflow": "tensorflow",
13
+ "jax": "jax",
14
+ }
15
+
16
+
17
+ def find_cann_ge_root(script: str | Path) -> Path | None:
18
+ """Find the repository root that provides a cann-ge/Baize ``libs`` package."""
19
+ path = Path(script).resolve()
20
+ for candidate in (path.parent, *path.parents):
21
+ if (candidate / "libs" / "__init__.py").is_file() and (candidate / "feature").is_dir():
22
+ return candidate
23
+ return None
24
+
25
+
26
+ def _import_roots(tree: ast.AST) -> set[str]:
27
+ roots: set[str] = set()
28
+ for node in ast.walk(tree):
29
+ if isinstance(node, ast.Import):
30
+ names = (item.name for item in node.names)
31
+ elif isinstance(node, ast.ImportFrom) and node.module:
32
+ names = (node.module,)
33
+ else:
34
+ continue
35
+ roots.update(name.split(".", 1)[0] for name in names)
36
+ return roots
37
+
38
+
39
+ def detect_framework(script: str | Path) -> str:
40
+ """Detect the model framework from imports without executing the script."""
41
+ path = Path(script).resolve()
42
+ try:
43
+ tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
44
+ except (OSError, UnicodeError, SyntaxError) as exc:
45
+ raise ValueError(f"cannot inspect framework imports in {path}: {exc}") from exc
46
+
47
+ roots = _import_roots(tree)
48
+ detected = {framework for module, framework in _FRAMEWORK_MODULES.items() if module in roots}
49
+ if len(detected) > 1:
50
+ names = ", ".join(sorted(detected))
51
+ raise ValueError(
52
+ f"framework auto-detection found multiple frameworks in {path}: {names}; "
53
+ "pass --framework explicitly"
54
+ )
55
+ if detected:
56
+ return detected.pop()
57
+
58
+ # Keep old scripts working when the model class is imported from another module.
59
+ return "pytorch"
@@ -0,0 +1,38 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from autofusex.adapters.base import BackendAdapter, CapturedInvocation
6
+
7
+
8
+ class InductorAutofuseBackend(BackendAdapter):
9
+ name = "inductor_autofuse"
10
+ supported_frameworks = ("pytorch",)
11
+
12
+ def run(self, invocation: CapturedInvocation, **kwargs: Any) -> dict[str, Any]:
13
+ if not self.supports(invocation.framework):
14
+ raise ValueError(f"{self.name} does not support framework {invocation.framework}")
15
+
16
+ from autofusex.torch_model import TorchCase, run_torch_case
17
+
18
+ case = TorchCase(
19
+ model=invocation.model,
20
+ inputs=invocation.args,
21
+ kwargs=invocation.kwargs,
22
+ name=str(kwargs.pop("name", None) or invocation.name),
23
+ fullgraph=bool(kwargs.pop("fullgraph", False)),
24
+ dynamic=bool(kwargs.pop("dynamic", False)),
25
+ training=invocation.metadata.get("execution", {}).get("training"),
26
+ grad_enabled=bool(invocation.metadata.get("execution", {}).get("grad_enabled", True)),
27
+ autocast=dict(invocation.metadata.get("execution", {}).get("autocast", {})),
28
+ rewrite_device_hints=bool(kwargs.pop("rewrite_device_hints", False)),
29
+ )
30
+ script = invocation.metadata.get("script")
31
+ if not script:
32
+ raise ValueError("captured invocation does not contain its source script")
33
+ return run_torch_case(
34
+ case=case,
35
+ script=script,
36
+ invocation_metadata=invocation.metadata,
37
+ **kwargs,
38
+ )
@@ -0,0 +1,20 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ from autofusex.adapters.base import CapturedInvocation, FrameworkAdapter
6
+
7
+
8
+ class JaxAdapter(FrameworkAdapter):
9
+ name = "jax"
10
+
11
+ def capture(
12
+ self,
13
+ *,
14
+ script: str | Path,
15
+ script_args: tuple[str, ...] = (),
16
+ capture_call: int = 0,
17
+ module_pattern: str | None = None,
18
+ ) -> CapturedInvocation:
19
+ del script, script_args, capture_call, module_pattern
20
+ raise NotImplementedError("JaxAdapter is reserved but not implemented")