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.
- mlxsmith/__init__.py +2 -0
- mlxsmith/accel/__init__.py +10 -0
- mlxsmith/accel/base.py +17 -0
- mlxsmith/accel/none.py +13 -0
- mlxsmith/accel/zmlx_backend.py +42 -0
- mlxsmith/adapters.py +46 -0
- mlxsmith/api/__init__.py +48 -0
- mlxsmith/api/handlers.py +1217 -0
- mlxsmith/api/schemas.py +436 -0
- mlxsmith/auth.py +88 -0
- mlxsmith/bench.py +102 -0
- mlxsmith/cli.py +950 -0
- mlxsmith/config.py +543 -0
- mlxsmith/config_models.py +261 -0
- mlxsmith/data.py +493 -0
- mlxsmith/envs/__init__.py +33 -0
- mlxsmith/envs/system.py +388 -0
- mlxsmith/envs/token_env.py +191 -0
- mlxsmith/eval.py +112 -0
- mlxsmith/infer.py +140 -0
- mlxsmith/llm/__init__.py +16 -0
- mlxsmith/llm/backend.py +126 -0
- mlxsmith/llm/interface.py +212 -0
- mlxsmith/llm/mlx_lm_backend.py +509 -0
- mlxsmith/llm/mock_backend.py +228 -0
- mlxsmith/llm/registry.py +12 -0
- mlxsmith/models.py +257 -0
- mlxsmith/orchestrator/__init__.py +25 -0
- mlxsmith/orchestrator/daemon.py +454 -0
- mlxsmith/orchestrator/inference_worker.py +496 -0
- mlxsmith/orchestrator/queue.py +355 -0
- mlxsmith/orchestrator/trainer_worker.py +437 -0
- mlxsmith/rlm/__init__.py +8 -0
- mlxsmith/rlm/corpus.py +74 -0
- mlxsmith/rlm/gating.py +90 -0
- mlxsmith/rlm/generate.py +249 -0
- mlxsmith/rlm/history.py +12 -0
- mlxsmith/rlm/inference.py +150 -0
- mlxsmith/rlm/loop.py +1297 -0
- mlxsmith/rlm/mutate.py +82 -0
- mlxsmith/rlm/trainer.py +73 -0
- mlxsmith/rlm/weights.py +263 -0
- mlxsmith/runs.py +44 -0
- mlxsmith/sdk/__init__.py +392 -0
- mlxsmith/sdk/future.py +486 -0
- mlxsmith/sdk/losses.py +262 -0
- mlxsmith/sdk/sampling_client.py +729 -0
- mlxsmith/sdk/training_client.py +676 -0
- mlxsmith/server.py +376 -0
- mlxsmith/train/__init__.py +0 -0
- mlxsmith/train/distill.py +279 -0
- mlxsmith/train/lora.py +280 -0
- mlxsmith/train/pref.py +180 -0
- mlxsmith/train/rft.py +458 -0
- mlxsmith/train/sft.py +151 -0
- mlxsmith/util.py +174 -0
- mlxsmith/verifiers/__init__.py +3 -0
- mlxsmith/verifiers/compose.py +109 -0
- mlxsmith/verifiers/docker_verifier.py +111 -0
- mlxsmith/verifiers/jsonschema.py +54 -0
- mlxsmith/verifiers/pytest_verifier.py +82 -0
- mlxsmith/verifiers/regex.py +15 -0
- mlxsmith/verifiers/types.py +10 -0
- mlxsmith-0.1.0.dist-info/METADATA +163 -0
- mlxsmith-0.1.0.dist-info/RECORD +69 -0
- mlxsmith-0.1.0.dist-info/WHEEL +5 -0
- mlxsmith-0.1.0.dist-info/entry_points.txt +2 -0
- mlxsmith-0.1.0.dist-info/licenses/LICENSE +21 -0
- mlxsmith-0.1.0.dist-info/top_level.txt +1 -0
mlxsmith/__init__.py
ADDED
|
@@ -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
|
mlxsmith/api/__init__.py
ADDED
|
@@ -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
|
+
]
|