mlxsmith 0.1.0__tar.gz

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 (84) hide show
  1. mlxsmith-0.1.0/LICENSE +21 -0
  2. mlxsmith-0.1.0/PKG-INFO +163 -0
  3. mlxsmith-0.1.0/README.md +106 -0
  4. mlxsmith-0.1.0/pyproject.toml +75 -0
  5. mlxsmith-0.1.0/setup.cfg +4 -0
  6. mlxsmith-0.1.0/src/mlxsmith/__init__.py +2 -0
  7. mlxsmith-0.1.0/src/mlxsmith/accel/__init__.py +10 -0
  8. mlxsmith-0.1.0/src/mlxsmith/accel/base.py +17 -0
  9. mlxsmith-0.1.0/src/mlxsmith/accel/none.py +13 -0
  10. mlxsmith-0.1.0/src/mlxsmith/accel/zmlx_backend.py +42 -0
  11. mlxsmith-0.1.0/src/mlxsmith/adapters.py +46 -0
  12. mlxsmith-0.1.0/src/mlxsmith/api/__init__.py +48 -0
  13. mlxsmith-0.1.0/src/mlxsmith/api/handlers.py +1217 -0
  14. mlxsmith-0.1.0/src/mlxsmith/api/schemas.py +436 -0
  15. mlxsmith-0.1.0/src/mlxsmith/auth.py +88 -0
  16. mlxsmith-0.1.0/src/mlxsmith/bench.py +102 -0
  17. mlxsmith-0.1.0/src/mlxsmith/cli.py +950 -0
  18. mlxsmith-0.1.0/src/mlxsmith/config.py +543 -0
  19. mlxsmith-0.1.0/src/mlxsmith/config_models.py +261 -0
  20. mlxsmith-0.1.0/src/mlxsmith/data.py +493 -0
  21. mlxsmith-0.1.0/src/mlxsmith/envs/__init__.py +33 -0
  22. mlxsmith-0.1.0/src/mlxsmith/envs/system.py +388 -0
  23. mlxsmith-0.1.0/src/mlxsmith/envs/token_env.py +191 -0
  24. mlxsmith-0.1.0/src/mlxsmith/eval.py +112 -0
  25. mlxsmith-0.1.0/src/mlxsmith/infer.py +140 -0
  26. mlxsmith-0.1.0/src/mlxsmith/llm/__init__.py +16 -0
  27. mlxsmith-0.1.0/src/mlxsmith/llm/backend.py +126 -0
  28. mlxsmith-0.1.0/src/mlxsmith/llm/interface.py +212 -0
  29. mlxsmith-0.1.0/src/mlxsmith/llm/mlx_lm_backend.py +509 -0
  30. mlxsmith-0.1.0/src/mlxsmith/llm/mock_backend.py +228 -0
  31. mlxsmith-0.1.0/src/mlxsmith/llm/registry.py +12 -0
  32. mlxsmith-0.1.0/src/mlxsmith/models.py +257 -0
  33. mlxsmith-0.1.0/src/mlxsmith/orchestrator/__init__.py +25 -0
  34. mlxsmith-0.1.0/src/mlxsmith/orchestrator/daemon.py +454 -0
  35. mlxsmith-0.1.0/src/mlxsmith/orchestrator/inference_worker.py +496 -0
  36. mlxsmith-0.1.0/src/mlxsmith/orchestrator/queue.py +355 -0
  37. mlxsmith-0.1.0/src/mlxsmith/orchestrator/trainer_worker.py +437 -0
  38. mlxsmith-0.1.0/src/mlxsmith/rlm/__init__.py +8 -0
  39. mlxsmith-0.1.0/src/mlxsmith/rlm/corpus.py +74 -0
  40. mlxsmith-0.1.0/src/mlxsmith/rlm/gating.py +90 -0
  41. mlxsmith-0.1.0/src/mlxsmith/rlm/generate.py +249 -0
  42. mlxsmith-0.1.0/src/mlxsmith/rlm/history.py +12 -0
  43. mlxsmith-0.1.0/src/mlxsmith/rlm/inference.py +150 -0
  44. mlxsmith-0.1.0/src/mlxsmith/rlm/loop.py +1297 -0
  45. mlxsmith-0.1.0/src/mlxsmith/rlm/mutate.py +82 -0
  46. mlxsmith-0.1.0/src/mlxsmith/rlm/trainer.py +73 -0
  47. mlxsmith-0.1.0/src/mlxsmith/rlm/weights.py +263 -0
  48. mlxsmith-0.1.0/src/mlxsmith/runs.py +44 -0
  49. mlxsmith-0.1.0/src/mlxsmith/sdk/__init__.py +392 -0
  50. mlxsmith-0.1.0/src/mlxsmith/sdk/future.py +486 -0
  51. mlxsmith-0.1.0/src/mlxsmith/sdk/losses.py +262 -0
  52. mlxsmith-0.1.0/src/mlxsmith/sdk/sampling_client.py +729 -0
  53. mlxsmith-0.1.0/src/mlxsmith/sdk/training_client.py +676 -0
  54. mlxsmith-0.1.0/src/mlxsmith/server.py +376 -0
  55. mlxsmith-0.1.0/src/mlxsmith/train/__init__.py +0 -0
  56. mlxsmith-0.1.0/src/mlxsmith/train/distill.py +279 -0
  57. mlxsmith-0.1.0/src/mlxsmith/train/lora.py +280 -0
  58. mlxsmith-0.1.0/src/mlxsmith/train/pref.py +180 -0
  59. mlxsmith-0.1.0/src/mlxsmith/train/rft.py +458 -0
  60. mlxsmith-0.1.0/src/mlxsmith/train/sft.py +151 -0
  61. mlxsmith-0.1.0/src/mlxsmith/util.py +174 -0
  62. mlxsmith-0.1.0/src/mlxsmith/verifiers/__init__.py +3 -0
  63. mlxsmith-0.1.0/src/mlxsmith/verifiers/compose.py +109 -0
  64. mlxsmith-0.1.0/src/mlxsmith/verifiers/docker_verifier.py +111 -0
  65. mlxsmith-0.1.0/src/mlxsmith/verifiers/jsonschema.py +54 -0
  66. mlxsmith-0.1.0/src/mlxsmith/verifiers/pytest_verifier.py +82 -0
  67. mlxsmith-0.1.0/src/mlxsmith/verifiers/regex.py +15 -0
  68. mlxsmith-0.1.0/src/mlxsmith/verifiers/types.py +10 -0
  69. mlxsmith-0.1.0/src/mlxsmith.egg-info/PKG-INFO +163 -0
  70. mlxsmith-0.1.0/src/mlxsmith.egg-info/SOURCES.txt +82 -0
  71. mlxsmith-0.1.0/src/mlxsmith.egg-info/dependency_links.txt +1 -0
  72. mlxsmith-0.1.0/src/mlxsmith.egg-info/entry_points.txt +2 -0
  73. mlxsmith-0.1.0/src/mlxsmith.egg-info/requires.txt +39 -0
  74. mlxsmith-0.1.0/src/mlxsmith.egg-info/top_level.txt +1 -0
  75. mlxsmith-0.1.0/tests/test_api.py +266 -0
  76. mlxsmith-0.1.0/tests/test_auth.py +20 -0
  77. mlxsmith-0.1.0/tests/test_config.py +783 -0
  78. mlxsmith-0.1.0/tests/test_data.py +46 -0
  79. mlxsmith-0.1.0/tests/test_rlm.py +51 -0
  80. mlxsmith-0.1.0/tests/test_rlm_mutation.py +39 -0
  81. mlxsmith-0.1.0/tests/test_runs.py +18 -0
  82. mlxsmith-0.1.0/tests/test_sdk.py +749 -0
  83. mlxsmith-0.1.0/tests/test_training_smoke.py +106 -0
  84. mlxsmith-0.1.0/tests/test_verifiers.py +25 -0
mlxsmith-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,163 @@
1
+ Metadata-Version: 2.4
2
+ Name: mlxsmith
3
+ Version: 0.1.0
4
+ Summary: Apple Silicon MLX fine-tuning and OpenAI-compatible serving (SFT stable; preference/RL experimental).
5
+ Author-email: Shannon Labs <hmbown@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Hmbown/MLXSmith
8
+ Project-URL: Repository, https://github.com/Hmbown/MLXSmith
9
+ Project-URL: Issues, https://github.com/Hmbown/MLXSmith/issues
10
+ Keywords: mlx,apple-silicon,llm,fine-tuning,lora,openai-compatible
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Operating System :: MacOS :: MacOS X
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: typer>=0.9.0
26
+ Requires-Dist: rich>=13.7.0
27
+ Requires-Dist: pyyaml>=6.0.1
28
+ Requires-Dist: pydantic>=2.5.0
29
+ Requires-Dist: pydantic-settings>=2.2.1
30
+ Requires-Dist: tomli>=2.0.1; python_version < "3.11"
31
+ Requires-Dist: huggingface_hub>=1.3.4
32
+ Requires-Dist: jsonschema>=4.21.0
33
+ Provides-Extra: mlx
34
+ Requires-Dist: mlx>=0.30.4; extra == "mlx"
35
+ Provides-Extra: llm
36
+ Requires-Dist: mlx-lm>=0.30.5; extra == "llm"
37
+ Requires-Dist: transformers>=5.0.0; extra == "llm"
38
+ Requires-Dist: datasets>=3.0.0; extra == "llm"
39
+ Provides-Extra: serve
40
+ Requires-Dist: fastapi>=0.128.0; extra == "serve"
41
+ Requires-Dist: uvicorn>=0.40.0; extra == "serve"
42
+ Requires-Dist: httpx>=0.28.0; extra == "serve"
43
+ Provides-Extra: zmlx
44
+ Requires-Dist: zmlx; extra == "zmlx"
45
+ Provides-Extra: dev
46
+ Requires-Dist: pytest>=9.0.0; extra == "dev"
47
+ Requires-Dist: ruff>=0.14.0; extra == "dev"
48
+ Provides-Extra: all
49
+ Requires-Dist: mlx>=0.30.4; extra == "all"
50
+ Requires-Dist: mlx-lm>=0.30.5; extra == "all"
51
+ Requires-Dist: transformers>=5.0.0; extra == "all"
52
+ Requires-Dist: datasets>=3.0.0; extra == "all"
53
+ Requires-Dist: fastapi>=0.128.0; extra == "all"
54
+ Requires-Dist: uvicorn>=0.40.0; extra == "all"
55
+ Requires-Dist: httpx>=0.28.0; extra == "all"
56
+ Dynamic: license-file
57
+
58
+ # mlxsmith
59
+
60
+ Apple Silicon MLX fine-tuning and OpenAI-compatible serving.
61
+ SFT + serving are stable. Preference/RL/RLM features are experimental.
62
+
63
+ Status: alpha (2026-02-02).
64
+
65
+ ## Stable features
66
+ - Project init, config, data tools, HF auth, model pull/convert.
67
+ - SFT (LoRA/QLoRA) training with run tracking and adapters.
68
+ - Inference and OpenAI-compatible /v1/chat/completions serving.
69
+ - Basic eval/bench and verifier plumbing (regex/jsonschema/pytest).
70
+
71
+ ## Experimental features
72
+ - Preference tuning (DPO/ORPO).
73
+ - GRPO-style RFT.
74
+ - RLM self-play loop (research).
75
+ - Distill/OPD and orchestrated RLM.
76
+
77
+ ## Install
78
+
79
+ MLX is only available on Apple Silicon. Other platforms can still use data tools
80
+ and mock backends, but MLX training and serving require macOS on Apple Silicon.
81
+
82
+ ```bash
83
+ python -m venv .venv && source .venv/bin/activate
84
+ pip install -U pip
85
+
86
+ # Core CLI
87
+ pip install mlxsmith
88
+
89
+ # Apple Silicon training + serving
90
+ pip install "mlxsmith[mlx,llm,serve]"
91
+ ```
92
+
93
+ ## Quickstart
94
+
95
+ ```bash
96
+ mlxsmith init myproj
97
+ cd myproj
98
+ mlxsmith doctor
99
+ ```
100
+
101
+ ## HF auth (optional)
102
+
103
+ ```bash
104
+ mlxsmith auth login --token "$HF_TOKEN"
105
+ mlxsmith auth status
106
+ mlxsmith auth logout
107
+ ```
108
+
109
+ ## Pull + convert a model (HF -> MLX)
110
+
111
+ ```bash
112
+ mlxsmith pull Qwen/Qwen3-4B-Instruct-2507
113
+ # outputs to cache/mlx/Qwen__Qwen3-4B-Instruct-2507
114
+ ```
115
+
116
+ Optional quantization:
117
+
118
+ ```bash
119
+ mlxsmith pull Qwen/Qwen3-4B-Instruct-2507 --quantize --q-bits 4
120
+ ```
121
+
122
+ ## SFT (LoRA/QLoRA)
123
+
124
+ ```bash
125
+ mlxsmith sft --model cache/mlx/Qwen__Qwen3-4B-Instruct-2507 --data data/sft
126
+ ```
127
+
128
+ ## Serve (OpenAI-compatible)
129
+
130
+ ```bash
131
+ mlxsmith serve --model runs/sft_0001/adapter --port 8080
132
+ ```
133
+
134
+ Sample request:
135
+
136
+ ```bash
137
+ curl http://localhost:8080/v1/chat/completions \
138
+ -H 'Content-Type: application/json' \
139
+ -d '{"messages":[{"role":"user","content":"Hello"}],"max_tokens":64}'
140
+ ```
141
+
142
+ To enable the optional UI/monitor dashboard, set `serve.ui: true` in `mlxsmith.yaml`.
143
+
144
+ ## Experimental commands
145
+
146
+ - `mlxsmith pref` (DPO/ORPO)
147
+ - `mlxsmith rft` (GRPO-style)
148
+ - `mlxsmith rlm` / `mlxsmith pipeline` (self-play loop)
149
+ - `mlxsmith distill` (offline/OPD)
150
+ - `mlxsmith eval` / `mlxsmith bench`
151
+
152
+ ## Docs
153
+
154
+ - `docs/PROJECT_FORMAT.md` for project layout and artifacts.
155
+ - `docs/VERIFIERS.md` for verifier API and sandbox behavior.
156
+ - `docs/COMPATIBILITY.md` for tested versions and model families.
157
+ - `docs/ENVIRONMENTS.md` for the environment plugin system.
158
+ - `docs/ROADMAP.md` for product direction and milestones.
159
+ - `docs/README.md` for the full docs index.
160
+
161
+ ## License
162
+
163
+ MIT
@@ -0,0 +1,106 @@
1
+ # mlxsmith
2
+
3
+ Apple Silicon MLX fine-tuning and OpenAI-compatible serving.
4
+ SFT + serving are stable. Preference/RL/RLM features are experimental.
5
+
6
+ Status: alpha (2026-02-02).
7
+
8
+ ## Stable features
9
+ - Project init, config, data tools, HF auth, model pull/convert.
10
+ - SFT (LoRA/QLoRA) training with run tracking and adapters.
11
+ - Inference and OpenAI-compatible /v1/chat/completions serving.
12
+ - Basic eval/bench and verifier plumbing (regex/jsonschema/pytest).
13
+
14
+ ## Experimental features
15
+ - Preference tuning (DPO/ORPO).
16
+ - GRPO-style RFT.
17
+ - RLM self-play loop (research).
18
+ - Distill/OPD and orchestrated RLM.
19
+
20
+ ## Install
21
+
22
+ MLX is only available on Apple Silicon. Other platforms can still use data tools
23
+ and mock backends, but MLX training and serving require macOS on Apple Silicon.
24
+
25
+ ```bash
26
+ python -m venv .venv && source .venv/bin/activate
27
+ pip install -U pip
28
+
29
+ # Core CLI
30
+ pip install mlxsmith
31
+
32
+ # Apple Silicon training + serving
33
+ pip install "mlxsmith[mlx,llm,serve]"
34
+ ```
35
+
36
+ ## Quickstart
37
+
38
+ ```bash
39
+ mlxsmith init myproj
40
+ cd myproj
41
+ mlxsmith doctor
42
+ ```
43
+
44
+ ## HF auth (optional)
45
+
46
+ ```bash
47
+ mlxsmith auth login --token "$HF_TOKEN"
48
+ mlxsmith auth status
49
+ mlxsmith auth logout
50
+ ```
51
+
52
+ ## Pull + convert a model (HF -> MLX)
53
+
54
+ ```bash
55
+ mlxsmith pull Qwen/Qwen3-4B-Instruct-2507
56
+ # outputs to cache/mlx/Qwen__Qwen3-4B-Instruct-2507
57
+ ```
58
+
59
+ Optional quantization:
60
+
61
+ ```bash
62
+ mlxsmith pull Qwen/Qwen3-4B-Instruct-2507 --quantize --q-bits 4
63
+ ```
64
+
65
+ ## SFT (LoRA/QLoRA)
66
+
67
+ ```bash
68
+ mlxsmith sft --model cache/mlx/Qwen__Qwen3-4B-Instruct-2507 --data data/sft
69
+ ```
70
+
71
+ ## Serve (OpenAI-compatible)
72
+
73
+ ```bash
74
+ mlxsmith serve --model runs/sft_0001/adapter --port 8080
75
+ ```
76
+
77
+ Sample request:
78
+
79
+ ```bash
80
+ curl http://localhost:8080/v1/chat/completions \
81
+ -H 'Content-Type: application/json' \
82
+ -d '{"messages":[{"role":"user","content":"Hello"}],"max_tokens":64}'
83
+ ```
84
+
85
+ To enable the optional UI/monitor dashboard, set `serve.ui: true` in `mlxsmith.yaml`.
86
+
87
+ ## Experimental commands
88
+
89
+ - `mlxsmith pref` (DPO/ORPO)
90
+ - `mlxsmith rft` (GRPO-style)
91
+ - `mlxsmith rlm` / `mlxsmith pipeline` (self-play loop)
92
+ - `mlxsmith distill` (offline/OPD)
93
+ - `mlxsmith eval` / `mlxsmith bench`
94
+
95
+ ## Docs
96
+
97
+ - `docs/PROJECT_FORMAT.md` for project layout and artifacts.
98
+ - `docs/VERIFIERS.md` for verifier API and sandbox behavior.
99
+ - `docs/COMPATIBILITY.md` for tested versions and model families.
100
+ - `docs/ENVIRONMENTS.md` for the environment plugin system.
101
+ - `docs/ROADMAP.md` for product direction and milestones.
102
+ - `docs/README.md` for the full docs index.
103
+
104
+ ## License
105
+
106
+ MIT
@@ -0,0 +1,75 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mlxsmith"
7
+ version = "0.1.0"
8
+ description = "Apple Silicon MLX fine-tuning and OpenAI-compatible serving (SFT stable; preference/RL experimental)."
9
+ readme = {file = "README.md", content-type = "text/markdown"}
10
+ requires-python = ">=3.10"
11
+ license = {text = "MIT"}
12
+ authors = [{name="Shannon Labs", email="hmbown@gmail.com"}]
13
+ keywords = ["mlx", "apple-silicon", "llm", "fine-tuning", "lora", "openai-compatible"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Intended Audience :: Science/Research",
18
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Operating System :: MacOS :: MacOS X",
26
+ ]
27
+ dependencies = [
28
+ "typer>=0.9.0",
29
+ "rich>=13.7.0",
30
+ "pyyaml>=6.0.1",
31
+ "pydantic>=2.5.0",
32
+ "pydantic-settings>=2.2.1",
33
+ "tomli>=2.0.1; python_version < '3.11'",
34
+ "huggingface_hub>=1.3.4",
35
+ "jsonschema>=4.21.0",
36
+ ]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/Hmbown/MLXSmith"
40
+ Repository = "https://github.com/Hmbown/MLXSmith"
41
+ Issues = "https://github.com/Hmbown/MLXSmith/issues"
42
+
43
+ [project.optional-dependencies]
44
+ mlx = ["mlx>=0.30.4"]
45
+ llm = [
46
+ "mlx-lm>=0.30.5",
47
+ "transformers>=5.0.0",
48
+ "datasets>=3.0.0",
49
+ ]
50
+ serve = [
51
+ "fastapi>=0.128.0",
52
+ "uvicorn>=0.40.0",
53
+ "httpx>=0.28.0",
54
+ ]
55
+ zmlx = ["zmlx"]
56
+ dev = ["pytest>=9.0.0", "ruff>=0.14.0"]
57
+ all = [
58
+ "mlx>=0.30.4",
59
+ "mlx-lm>=0.30.5",
60
+ "transformers>=5.0.0",
61
+ "datasets>=3.0.0",
62
+ "fastapi>=0.128.0",
63
+ "uvicorn>=0.40.0",
64
+ "httpx>=0.28.0",
65
+ ]
66
+
67
+ [project.scripts]
68
+ mlxsmith = "mlxsmith.cli:app"
69
+
70
+ [tool.setuptools]
71
+ package-dir = {"" = "src"}
72
+ license-files = ["LICENSE"]
73
+
74
+ [tool.setuptools.packages.find]
75
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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}")
@@ -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: ...
@@ -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)
@@ -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
+ ]