mlx-agent 0.9.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 (230) hide show
  1. mlx_agent/__init__.py +6 -0
  2. mlx_agent/__main__.py +9 -0
  3. mlx_agent/_lab/video_lab/__init__.py +24 -0
  4. mlx_agent/_lab/video_lab/adapter_protocol.py +152 -0
  5. mlx_agent/_lab/video_lab/adapter_registry.py +300 -0
  6. mlx_agent/_lab/video_lab/adapters/__init__.py +1 -0
  7. mlx_agent/_lab/video_lab/adapters/animegen_mps.py +1242 -0
  8. mlx_agent/_lab/video_lab/adapters/fake.py +164 -0
  9. mlx_agent/_lab/video_lab/adapters/wan_mps.py +523 -0
  10. mlx_agent/_lab/video_lab/adaptive_study_models.py +415 -0
  11. mlx_agent/_lab/video_lab/adaptive_study_repository.py +1069 -0
  12. mlx_agent/_lab/video_lab/adaptive_study_service.py +810 -0
  13. mlx_agent/_lab/video_lab/adaptive_web_creation_repository.py +250 -0
  14. mlx_agent/_lab/video_lab/animegen_feasibility.py +596 -0
  15. mlx_agent/_lab/video_lab/animegen_pair_contract.py +6 -0
  16. mlx_agent/_lab/video_lab/artifacts.py +988 -0
  17. mlx_agent/_lab/video_lab/capabilities.py +82 -0
  18. mlx_agent/_lab/video_lab/character_benchmark_analysis.py +283 -0
  19. mlx_agent/_lab/video_lab/character_benchmark_models.py +264 -0
  20. mlx_agent/_lab/video_lab/character_benchmark_protocol.py +304 -0
  21. mlx_agent/_lab/video_lab/character_benchmark_repository.py +919 -0
  22. mlx_agent/_lab/video_lab/character_benchmark_service.py +1062 -0
  23. mlx_agent/_lab/video_lab/character_images.py +62 -0
  24. mlx_agent/_lab/video_lab/character_models.py +110 -0
  25. mlx_agent/_lab/video_lab/character_pack.py +177 -0
  26. mlx_agent/_lab/video_lab/character_repository.py +691 -0
  27. mlx_agent/_lab/video_lab/character_service.py +528 -0
  28. mlx_agent/_lab/video_lab/character_web_grant_repository.py +174 -0
  29. mlx_agent/_lab/video_lab/cli.py +2801 -0
  30. mlx_agent/_lab/video_lab/comparison.py +70 -0
  31. mlx_agent/_lab/video_lab/compilers/__init__.py +5 -0
  32. mlx_agent/_lab/video_lab/compilers/wan_curated.py +473 -0
  33. mlx_agent/_lab/video_lab/curated_ids.py +16 -0
  34. mlx_agent/_lab/video_lab/curated_metrics.py +86 -0
  35. mlx_agent/_lab/video_lab/curated_models.py +269 -0
  36. mlx_agent/_lab/video_lab/curated_source.py +468 -0
  37. mlx_agent/_lab/video_lab/curated_splits.py +279 -0
  38. mlx_agent/_lab/video_lab/curated_validation.py +557 -0
  39. mlx_agent/_lab/video_lab/database.py +6351 -0
  40. mlx_agent/_lab/video_lab/dataset_cli.py +1324 -0
  41. mlx_agent/_lab/video_lab/dataset_compiler.py +565 -0
  42. mlx_agent/_lab/video_lab/dataset_receipts.py +547 -0
  43. mlx_agent/_lab/video_lab/domain.py +249 -0
  44. mlx_agent/_lab/video_lab/evidence_service.py +525 -0
  45. mlx_agent/_lab/video_lab/feasibility.py +689 -0
  46. mlx_agent/_lab/video_lab/feasibility_models.py +300 -0
  47. mlx_agent/_lab/video_lab/feasibility_projection.py +531 -0
  48. mlx_agent/_lab/video_lab/feasibility_repository.py +900 -0
  49. mlx_agent/_lab/video_lab/feasibility_telemetry.py +128 -0
  50. mlx_agent/_lab/video_lab/host_canaries/__init__.py +29 -0
  51. mlx_agent/_lab/video_lab/host_canaries/wan_curated.py +1046 -0
  52. mlx_agent/_lab/video_lab/host_canaries/wan_qualification.py +1555 -0
  53. mlx_agent/_lab/video_lab/launcher.py +13 -0
  54. mlx_agent/_lab/video_lab/local_authority.py +689 -0
  55. mlx_agent/_lab/video_lab/normal_generation.py +161 -0
  56. mlx_agent/_lab/video_lab/operations.py +118 -0
  57. mlx_agent/_lab/video_lab/preference_optimizer.py +560 -0
  58. mlx_agent/_lab/video_lab/py.typed +0 -0
  59. mlx_agent/_lab/video_lab/queue_service.py +198 -0
  60. mlx_agent/_lab/video_lab/repositories.py +1293 -0
  61. mlx_agent/_lab/video_lab/review_service.py +545 -0
  62. mlx_agent/_lab/video_lab/reviews.py +452 -0
  63. mlx_agent/_lab/video_lab/runtime_identity.py +87 -0
  64. mlx_agent/_lab/video_lab/services.py +137 -0
  65. mlx_agent/_lab/video_lab/source_inventory.py +556 -0
  66. mlx_agent/_lab/video_lab/states.py +26 -0
  67. mlx_agent/_lab/video_lab/telemetry.py +54 -0
  68. mlx_agent/_lab/video_lab/trainer_protocol.py +855 -0
  69. mlx_agent/_lab/video_lab/trainers/__init__.py +106 -0
  70. mlx_agent/_lab/video_lab/trainers/fake.py +434 -0
  71. mlx_agent/_lab/video_lab/trainers/wan_batch.py +314 -0
  72. mlx_agent/_lab/video_lab/trainers/wan_branch_loader.py +623 -0
  73. mlx_agent/_lab/video_lab/trainers/wan_branch_runtime.py +916 -0
  74. mlx_agent/_lab/video_lab/trainers/wan_checkpoint.py +1642 -0
  75. mlx_agent/_lab/video_lab/trainers/wan_continuity.py +147 -0
  76. mlx_agent/_lab/video_lab/trainers/wan_diffusers_runtime.py +1289 -0
  77. mlx_agent/_lab/video_lab/trainers/wan_factory.py +1069 -0
  78. mlx_agent/_lab/video_lab/trainers/wan_mps.py +1442 -0
  79. mlx_agent/_lab/video_lab/trainers/wan_production_models.py +735 -0
  80. mlx_agent/_lab/video_lab/training_data.py +181 -0
  81. mlx_agent/_lab/video_lab/training_data_cli.py +66 -0
  82. mlx_agent/_lab/video_lab/training_dataset.py +206 -0
  83. mlx_agent/_lab/video_lab/training_media.py +586 -0
  84. mlx_agent/_lab/video_lab/training_models.py +1041 -0
  85. mlx_agent/_lab/video_lab/training_repository.py +1822 -0
  86. mlx_agent/_lab/video_lab/training_service.py +2759 -0
  87. mlx_agent/_lab/video_lab/validation_analysis.py +154 -0
  88. mlx_agent/_lab/video_lab/validation_models.py +263 -0
  89. mlx_agent/_lab/video_lab/validation_panel.py +151 -0
  90. mlx_agent/_lab/video_lab/validation_repository.py +641 -0
  91. mlx_agent/_lab/video_lab/validation_service.py +818 -0
  92. mlx_agent/_lab/video_lab/wan_pending.py +174 -0
  93. mlx_agent/_lab/video_lab/worker.py +525 -0
  94. mlx_agent/_lab/video_lab/worker_control.py +21 -0
  95. mlx_agent/_lab/video_lab/worker_supervisor.py +327 -0
  96. mlx_agent/adoption.py +870 -0
  97. mlx_agent/atomicio.py +11 -0
  98. mlx_agent/backend_install.py +255 -0
  99. mlx_agent/backend_runner.py +63 -0
  100. mlx_agent/backends.py +676 -0
  101. mlx_agent/bench.py +445 -0
  102. mlx_agent/blueprint.py +128 -0
  103. mlx_agent/capture_platform.py +179 -0
  104. mlx_agent/capture_volume.py +266 -0
  105. mlx_agent/cli.py +2570 -0
  106. mlx_agent/coding_capture_client.py +138 -0
  107. mlx_agent/coding_capture_contracts.py +244 -0
  108. mlx_agent/coding_capture_plugins.py +263 -0
  109. mlx_agent/coding_capture_policy.py +121 -0
  110. mlx_agent/coding_capture_process.py +179 -0
  111. mlx_agent/coding_capture_storage.py +444 -0
  112. mlx_agent/command_args.py +508 -0
  113. mlx_agent/command_executor.py +74 -0
  114. mlx_agent/compute.py +174 -0
  115. mlx_agent/contextfit.py +87 -0
  116. mlx_agent/contracts.py +98 -0
  117. mlx_agent/convert.py +549 -0
  118. mlx_agent/convert_queue.py +532 -0
  119. mlx_agent/decide.py +145 -0
  120. mlx_agent/decide_runner.py +31 -0
  121. mlx_agent/describe.py +182 -0
  122. mlx_agent/describe_runner.py +125 -0
  123. mlx_agent/discovery.py +528 -0
  124. mlx_agent/fetch_runner.py +64 -0
  125. mlx_agent/fleet.py +277 -0
  126. mlx_agent/fuse.py +213 -0
  127. mlx_agent/generate.py +124 -0
  128. mlx_agent/generate_runner.py +36 -0
  129. mlx_agent/gguf.py +1038 -0
  130. mlx_agent/gguf_runner.py +242 -0
  131. mlx_agent/host.py +54 -0
  132. mlx_agent/huggingface.py +683 -0
  133. mlx_agent/installer.py +829 -0
  134. mlx_agent/intake.py +387 -0
  135. mlx_agent/intake_fetch.py +179 -0
  136. mlx_agent/intake_source.py +106 -0
  137. mlx_agent/interview.py +302 -0
  138. mlx_agent/jit_serve.py +564 -0
  139. mlx_agent/lab.py +146 -0
  140. mlx_agent/lab_adoption.py +193 -0
  141. mlx_agent/lab_studies.py +52 -0
  142. mlx_agent/lab_workspace.py +246 -0
  143. mlx_agent/lora.py +568 -0
  144. mlx_agent/mcp_server.py +243 -0
  145. mlx_agent/modality.py +283 -0
  146. mlx_agent/model_doctor.py +502 -0
  147. mlx_agent/models.py +184 -0
  148. mlx_agent/music.py +90 -0
  149. mlx_agent/music_requantize_runner.py +71 -0
  150. mlx_agent/music_runner.py +89 -0
  151. mlx_agent/port_analysis.py +181 -0
  152. mlx_agent/port_plan.py +113 -0
  153. mlx_agent/probe_assets.py +116 -0
  154. mlx_agent/project_blueprint.py +257 -0
  155. mlx_agent/providers.py +523 -0
  156. mlx_agent/queue_bridge.py +139 -0
  157. mlx_agent/queue_cli.py +190 -0
  158. mlx_agent/research.py +502 -0
  159. mlx_agent/resources/adapter-runtime.json +4 -0
  160. mlx_agent/resources/backends/mflux.json +39 -0
  161. mlx_agent/resources/backends/mflux.lock +1447 -0
  162. mlx_agent/resources/backends/mlx-audio.json +176 -0
  163. mlx_agent/resources/backends/mlx-audio.lock +1543 -0
  164. mlx_agent/resources/backends/mlx-embeddings.json +50 -0
  165. mlx_agent/resources/backends/mlx-embeddings.lock +1576 -0
  166. mlx_agent/resources/backends/mlx-lm.json +123 -0
  167. mlx_agent/resources/backends/mlx-video.json +27 -0
  168. mlx_agent/resources/backends/mlx-video.lock +1635 -0
  169. mlx_agent/resources/backends/mlx-vlm.json +356 -0
  170. mlx_agent/resources/backends/mlx-vlm.lock +1495 -0
  171. mlx_agent/resources/bench-community.json +4 -0
  172. mlx_agent/resources/coding_capture/freeze.mjs +99 -0
  173. mlx_agent/resources/coding_capture/legacy.mjs +77 -0
  174. mlx_agent/resources/coding_capture/proxy.mjs +47 -0
  175. mlx_agent/resources/coding_capture/rpc.mjs +54 -0
  176. mlx_agent/resources/coding_capture/worker.mjs +36 -0
  177. mlx_agent/resources/ports/mflux/qwen_image_21/__init__.py +5 -0
  178. mlx_agent/resources/ports/mflux/qwen_image_21/convert.py +81 -0
  179. mlx_agent/resources/ports/mflux/qwen_image_21/qwen_image_21.py +73 -0
  180. mlx_agent/resources/ports/mlx-audio/audio8_asr_infinite/__init__.py +4 -0
  181. mlx_agent/resources/ports/mlx-audio/audio8_asr_infinite/audio.py +96 -0
  182. mlx_agent/resources/ports/mlx-audio/audio8_asr_infinite/audio8_asr_infinite.py +494 -0
  183. mlx_agent/resources/ports/mlx-audio/audio8_asr_infinite/config.py +106 -0
  184. mlx_agent/resources/ports/mlx-embeddings/laya/__init__.py +5 -0
  185. mlx_agent/resources/ports/mlx-embeddings/laya/convert.py +94 -0
  186. mlx_agent/resources/ports/mlx-embeddings/laya/laya.py +337 -0
  187. mlx_agent/resources/ports/mlx-lm/deepseek_v4_dspark/__init__.py +1 -0
  188. mlx_agent/resources/ports/mlx-lm/deepseek_v4_dspark/convert.py +311 -0
  189. mlx_agent/resources/ports/mlx-video/t2v/__init__.py +6 -0
  190. mlx_agent/resources/ports/mlx-video/t2v/convert.py +87 -0
  191. mlx_agent/resources/ports/mlx-video/t2v/t2v.py +145 -0
  192. mlx_agent/resources/ports/mlx-video/t2v/training.py +292 -0
  193. mlx_agent/resources/ports/mlx-video/t2v/training_inputs.py +253 -0
  194. mlx_agent/resources/references/model-families.md +35 -0
  195. mlx_agent/resources/references/quantization.md +25 -0
  196. mlx_agent/resources/references/troubleshooting.md +33 -0
  197. mlx_agent/resources/serve-recipes.json +30 -0
  198. mlx_agent/runtime_preference.py +142 -0
  199. mlx_agent/scoring.py +194 -0
  200. mlx_agent/serve.py +972 -0
  201. mlx_agent/speak.py +161 -0
  202. mlx_agent/speak_runner.py +73 -0
  203. mlx_agent/strata_runtime.py +277 -0
  204. mlx_agent/study_recipes.py +206 -0
  205. mlx_agent/task_cli.py +92 -0
  206. mlx_agent/task_contracts.py +313 -0
  207. mlx_agent/task_identity.py +60 -0
  208. mlx_agent/task_mp4_validator.py +46 -0
  209. mlx_agent/task_png_validator.py +25 -0
  210. mlx_agent/task_runtime.py +500 -0
  211. mlx_agent/task_store.py +476 -0
  212. mlx_agent/task_worker.py +19 -0
  213. mlx_agent/taxonomy.py +266 -0
  214. mlx_agent/training_artifacts.py +43 -0
  215. mlx_agent/training_eval_runtime.py +31 -0
  216. mlx_agent/training_evaluation.py +235 -0
  217. mlx_agent/training_runner.py +30 -0
  218. mlx_agent/transactions.py +1362 -0
  219. mlx_agent/transcribe.py +107 -0
  220. mlx_agent/transcribe_runner.py +66 -0
  221. mlx_agent/verification.py +1163 -0
  222. mlx_agent/video.py +182 -0
  223. mlx_agent/video_runner.py +38 -0
  224. mlx_agent/watch.py +206 -0
  225. mlx_agent/wiring.py +353 -0
  226. mlx_agent-0.9.0.dist-info/METADATA +212 -0
  227. mlx_agent-0.9.0.dist-info/RECORD +230 -0
  228. mlx_agent-0.9.0.dist-info/WHEEL +4 -0
  229. mlx_agent-0.9.0.dist-info/entry_points.txt +3 -0
  230. mlx_agent-0.9.0.dist-info/licenses/LICENSE +21 -0
mlx_agent/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """Public API for the dependency-free MLX agent core."""
2
+
3
+ from .contracts import ResultEnvelope
4
+
5
+ __all__ = ["ResultEnvelope"]
6
+ __version__ = "0.9.0"
mlx_agent/__main__.py ADDED
@@ -0,0 +1,9 @@
1
+ """Run the MLX agent core with ``python -m mlx_agent``."""
2
+
3
+ import sys
4
+
5
+ from .cli import main
6
+
7
+
8
+ if __name__ == "__main__":
9
+ sys.exit(main())
@@ -0,0 +1,24 @@
1
+ __version__ = "0.1.0"
2
+
3
+ from .curated_ids import curated_dataset_digest, structured_caption_digest
4
+ from .curated_models import (
5
+ CuratedDatasetManifestV1,
6
+ CuratedFrameV1,
7
+ CuratedSequenceV1,
8
+ DatasetSplitPolicyV1,
9
+ SequenceTransformRecipeV1,
10
+ StructuredCaptionV1,
11
+ render_caption_v1,
12
+ )
13
+
14
+ __all__ = (
15
+ "CuratedDatasetManifestV1",
16
+ "CuratedFrameV1",
17
+ "CuratedSequenceV1",
18
+ "DatasetSplitPolicyV1",
19
+ "SequenceTransformRecipeV1",
20
+ "StructuredCaptionV1",
21
+ "curated_dataset_digest",
22
+ "render_caption_v1",
23
+ "structured_caption_digest",
24
+ )
@@ -0,0 +1,152 @@
1
+ import json
2
+ import math
3
+ from collections.abc import Callable, Mapping, Sequence, Set
4
+ from dataclasses import dataclass
5
+ from enum import StrEnum
6
+ from pathlib import Path
7
+ from types import MappingProxyType
8
+ from typing import Protocol, runtime_checkable
9
+
10
+ from pydantic import Field, field_serializer, field_validator
11
+
12
+ from video_lab.capabilities import AdapterCapabilities
13
+ from video_lab.domain import FrozenModel, Manifest
14
+
15
+
16
+ class GenerationRequest(FrozenModel):
17
+ job_id: str
18
+ attempt_id: str
19
+ manifest: Manifest
20
+ scratch_root: Path
21
+
22
+
23
+ class GenerationProgress(FrozenModel):
24
+ phase: str
25
+ completed: int = Field(ge=0)
26
+ total: int = Field(gt=0)
27
+ message: str
28
+ elapsed_seconds: float = Field(ge=0)
29
+
30
+
31
+ class GenerationResult(FrozenModel):
32
+ video_path: Path
33
+ effective_manifest: Manifest
34
+ frame_count: int = Field(gt=0)
35
+ fps: int = Field(gt=0)
36
+ width: int = Field(gt=0)
37
+ height: int = Field(gt=0)
38
+ adapter_version: str
39
+ runtime_versions: Mapping[str, str]
40
+ adapter_telemetry: Mapping[str, object]
41
+
42
+ @field_validator("runtime_versions")
43
+ @classmethod
44
+ def freeze_runtime_versions(cls, value: Mapping[str, str]) -> Mapping[str, str]:
45
+ return MappingProxyType(dict(value))
46
+
47
+ @field_validator("adapter_telemetry")
48
+ @classmethod
49
+ def freeze_adapter_telemetry(cls, value: object) -> Mapping[str, object]:
50
+ frozen = _freeze_json(value)
51
+ if not isinstance(frozen, Mapping):
52
+ raise TypeError("adapter telemetry must be a mapping")
53
+ return frozen
54
+
55
+ @field_serializer("runtime_versions")
56
+ def serialize_runtime_versions(self, value: Mapping[str, str]) -> dict[str, str]:
57
+ return dict(value)
58
+
59
+ @field_serializer("adapter_telemetry")
60
+ def serialize_adapter_telemetry(self, value: Mapping[str, object]) -> dict[str, object]:
61
+ serialized = _serialize_json(value)
62
+ if not isinstance(serialized, dict):
63
+ raise TypeError("adapter telemetry must serialize to a mapping")
64
+ return serialized
65
+
66
+
67
+ def _freeze_json(value: object) -> object:
68
+ if isinstance(value, float) and not math.isfinite(value):
69
+ raise ValueError("unsupported non-finite JSON number")
70
+ if value is None or isinstance(value, str | int | float | bool):
71
+ return value
72
+ if isinstance(value, Mapping):
73
+ if not all(isinstance(key, str) for key in value):
74
+ raise TypeError("adapter telemetry mapping keys must be strings")
75
+ return MappingProxyType({key: _freeze_json(item) for key, item in value.items()})
76
+ if isinstance(value, Set):
77
+ frozen = tuple(_freeze_json(item) for item in value)
78
+ return tuple(sorted(frozen, key=_json_order))
79
+ if isinstance(value, Sequence) and not isinstance(value, str | bytes | bytearray):
80
+ return tuple(_freeze_json(item) for item in value)
81
+ raise TypeError(f"unsupported adapter telemetry value: {type(value).__name__}")
82
+
83
+
84
+ def _serialize_json(value: object) -> object:
85
+ if isinstance(value, float) and not math.isfinite(value):
86
+ raise ValueError("unsupported non-finite JSON number")
87
+ if isinstance(value, Mapping):
88
+ return {str(key): _serialize_json(item) for key, item in value.items()}
89
+ if isinstance(value, tuple):
90
+ return [_serialize_json(item) for item in value]
91
+ return value
92
+
93
+
94
+ def _json_order(value: object) -> str:
95
+ return json.dumps(_serialize_json(value), sort_keys=True)
96
+
97
+
98
+ class GenerationCancelled(Exception):
99
+ """Raised when generation is cancelled before artifact finalization."""
100
+
101
+
102
+ class AdapterExecutionError(Exception):
103
+ """Raised when an adapter cannot complete generation."""
104
+
105
+
106
+ ProgressCallback = Callable[[GenerationProgress], None]
107
+ CancellationCheck = Callable[[], bool]
108
+
109
+
110
+ class ProbePhase(StrEnum):
111
+ ENVIRONMENT = "environment"
112
+ METADATA = "metadata"
113
+ CACHE = "cache"
114
+ LOAD = "load"
115
+ GENERATE = "generate"
116
+
117
+
118
+ @dataclass(frozen=True)
119
+ class ProbeReport:
120
+ phase: ProbePhase | str
121
+ ok: bool
122
+ diagnostics: Mapping[str, object]
123
+
124
+
125
+ @dataclass(frozen=True)
126
+ class ProbeRequest:
127
+ generation: GenerationRequest
128
+ progress: ProgressCallback
129
+ cancelled: CancellationCheck
130
+
131
+
132
+ @runtime_checkable
133
+ class GenerationAdapter(Protocol):
134
+ adapter_id: str
135
+
136
+ def capabilities(self) -> AdapterCapabilities: ...
137
+
138
+ def probe(self) -> bool: ...
139
+
140
+ def generate(
141
+ self,
142
+ request: GenerationRequest,
143
+ progress: ProgressCallback,
144
+ cancelled: CancellationCheck,
145
+ ) -> GenerationResult: ...
146
+
147
+
148
+ @runtime_checkable
149
+ class StagedProbeAdapter(GenerationAdapter, Protocol):
150
+ def probe_phase(
151
+ self, phase: ProbePhase, request: ProbeRequest | None = None
152
+ ) -> ProbeReport: ...
@@ -0,0 +1,300 @@
1
+ from collections.abc import Callable
2
+ from typing import Protocol
3
+
4
+ from video_lab.adapter_protocol import GenerationAdapter
5
+ from video_lab.adapters.animegen_mps import AnimeGenStorageMode
6
+ from video_lab.capabilities import AdapterCapabilities
7
+ from video_lab.domain import FrozenModel
8
+ from video_lab.feasibility_models import SupportVerdict
9
+ from video_lab.feasibility_repository import GenerationAuthorizationBundle
10
+
11
+ AdapterFactory = Callable[[], GenerationAdapter]
12
+ CapabilitiesFactory = Callable[[], AdapterCapabilities]
13
+
14
+
15
+ class FeasibilityAuthorizationRepository(Protocol):
16
+ def generation_authorization_bundle(
17
+ self, adapter_id: str
18
+ ) -> GenerationAuthorizationBundle | None: ...
19
+
20
+
21
+ class AdapterMetadata(FrozenModel):
22
+ adapter_id: str
23
+ display_name: str
24
+ source_model: str | None = None
25
+ frame_rule: str | None = None
26
+ declared_profiles: tuple[str, ...] = ()
27
+ generation_enabled: bool = True
28
+
29
+
30
+ MetadataFactory = Callable[[], AdapterMetadata]
31
+
32
+
33
+ class _Registration:
34
+ def __init__(
35
+ self,
36
+ factory: AdapterFactory,
37
+ metadata_factory: MetadataFactory | None,
38
+ capabilities_factory: CapabilitiesFactory | None,
39
+ ) -> None:
40
+ self.factory = factory
41
+ self.metadata_factory = metadata_factory
42
+ self.capabilities_factory = capabilities_factory
43
+
44
+
45
+ class UnknownAdapterError(LookupError):
46
+ """Raised when an exact adapter ID is not registered."""
47
+
48
+
49
+ class AdapterRegistry:
50
+ def __init__(self) -> None:
51
+ self._registrations: dict[str, _Registration] = {}
52
+
53
+ def register(
54
+ self,
55
+ adapter_id: str,
56
+ factory: AdapterFactory,
57
+ *,
58
+ metadata_factory: MetadataFactory | None = None,
59
+ capabilities_factory: CapabilitiesFactory | None = None,
60
+ ) -> None:
61
+ if adapter_id in self._registrations:
62
+ raise ValueError(f"adapter {adapter_id!r} is already registered")
63
+ self._registrations[adapter_id] = _Registration(
64
+ factory, metadata_factory, capabilities_factory
65
+ )
66
+
67
+ def resolve(self, adapter_id: str) -> GenerationAdapter:
68
+ try:
69
+ registration = self._registrations[adapter_id]
70
+ except KeyError as error:
71
+ raise UnknownAdapterError(f"unknown adapter: {adapter_id}") from error
72
+ return registration.factory()
73
+
74
+ def catalog_metadata(self) -> tuple[tuple[AdapterMetadata, AdapterCapabilities], ...]:
75
+ catalog: list[tuple[AdapterMetadata, AdapterCapabilities]] = []
76
+ for adapter_id, registration in self._registrations.items():
77
+ if registration.metadata_factory is None or registration.capabilities_factory is None:
78
+ continue
79
+ metadata = registration.metadata_factory()
80
+ capabilities = registration.capabilities_factory()
81
+ if metadata.adapter_id != adapter_id:
82
+ raise ValueError(
83
+ f"catalog metadata does not match registered adapter {adapter_id!r}"
84
+ )
85
+ self._validate_capabilities_identity(adapter_id, capabilities)
86
+ catalog.append((metadata, capabilities))
87
+ return tuple(catalog)
88
+
89
+ def capabilities(self, adapter_id: str) -> AdapterCapabilities:
90
+ try:
91
+ registration = self._registrations[adapter_id]
92
+ except KeyError as error:
93
+ raise UnknownAdapterError(f"unknown adapter: {adapter_id}") from error
94
+ capabilities = (
95
+ registration.factory().capabilities()
96
+ if registration.capabilities_factory is None
97
+ else registration.capabilities_factory()
98
+ )
99
+ self._validate_capabilities_identity(adapter_id, capabilities)
100
+ return capabilities
101
+
102
+ @staticmethod
103
+ def _validate_capabilities_identity(adapter_id: str, capabilities: AdapterCapabilities) -> None:
104
+ if capabilities.adapter_id != adapter_id:
105
+ raise ValueError(f"capabilities do not match registered adapter {adapter_id!r}")
106
+
107
+ @classmethod
108
+ def with_defaults(
109
+ cls,
110
+ *,
111
+ feasibility_repository: FeasibilityAuthorizationRepository | None = None,
112
+ animegen_runtime_factory: Callable[[GenerationAuthorizationBundle], object] | None = None,
113
+ ) -> "AdapterRegistry":
114
+ registry = cls()
115
+
116
+ def fake_factory() -> GenerationAdapter:
117
+ from video_lab.adapters.fake import FakeVideoAdapter
118
+
119
+ return FakeVideoAdapter()
120
+
121
+ def fake_capabilities() -> AdapterCapabilities:
122
+ return AdapterCapabilities(
123
+ adapter_id="video-lab.fake.v1",
124
+ model_patterns=("*",),
125
+ backends=("cpu",),
126
+ dtypes=("uint8",),
127
+ quantizations=("none",),
128
+ schedulers=("fake",),
129
+ min_width=1,
130
+ max_width=4096,
131
+ width_multiple=1,
132
+ min_height=1,
133
+ max_height=4096,
134
+ height_multiple=1,
135
+ min_frames=17,
136
+ max_frames=17,
137
+ frame_rule="16n+1",
138
+ supports_lora=False,
139
+ )
140
+
141
+ registry.register(
142
+ "video-lab.fake.v1",
143
+ fake_factory,
144
+ metadata_factory=lambda: AdapterMetadata(
145
+ adapter_id="video-lab.fake.v1", display_name="Fake video"
146
+ ),
147
+ capabilities_factory=fake_capabilities,
148
+ )
149
+
150
+ def wan_mps_factory() -> GenerationAdapter:
151
+ from video_lab.adapters.wan_mps import WanMpsAdapter
152
+
153
+ return WanMpsAdapter()
154
+
155
+ def wan_mps_capabilities() -> AdapterCapabilities:
156
+ return AdapterCapabilities(
157
+ adapter_id="diffusers.wan2.1-t2v-1.3b.mps.v1",
158
+ model_patterns=("Wan-AI/Wan2.1-T2V-1.3B-Diffusers",),
159
+ backends=("mps",),
160
+ dtypes=("bfloat16",),
161
+ quantizations=("none",),
162
+ schedulers=("unipc",),
163
+ min_width=16,
164
+ max_width=4096,
165
+ width_multiple=16,
166
+ min_height=16,
167
+ max_height=4096,
168
+ height_multiple=16,
169
+ min_frames=17,
170
+ max_frames=129,
171
+ frame_rule="16n+1",
172
+ supports_lora=False,
173
+ )
174
+
175
+ registry.register(
176
+ "diffusers.wan2.1-t2v-1.3b.mps.v1",
177
+ wan_mps_factory,
178
+ metadata_factory=lambda: AdapterMetadata(
179
+ adapter_id="diffusers.wan2.1-t2v-1.3b.mps.v1", display_name="Wan 2.1 T2V 1.3B (MPS)"
180
+ ),
181
+ capabilities_factory=wan_mps_capabilities,
182
+ )
183
+
184
+ animegen_id = "diffusers.animegen-t2v.wan2.2-a14b.mps.v1"
185
+ authorization_bundle = (
186
+ None
187
+ if feasibility_repository is None
188
+ else feasibility_repository.generation_authorization_bundle(animegen_id)
189
+ )
190
+ animegen_verdict = (
191
+ SupportVerdict.PENDING if authorization_bundle is None else authorization_bundle.verdict
192
+ )
193
+ animegen_profile = (
194
+ None if authorization_bundle is None else authorization_bundle.measured_profile[:3]
195
+ )
196
+
197
+ def blocked_animegen_factory() -> GenerationAdapter:
198
+ raise UnknownAdapterError(
199
+ f"generation is disabled for candidate adapter: {animegen_id}"
200
+ )
201
+
202
+ def animegen_capabilities() -> AdapterCapabilities:
203
+ if animegen_verdict is SupportVerdict.EXPERIMENTAL_LOCAL_HYBRID:
204
+ if animegen_profile is None:
205
+ raise ValueError("experimental AnimeGen authorization requires minimum profile")
206
+ min_width, min_height, min_frames = animegen_profile
207
+ max_width, max_height, max_frames = min_width, min_height, min_frames
208
+ elif animegen_verdict is SupportVerdict.STANDARD_LAB_QUALIFIED:
209
+ if animegen_profile is None:
210
+ raise ValueError("standard AnimeGen authorization requires measured profile")
211
+ min_width, min_height, min_frames = 16, 16, 17
212
+ max_width, max_height, max_frames = animegen_profile
213
+ else:
214
+ min_width, min_height, min_frames = 16, 16, 17
215
+ max_width, max_height, max_frames = 4096, 4096, 129
216
+ return AdapterCapabilities(
217
+ adapter_id=animegen_id,
218
+ model_patterns=("aidealab/AnimeGen-T2V",),
219
+ backends=("mps",),
220
+ dtypes=("bfloat16",),
221
+ quantizations=tuple(mode.value for mode in AnimeGenStorageMode),
222
+ schedulers=("flow-match-euler-shift-3",),
223
+ min_width=min_width,
224
+ max_width=max_width,
225
+ width_multiple=16,
226
+ min_height=min_height,
227
+ max_height=max_height,
228
+ height_multiple=16,
229
+ min_frames=min_frames,
230
+ max_frames=max_frames,
231
+ frame_rule="16n+1",
232
+ supports_lora=True,
233
+ min_fps=(
234
+ 1 if authorization_bundle is None else authorization_bundle.measured_profile[3]
235
+ ),
236
+ max_fps=(
237
+ 120
238
+ if authorization_bundle is None
239
+ else authorization_bundle.measured_profile[3]
240
+ ),
241
+ )
242
+
243
+ registry.register(
244
+ animegen_id,
245
+ (
246
+ (
247
+ lambda: _authorized_animegen_adapter(
248
+ animegen_runtime_factory, authorization_bundle
249
+ )
250
+ )
251
+ if animegen_runtime_factory is not None
252
+ and authorization_bundle is not None
253
+ and animegen_verdict
254
+ in (
255
+ SupportVerdict.EXPERIMENTAL_LOCAL_HYBRID,
256
+ SupportVerdict.STANDARD_LAB_QUALIFIED,
257
+ )
258
+ else blocked_animegen_factory
259
+ ),
260
+ metadata_factory=lambda: AdapterMetadata(
261
+ adapter_id=animegen_id,
262
+ display_name="AnimeGen T2V / Wan 2.2 A14B (MPS candidate)",
263
+ source_model="aidealab/AnimeGen-T2V",
264
+ frame_rule="16n+1",
265
+ declared_profiles=("minimum", "standard-512x288-17f-8fps"),
266
+ generation_enabled=animegen_verdict
267
+ in (
268
+ SupportVerdict.EXPERIMENTAL_LOCAL_HYBRID,
269
+ SupportVerdict.STANDARD_LAB_QUALIFIED,
270
+ ),
271
+ ),
272
+ capabilities_factory=animegen_capabilities,
273
+ )
274
+ return registry
275
+
276
+
277
+ def _authorized_animegen_adapter(
278
+ runtime_factory: Callable[[GenerationAuthorizationBundle], object],
279
+ authorization: GenerationAuthorizationBundle | None,
280
+ ) -> GenerationAdapter:
281
+ from typing import cast
282
+
283
+ from video_lab.adapters.animegen_mps import AnimeGenGenerationRuntime, AnimeGenMpsAdapter
284
+
285
+ if authorization is None:
286
+ raise UnknownAdapterError("AnimeGen generation is not authorized")
287
+ verdict, profile = authorization.verdict, authorization.measured_profile[:3]
288
+ return AnimeGenMpsAdapter(
289
+ runtime=cast(AnimeGenGenerationRuntime, runtime_factory(authorization)),
290
+ authorized_profile=profile,
291
+ exact_profile_only=verdict is SupportVerdict.EXPERIMENTAL_LOCAL_HYBRID,
292
+ expected_fingerprints=(
293
+ authorization.source_fingerprint,
294
+ authorization.runtime_fingerprint,
295
+ authorization.placement_fingerprint,
296
+ ),
297
+ authorized_manifest=authorization.authorized_manifest,
298
+ authorized_verdict=authorization.verdict.value,
299
+ authorized_manifest_hash=authorization.canonical_manifest_hash,
300
+ )
@@ -0,0 +1 @@
1
+ """Generation adapter implementations."""