mlxsmith 0.1.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 (69) hide show
  1. mlxsmith/__init__.py +2 -0
  2. mlxsmith/accel/__init__.py +10 -0
  3. mlxsmith/accel/base.py +17 -0
  4. mlxsmith/accel/none.py +13 -0
  5. mlxsmith/accel/zmlx_backend.py +42 -0
  6. mlxsmith/adapters.py +46 -0
  7. mlxsmith/api/__init__.py +48 -0
  8. mlxsmith/api/handlers.py +1217 -0
  9. mlxsmith/api/schemas.py +436 -0
  10. mlxsmith/auth.py +88 -0
  11. mlxsmith/bench.py +102 -0
  12. mlxsmith/cli.py +950 -0
  13. mlxsmith/config.py +543 -0
  14. mlxsmith/config_models.py +261 -0
  15. mlxsmith/data.py +493 -0
  16. mlxsmith/envs/__init__.py +33 -0
  17. mlxsmith/envs/system.py +388 -0
  18. mlxsmith/envs/token_env.py +191 -0
  19. mlxsmith/eval.py +112 -0
  20. mlxsmith/infer.py +140 -0
  21. mlxsmith/llm/__init__.py +16 -0
  22. mlxsmith/llm/backend.py +126 -0
  23. mlxsmith/llm/interface.py +212 -0
  24. mlxsmith/llm/mlx_lm_backend.py +509 -0
  25. mlxsmith/llm/mock_backend.py +228 -0
  26. mlxsmith/llm/registry.py +12 -0
  27. mlxsmith/models.py +257 -0
  28. mlxsmith/orchestrator/__init__.py +25 -0
  29. mlxsmith/orchestrator/daemon.py +454 -0
  30. mlxsmith/orchestrator/inference_worker.py +496 -0
  31. mlxsmith/orchestrator/queue.py +355 -0
  32. mlxsmith/orchestrator/trainer_worker.py +437 -0
  33. mlxsmith/rlm/__init__.py +8 -0
  34. mlxsmith/rlm/corpus.py +74 -0
  35. mlxsmith/rlm/gating.py +90 -0
  36. mlxsmith/rlm/generate.py +249 -0
  37. mlxsmith/rlm/history.py +12 -0
  38. mlxsmith/rlm/inference.py +150 -0
  39. mlxsmith/rlm/loop.py +1297 -0
  40. mlxsmith/rlm/mutate.py +82 -0
  41. mlxsmith/rlm/trainer.py +73 -0
  42. mlxsmith/rlm/weights.py +263 -0
  43. mlxsmith/runs.py +44 -0
  44. mlxsmith/sdk/__init__.py +392 -0
  45. mlxsmith/sdk/future.py +486 -0
  46. mlxsmith/sdk/losses.py +262 -0
  47. mlxsmith/sdk/sampling_client.py +729 -0
  48. mlxsmith/sdk/training_client.py +676 -0
  49. mlxsmith/server.py +376 -0
  50. mlxsmith/train/__init__.py +0 -0
  51. mlxsmith/train/distill.py +279 -0
  52. mlxsmith/train/lora.py +280 -0
  53. mlxsmith/train/pref.py +180 -0
  54. mlxsmith/train/rft.py +458 -0
  55. mlxsmith/train/sft.py +151 -0
  56. mlxsmith/util.py +174 -0
  57. mlxsmith/verifiers/__init__.py +3 -0
  58. mlxsmith/verifiers/compose.py +109 -0
  59. mlxsmith/verifiers/docker_verifier.py +111 -0
  60. mlxsmith/verifiers/jsonschema.py +54 -0
  61. mlxsmith/verifiers/pytest_verifier.py +82 -0
  62. mlxsmith/verifiers/regex.py +15 -0
  63. mlxsmith/verifiers/types.py +10 -0
  64. mlxsmith-0.1.0.dist-info/METADATA +163 -0
  65. mlxsmith-0.1.0.dist-info/RECORD +69 -0
  66. mlxsmith-0.1.0.dist-info/WHEEL +5 -0
  67. mlxsmith-0.1.0.dist-info/entry_points.txt +2 -0
  68. mlxsmith-0.1.0.dist-info/licenses/LICENSE +21 -0
  69. mlxsmith-0.1.0.dist-info/top_level.txt +1 -0
mlxsmith/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ __all__ = ['__version__']
2
+ __version__ = '0.1.0'
@@ -0,0 +1,10 @@
1
+ from __future__ import annotations
2
+ from .none import NoneBackend
3
+ from .zmlx_backend import ZMLXBackend
4
+
5
+ def get_backend(name: str):
6
+ if name == "none":
7
+ return NoneBackend()
8
+ if name == "zmlx":
9
+ return ZMLXBackend()
10
+ raise ValueError(f"Unknown accel backend: {name}")
mlxsmith/accel/base.py ADDED
@@ -0,0 +1,17 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any, Dict, Protocol
5
+
6
+ @dataclass
7
+ class AccelStats:
8
+ backend: str
9
+ compiled: int = 0
10
+ cache_hits: int = 0
11
+ notes: Dict[str, Any] | None = None
12
+
13
+ class AccelBackend(Protocol):
14
+ name: str
15
+ def patch(self) -> None: ...
16
+ def warmup(self, model: Any, example_batch: Any) -> Dict[str, Any]: ...
17
+ def stats(self) -> AccelStats: ...
mlxsmith/accel/none.py ADDED
@@ -0,0 +1,13 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Dict
4
+ from .base import AccelStats
5
+
6
+ class NoneBackend:
7
+ name = "none"
8
+ def patch(self) -> None:
9
+ return
10
+ def warmup(self, model: Any, example_batch: Any) -> Dict[str, Any]:
11
+ return {"warmup": "skipped"}
12
+ def stats(self) -> AccelStats:
13
+ return AccelStats(backend="none")
@@ -0,0 +1,42 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Dict
4
+ from .base import AccelStats
5
+
6
+ class ZMLXBackend:
7
+ name = "zmlx"
8
+
9
+ def __init__(self):
10
+ self._available = False
11
+ self._notes = {}
12
+ try:
13
+ import zmlx # type: ignore
14
+ self._available = True
15
+ self._notes["zmlx_version"] = getattr(zmlx, "__version__", None)
16
+ except Exception as e:
17
+ self._available = False
18
+ self._notes["error"] = f"{type(e).__name__}: {e}"
19
+
20
+ def patch(self) -> None:
21
+ if not self._available:
22
+ # soft fail; caller should report status
23
+ return
24
+ # ZMLX can patch ops/modules. We keep this intentionally minimal and safe.
25
+ try:
26
+ import zmlx # type: ignore
27
+ # If ZMLX provides a global patch hook, call it; otherwise, no-op.
28
+ patch_fn = getattr(zmlx, "patch", None)
29
+ if callable(patch_fn):
30
+ patch_fn()
31
+ self._notes["patched"] = True
32
+ else:
33
+ self._notes["patched"] = False
34
+ self._notes["hint"] = "No zmlx.patch() found; implement patch hook or integrate per-module."
35
+ except Exception as e:
36
+ self._notes["patched_error"] = f"{type(e).__name__}: {e}"
37
+
38
+ def warmup(self, model: Any, example_batch: Any) -> Dict[str, Any]:
39
+ return {"warmup": "not_implemented", "notes": self._notes}
40
+
41
+ def stats(self) -> AccelStats:
42
+ return AccelStats(backend="zmlx", notes=self._notes)
mlxsmith/adapters.py ADDED
@@ -0,0 +1,46 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+ from typing import Iterable, Optional
6
+
7
+ from .util import ensure_dir, copytree, now_ts
8
+
9
+
10
+ def merge_adapters(
11
+ base_model: str,
12
+ adapters: Iterable[Path],
13
+ out_dir: Path,
14
+ *,
15
+ weights: Optional[list[float]] = None,
16
+ ) -> Path:
17
+ adapter_list = [Path(a) for a in adapters]
18
+ if not adapter_list:
19
+ raise RuntimeError("No adapters provided")
20
+ ensure_dir(out_dir)
21
+
22
+ try:
23
+ from mlx_lm.tuner import utils as tuner_utils # type: ignore
24
+
25
+ if hasattr(tuner_utils, "merge_adapters"):
26
+ tuner_utils.merge_adapters(
27
+ base_model,
28
+ [str(p) for p in adapter_list],
29
+ str(out_dir),
30
+ weights=weights,
31
+ )
32
+ return out_dir
33
+ except Exception:
34
+ pass
35
+
36
+ # Fallback: copy the first adapter and record metadata.
37
+ copytree(adapter_list[0], out_dir)
38
+ meta = {
39
+ "base_model": base_model,
40
+ "merged_from": [str(p) for p in adapter_list],
41
+ "weights": weights,
42
+ "merged_at": now_ts(),
43
+ "note": "merge_adapters fallback: copied first adapter (mlx_lm merge unavailable)",
44
+ }
45
+ (out_dir / "adapter_merge.json").write_text(json.dumps(meta, indent=2), encoding="utf-8")
46
+ return out_dir
@@ -0,0 +1,48 @@
1
+ """MLXSmith API handlers and schemas."""
2
+
3
+ from .schemas import (
4
+ ChatMessage,
5
+ ChatRequest,
6
+ ChatResponse,
7
+ ChatCompletionChunk,
8
+ RolloutRequest,
9
+ RolloutResponse,
10
+ AdapterReloadRequest,
11
+ AdapterReloadResponse,
12
+ RLMState,
13
+ RLMHistoryEntry,
14
+ ModelInfo,
15
+ ModelsListResponse,
16
+ ModelPullRequest,
17
+ ModelPullResponse,
18
+ HFTokenRequest,
19
+ HFTokenResponse,
20
+ HealthResponse,
21
+ ErrorResponse,
22
+ )
23
+ from .handlers import create_router, InternalAuthMiddleware
24
+
25
+ __all__ = [
26
+ # Schemas
27
+ "ChatMessage",
28
+ "ChatRequest",
29
+ "ChatResponse",
30
+ "ChatCompletionChunk",
31
+ "RolloutRequest",
32
+ "RolloutResponse",
33
+ "AdapterReloadRequest",
34
+ "AdapterReloadResponse",
35
+ "RLMState",
36
+ "RLMHistoryEntry",
37
+ "ModelInfo",
38
+ "ModelsListResponse",
39
+ "ModelPullRequest",
40
+ "ModelPullResponse",
41
+ "HFTokenRequest",
42
+ "HFTokenResponse",
43
+ "HealthResponse",
44
+ "ErrorResponse",
45
+ # Handlers
46
+ "create_router",
47
+ "InternalAuthMiddleware",
48
+ ]