m37labs-slm-forge 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 (100) hide show
  1. m37labs_slm_forge-0.1.0/LICENSE +202 -0
  2. m37labs_slm_forge-0.1.0/NOTICE +37 -0
  3. m37labs_slm_forge-0.1.0/PKG-INFO +376 -0
  4. m37labs_slm_forge-0.1.0/README.md +335 -0
  5. m37labs_slm_forge-0.1.0/pyproject.toml +107 -0
  6. m37labs_slm_forge-0.1.0/pyproject.toml.orig +82 -0
  7. m37labs_slm_forge-0.1.0/src/slm/__init__.py +3 -0
  8. m37labs_slm_forge-0.1.0/src/slm/agents/__init__.py +0 -0
  9. m37labs_slm_forge-0.1.0/src/slm/agents/actions.py +111 -0
  10. m37labs_slm_forge-0.1.0/src/slm/agents/base.py +95 -0
  11. m37labs_slm_forge-0.1.0/src/slm/agents/observer.py +186 -0
  12. m37labs_slm_forge-0.1.0/src/slm/agents/prep.py +96 -0
  13. m37labs_slm_forge-0.1.0/src/slm/agents/provider.py +392 -0
  14. m37labs_slm_forge-0.1.0/src/slm/agents/scout.py +190 -0
  15. m37labs_slm_forge-0.1.0/src/slm/agents/synth.py +192 -0
  16. m37labs_slm_forge-0.1.0/src/slm/api/__init__.py +0 -0
  17. m37labs_slm_forge-0.1.0/src/slm/api/app.py +82 -0
  18. m37labs_slm_forge-0.1.0/src/slm/api/common.py +41 -0
  19. m37labs_slm_forge-0.1.0/src/slm/api/routes_agents.py +201 -0
  20. m37labs_slm_forge-0.1.0/src/slm/api/routes_feedback.py +208 -0
  21. m37labs_slm_forge-0.1.0/src/slm/api/routes_projects.py +412 -0
  22. m37labs_slm_forge-0.1.0/src/slm/api/routes_studio.py +278 -0
  23. m37labs_slm_forge-0.1.0/src/slm/api/routes_system.py +163 -0
  24. m37labs_slm_forge-0.1.0/src/slm/cli.py +65 -0
  25. m37labs_slm_forge-0.1.0/src/slm/config.py +129 -0
  26. m37labs_slm_forge-0.1.0/src/slm/data/__init__.py +0 -0
  27. m37labs_slm_forge-0.1.0/src/slm/data/clean.py +133 -0
  28. m37labs_slm_forge-0.1.0/src/slm/data/format.py +178 -0
  29. m37labs_slm_forge-0.1.0/src/slm/data/length.py +136 -0
  30. m37labs_slm_forge-0.1.0/src/slm/data/pipeline.py +245 -0
  31. m37labs_slm_forge-0.1.0/src/slm/data/scout_tools.py +228 -0
  32. m37labs_slm_forge-0.1.0/src/slm/data/split.py +80 -0
  33. m37labs_slm_forge-0.1.0/src/slm/db.py +340 -0
  34. m37labs_slm_forge-0.1.0/src/slm/eval/__init__.py +0 -0
  35. m37labs_slm_forge-0.1.0/src/slm/events.py +47 -0
  36. m37labs_slm_forge-0.1.0/src/slm/export/__init__.py +0 -0
  37. m37labs_slm_forge-0.1.0/src/slm/export/fuse.py +367 -0
  38. m37labs_slm_forge-0.1.0/src/slm/export/gguf.py +112 -0
  39. m37labs_slm_forge-0.1.0/src/slm/feedback.py +85 -0
  40. m37labs_slm_forge-0.1.0/src/slm/hardware.py +204 -0
  41. m37labs_slm_forge-0.1.0/src/slm/inference/__init__.py +0 -0
  42. m37labs_slm_forge-0.1.0/src/slm/inference/engine.py +214 -0
  43. m37labs_slm_forge-0.1.0/src/slm/inference/targets.py +49 -0
  44. m37labs_slm_forge-0.1.0/src/slm/models/__init__.py +0 -0
  45. m37labs_slm_forge-0.1.0/src/slm/models/catalog.py +281 -0
  46. m37labs_slm_forge-0.1.0/src/slm/models/hub.py +151 -0
  47. m37labs_slm_forge-0.1.0/src/slm/models/manage.py +160 -0
  48. m37labs_slm_forge-0.1.0/src/slm/profile.py +128 -0
  49. m37labs_slm_forge-0.1.0/src/slm/sessions.py +197 -0
  50. m37labs_slm_forge-0.1.0/src/slm/storage.py +353 -0
  51. m37labs_slm_forge-0.1.0/src/slm/train/__init__.py +0 -0
  52. m37labs_slm_forge-0.1.0/src/slm/train/config.py +193 -0
  53. m37labs_slm_forge-0.1.0/src/slm/train/diagnose.py +82 -0
  54. m37labs_slm_forge-0.1.0/src/slm/train/jobs.py +688 -0
  55. m37labs_slm_forge-0.1.0/src/slm/train/runner.py +217 -0
  56. m37labs_slm_forge-0.1.0/src/slm/train/worker.py +217 -0
  57. m37labs_slm_forge-0.1.0/src/slm/tuner/agent.py +195 -0
  58. m37labs_slm_forge-0.1.0/src/slm/tuner/confirm.py +253 -0
  59. m37labs_slm_forge-0.1.0/src/slm/tuner/runs.py +35 -0
  60. m37labs_slm_forge-0.1.0/src/slm/tuner/session.py +415 -0
  61. m37labs_slm_forge-0.1.0/src/slm/tuner/specialists.py +237 -0
  62. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/__init__.py +104 -0
  63. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/_core.py +163 -0
  64. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/data.py +336 -0
  65. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/evaluation.py +257 -0
  66. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/generate.py +46 -0
  67. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/models.py +85 -0
  68. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/person.py +24 -0
  69. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/scoring.py +69 -0
  70. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/status.py +231 -0
  71. m37labs_slm_forge-0.1.0/src/slm/tuner/tools/training.py +287 -0
  72. m37labs_slm_forge-0.1.0/src/slm/tuner/util.py +12 -0
  73. m37labs_slm_forge-0.1.0/src/slm/usage.py +164 -0
  74. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Agents-EKvkHvj4.js +1 -0
  75. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Charts-B3kGbhSE.js +57 -0
  76. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/ChatMessage-BJZeY882.js +1 -0
  77. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Data-BPW1g8F_.js +1 -0
  78. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Evaluate-CCmL7g9W.js +1 -0
  79. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Evaluate-DuruNXNg.js +1 -0
  80. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Export-BgfkfJds.js +1 -0
  81. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/ExportActions-C9W-InJM.js +1 -0
  82. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Feedback-Dunyy-bX.js +1 -0
  83. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Home-D9jHzwmO.js +1 -0
  84. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/JobLog-CyZjOiAy.js +2 -0
  85. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Markdown-ZmemsPsC.js +4 -0
  86. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Model-D95-4-r5.js +1 -0
  87. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Overview-gPAciH9r.js +1 -0
  88. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Page-BTsRUFS3.js +1 -0
  89. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Playground-D__3Q7c0.js +1 -0
  90. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/ProposalCard-YN4LCdN-.js +1 -0
  91. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/SamplingControls-CrBpaVsB.js +1 -0
  92. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Storage-DKoSHyCW.js +1 -0
  93. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/Train-D5pxhBgQ.js +1 -0
  94. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/TryModel-C5rr2Nyv.js +1 -0
  95. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/hooks-BRFvGiIJ.js +3 -0
  96. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/index-CKnHE1vA.js +10 -0
  97. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/index-ldWY0Op-.css +2 -0
  98. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/stages-DmDnqGEN.js +1 -0
  99. m37labs_slm_forge-0.1.0/src/slm/web_dist/assets/studio-CXCM9V1P.js +1 -0
  100. m37labs_slm_forge-0.1.0/src/slm/web_dist/index.html +22 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,37 @@
1
+ SLM Forge
2
+ Copyright 2026 Zorawar Purohit (github.com/engagepy) and the SLM Forge contributors.
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ -------------------------------------------------------------------------------
7
+ Third-party material included in this repository
8
+ -------------------------------------------------------------------------------
9
+
10
+ tests/fixtures/templates/*.jinja
11
+ Chat templates copied verbatim from the tokenizers of the models below, used only as test
12
+ fixtures. Each remains under its model's licence; see tests/fixtures/templates/README.md.
13
+ qwen2.5.jinja Qwen2.5-0.5B-Instruct Apache-2.0
14
+ qwen3.jinja Qwen3-1.7B Apache-2.0
15
+ smollm2.jinja SmolLM2-360M-Instruct Apache-2.0
16
+ smollm3.jinja SmolLM3-3B Apache-2.0
17
+ granite3.3.jinja Granite 3.3 2B Instruct Apache-2.0
18
+ phi4mini.jinja Phi-4-mini-instruct MIT
19
+ llama3.2.jinja Llama 3.2 1B Instruct Llama 3.2 Community License
20
+ Llama 3.2 is licensed under the Llama 3.2 Community License,
21
+ Copyright (c) Meta Platforms, Inc. All Rights Reserved.
22
+ gemma3.jinja Gemma 3 1B IT Gemma Terms of Use
23
+ (https://ai.google.dev/gemma/terms)
24
+
25
+ docs/brag/brag.mp4 (promo video)
26
+ Music: "Happy Beats / Business Moves" by ende.app, used with permission.
27
+ Sound effects: Kenney.nl and unicae_games (OpenGameArt), CC0 1.0 (public domain).
28
+
29
+ -------------------------------------------------------------------------------
30
+ Models and data you use with SLM Forge
31
+ -------------------------------------------------------------------------------
32
+
33
+ SLM Forge downloads base models and datasets from the Hugging Face Hub at your request; none are
34
+ included here. They stay under their own licences, and a model you train inherits the conditions
35
+ of its base model and training data. Every export records them in its model card and copies the
36
+ base model's licence files. Training data written or reviewed by OpenAI models is subject to
37
+ OpenAI's terms.
@@ -0,0 +1,376 @@
1
+ Metadata-Version: 2.4
2
+ Name: m37labs-slm-forge
3
+ Version: 0.1.0
4
+ Summary: Build your own small language model on a Mac by talking to an agent: data, MLX fine-tuning, evaluation and export
5
+ Keywords: llm,small-language-model,fine-tuning,lora,mlx,apple-silicon,agents
6
+ Author: Zorawar Purohit
7
+ Author-email: Zorawar Purohit <42845567+engagepy@users.noreply.github.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: GPU
13
+ Classifier: Environment :: Web Environment
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Dist: anthropic>=1.8.0
21
+ Requires-Dist: datasets>=5.0.1
22
+ Requires-Dist: fastapi>=0.141.1
23
+ Requires-Dist: httpx>=0.28.1
24
+ Requires-Dist: huggingface-hub>=1.33.0
25
+ Requires-Dist: mlx>=0.32.2
26
+ Requires-Dist: mlx-lm>=0.31.3
27
+ Requires-Dist: mlx-lm-lora>=3.1.3
28
+ Requires-Dist: openai>=3.19.2
29
+ Requires-Dist: openai-agents>=0.22.3
30
+ Requires-Dist: pydantic-settings>=2.15.0
31
+ Requires-Dist: python-multipart>=0.0.32
32
+ Requires-Dist: pyyaml>=6.0.3
33
+ Requires-Dist: sqlmodel>=0.0.47
34
+ Requires-Dist: sse-starlette>=3.4.11
35
+ Requires-Dist: uvicorn[standard]>=0.53.0
36
+ Requires-Python: >=3.13
37
+ Project-URL: Homepage, https://github.com/engagepy/SLM-Forge
38
+ Project-URL: Issues, https://github.com/engagepy/SLM-Forge/issues
39
+ Project-URL: Changelog, https://github.com/engagepy/SLM-Forge/blob/main/CHANGELOG.md
40
+ Description-Content-Type: text/markdown
41
+
42
+ # SLM Forge
43
+
44
+ https://github.com/user-attachments/assets/e9d6d7d1-d623-4441-8c28-ec0e63f40e6e
45
+
46
+ *One-minute tour: describe the model in a sentence. The Tuner picks the smallest model that fits your Mac, finds public data first and asks before every run. It trains and scores the model, and there is an Advanced view with every setting. You export to GGUF or Hugging Face, then chat with the result.*
47
+
48
+ Build your own small language model on a Mac, by talking to an agent.
49
+
50
+ Describe what the model should do in one sentence. The **Tuner**, a GPT-6 Luna agent built on
51
+ the OpenAI Agents SDK, takes it from there. It aims for a small, finished model you enjoy talking
52
+ to: the smallest base model that can do the job (preferring ones already on your Mac), training
53
+ data found on Hugging Face (with at most a small set written by GPT-6 to fill gaps), a quick
54
+ fine-tune with
55
+ [MLX](https://github.com/ml-explore/mlx), an honest before/after test, an optional refinement round
56
+ where GPT-6 reviews and corrects the answers, and an export. It does the groundwork on its own and
57
+ explains each decision in plain language, but **every run waits for your go-ahead**: downloading
58
+ the base model, each training run and the export. At the end you chat with the finished model on
59
+ the **Try it** page. You can steer the Tuner at any time by typing, or pause it.
60
+
61
+ ```
62
+ You ──chat──▶ Tuner (GPT-6 Luna) ──tools──▶ models · data · training · evaluation · export
63
+ │ (all local, on Apple Silicon)
64
+ └──▶ live canvas: every stage rendered as it happens
65
+ ```
66
+
67
+ Training and inference run locally on Apple Silicon. Only the agents call out to an LLM.
68
+
69
+ ## The Studio
70
+
71
+ The main screen is split in two:
72
+
73
+ - **Left: the Tuner.** A conversation that streams token by token. The agent's actions appear
74
+ as compact steps ("26 steps · searched datasets ×17…"). When the next step is a run, the Tuner
75
+ proposes it and a card appears above the input with **Go ahead** and **Not now** (a plain
76
+ "yes" in the chat works too). Nothing starts until you confirm. Between runs, autopilot keeps
77
+ it working on the groundwork, and a finished job wakes it to interpret the result. Autopilot
78
+ stops when the Tuner calls `finish_project`, or pauses itself (and says so) after two nudges
79
+ without progress. There's an on/off switch in the top bar.
80
+ Only creating a project (or pressing **Start the Tuner**) starts it; opening a project from
81
+ the sidebar never does. Pausing or stopping a project also cancels the Tuner's current turn and
82
+ blocks new jobs until you resume it or type a message.
83
+ - **Right: the live canvas.** A stage rail (Goal → Data → Model → Train → Evaluate → Refine →
84
+ Export) above cards that fill in as the work happens: the chosen model with its memory
85
+ footprint, training sets with cleaning stats, live loss curves, before/after answers, A/B
86
+ comparisons you judge with one click, and the exported model. The console underneath streams
87
+ the agent's tool calls and the running job's output.
88
+
89
+ Once a model is exported, **Try it** (`/p/:id/try`, linked from the Studio and Home) opens a chat
90
+ with the exported model itself: the fused, quantized folder on disk, exactly as it would run
91
+ elsewhere. The page also shows the folder and the command to run it outside SLM Forge.
92
+
93
+ Finishing doesn't close a project. **Keep improving** on the Done banner (or just asking the Tuner)
94
+ starts another round from the current model, and the new export gets a new name (`-v2`, or `-2`
95
+ if the name is taken), so earlier models are never overwritten.
96
+
97
+ Talking to the Tuner never costs anything. Between the export and your next go-ahead, anything
98
+ that spends (writing examples with GPT-6, an AI review, a download) is a card you confirm, and
99
+ questions get answers rather than actions.
100
+
101
+ Every project has the same switch at the top right: **Studio**, **Advanced** and **▶ Try it** (once a model is exported). For ML experts, **Advanced** shows the same project with every setting and number: the same stages and ticks as the Studio, each opening a full screen (data, base model, training hyperparameters and runs, evaluation scores and test set, feedback and DPO, export), plus a Playground to chat with any checkpoint.
102
+
103
+ ## Quick start
104
+
105
+ **Requirements:** an Apple Silicon Mac (M1 or later; 16 GB of memory or more recommended),
106
+ Python 3.13, and an [OpenAI API key](https://platform.openai.com/api-keys) for the Tuner.
107
+
108
+ **Install from PyPI** (needs [uv](https://docs.astral.sh/uv/) or [pipx](https://pipx.pypa.io/)):
109
+
110
+ ```bash
111
+ uv tool install m37labs-slm-forge # or: pipx install m37labs-slm-forge
112
+ echo "OPENAI_API_KEY=sk-..." > .env # in the folder you start it from; add HF_TOKEN=hf_... to publish
113
+ slm serve # → http://127.0.0.1:8000
114
+ ```
115
+
116
+ The package is `m37labs-slm-forge` on PyPI (plain `slm-forge` is too close to an existing project
117
+ name). It installs the `slm` command; `uvx m37labs-slm-forge serve` runs it without installing.
118
+
119
+ An installed copy keeps its projects, data and models in
120
+ `~/Library/Application Support/SLM Forge/` (set `SLM_WORKSPACE` to move them) and reads `.env` from
121
+ the current folder, then from that one.
122
+
123
+ **Or run from source** (also needs Node 20+):
124
+
125
+ ```bash
126
+ git clone https://github.com/engagepy/SLM-Forge.git && cd SLM-Forge
127
+ uv sync # Python deps (MLX, mlx-lm, mlx-lm-lora, FastAPI…)
128
+ cp .env.example .env # then add OPENAI_API_KEY
129
+ npm --prefix web ci && npm --prefix web run build # the web UI
130
+ uv run slm serve # → http://127.0.0.1:8000
131
+ ```
132
+
133
+ A clone keeps its data in `./workspace`. The Tuner uses the model named in `SLM_OPENAI_MODEL`
134
+ (default `gpt-6-luna`); set it in `.env` if your OpenAI account uses a different model.
135
+
136
+ Useful commands:
137
+
138
+ ```bash
139
+ uv run slm hardware # what this Mac can train
140
+ uv run slm models qwen # base models that fit, with memory estimates
141
+ uv run python scripts/smoke.py # end-to-end check: download → SFT → DPO → export (~4 min)
142
+ uv run pytest # unit + API tests (no GPU or network needed)
143
+ ```
144
+
145
+ For UI development, run `uv run slm serve` and `npm run dev` in `web/` (Vite proxies `/api`).
146
+
147
+ ## The loop
148
+
149
+ | Step | What happens |
150
+ |---|---|
151
+ | **1. Base model** | Search Hugging Face (MLX conversions first). Each model gets a fit verdict and a memory breakdown for inference and each training preset, measured against this Mac's GPU budget. |
152
+ | **2. Data** | **DataScout** searches the Hub, reads dataset cards, previews rows and *proposes* imports with a column mapping. When data needs a login or lives elsewhere, it writes step-by-step instructions and gives you an upload slot. You can also browse or upload yourself. **DataPrep** proposes the mapping and cleaning rules. Preparing a dataset normalises, dedupes, filters, splits and measures token lengths into an immutable version. |
153
+ | **3. Train (SFT)** | LoRA / DoRA / full fine-tuning with every `mlx-lm` knob exposed. Presets are sized to your hardware using the data's real token lengths, with a live memory estimate before launch and live loss/LR curves during the run. Epochs are converted to iterations for you. |
154
+ | **4. Playground** | Chat with any checkpoint or the base model. Every sampling control is available: temperature, top-p/k, min-p, repetition/presence/frequency penalties, XTC, seed, thinking mode. |
155
+ | **5. Feedback** | Compare two answers, pick one, optionally rewrite it, add a critique. Picks become DPO preference pairs; rewrites become SFT examples too. **Observer** reads the feedback and training results and proposes the next step. **Synth** writes new examples aimed at the weaknesses your critiques describe. Its preference pairs use *your model's own answer* as the rejected side when the GPU is free. |
156
+ | **6. DPO** | Preference-tuning on your feedback via `mlx-lm-lora`. The current SFT model is fused first so it serves as the frozen reference. |
157
+ | **7. Export** | Fuse, optionally quantize, and write a model card with the model's real lineage and the minimum Mac memory it needs. Runs anywhere with `mlx_lm.generate --model <path>`. |
158
+
159
+ **Agents only propose.** Anything that downloads, trains or adds data waits in the Agents
160
+ page for your approval (and you can edit the payload first). Synthetic examples wait in a
161
+ review queue before they can reach training.
162
+
163
+ **"RLHF" here means DPO, not PPO.** PPO needs the policy, a reference and a reward model in
164
+ memory at once, which doesn't fit a 16 GB Mac for useful model sizes. DPO learns from the
165
+ same human preference pairs with just the policy and a frozen reference.
166
+
167
+ ## Agent providers
168
+
169
+ The Tuner and its specialists (DataScout, DataPrep) run on the
170
+ [OpenAI Agents SDK](https://github.com/openai/openai-agents-python) with streaming and persistent
171
+ session memory, on `gpt-6-luna` (`SLM_OPENAI_MODEL` overrides). They always need `OPENAI_API_KEY`.
172
+ Agent traces are sent to the OpenAI dashboard only if you opt in with `SLM_OPENAI_TRACING=true`.
173
+
174
+ `SLM_AGENT_PROVIDER` chooses the LLM behind the AI judge (evaluation, answer review) and the
175
+ Advanced screens' agents (Observer, Synth):
176
+
177
+ | Provider | Key | How it runs |
178
+ |---|---|---|
179
+ | `openai` (default) | `OPENAI_API_KEY` | Responses API with strict JSON schemas for structured outputs. |
180
+ | `claude` | `ANTHROPIC_API_KEY` | Anthropic SDK, with adaptive thinking and server-side refusal fallback. |
181
+ | `ollama` | none | A local model. Fully offline, but it competes with training for memory and writes weaker synthetic data. |
182
+
183
+ Every provider exposes the same two calls, and every tool call is logged the same way, so those
184
+ agents and the UI don't care which one is behind them.
185
+
186
+ ## Lessons the Tuner carries
187
+
188
+ Its instructions encode what real runs on a 16 GB Mac taught, and the code enforces the same
189
+ things: scored test sets sized by task (exact match for deterministic outputs), one output format
190
+ per project, exports that carry their system prompt, no tiny top-ups, no DPO under 30 pairs,
191
+ learning rate 1e-4, continued runs that resume the adapter instead of copying the model, and
192
+ spending only inside a round the user set in motion. `AGENTS.md` lists each with the run that
193
+ taught it.
194
+
195
+ ## How the Tuner works
196
+
197
+ - **One agent, 33 tools** (`src/slm/tuner/tools/`) wrapping the tested platform code: `get_status`,
198
+ `find_base_models`, `choose_base_model`, `search_datasets`, `prepare_dataset`,
199
+ `generate_synthetic_examples`, `start_training`, `try_model`, `ask_user_to_compare`,
200
+ `export_model` and more. Quick jobs (imports, data prep, synthesis) are awaited inside the
201
+ tool. Runs (`choose_base_model`, `start_training`, `export_model`) only record a proposal
202
+ (`tuner/confirm.py`); your confirmation submits the job, and the finished job wakes the Tuner
203
+ with a `[Job update]` turn.
204
+ - **Its instructions carry what running this platform taught us:** learning rate 1e-4 is safe
205
+ and 2e-4 diverged; near-duplicates make validation loss meaningless; `max_seq_length` must
206
+ cover the data's p95 tokens; when public data is poor, write a small seed set, never the dataset.
207
+ - **Public data first, small synthetic sets only:** the Tuner's DataScout hunts the Hugging Face
208
+ Hub (and the alternatives it can reach), imports generously and samples down to the plan's
209
+ target. The teacher model writes at most 50 examples per call and 200 per project: a seed of a
210
+ few dozen when nothing public fits, or a top-up aimed at a gap the evaluation showed. It never
211
+ writes the dataset itself.
212
+ - **Before/after is a number.** The Tuner writes a test set sized to the task (10–80 cases, with
213
+ exact expected outputs wherever the task is deterministic) and scores every checkpoint on it with
214
+ `evaluate_model`: exact match first, the judge (0–10 against the goal) only where there is no
215
+ expected output or the answer differs from it. The
216
+ scores sit on the Evaluate card, the export is the best-scoring checkpoint (`serve_checkpoint`
217
+ rolls back if the latest run made things worse), and DPO isn't attempted under 30 pairs.
218
+ - **Try it keeps you testing:** four suggested inputs sit above the message box, three on-goal at
219
+ varied difficulty and one that should get the model's empty or negative answer (dashed). Used ones
220
+ stay ticked; once all four are used, GPT-6 writes four fresh ones scoped to the goal.
221
+ - **Exports work with no flags.** The project's system prompt is built into the exported model's
222
+ chat template, so `mlx_lm.generate --model <folder> --prompt "…"` (or any loader) behaves like
223
+ the app. Exports made before this show a `--system-prompt` in their command instead.
224
+ - **A metrics strip above every project:** the Mac and its ML budget, the GPU, how much disk the app
225
+ occupies (datasets, runs, exports, uploads, databases and the downloaded models, with free space),
226
+ and the OpenAI spend below.
227
+ - **Disk is not the constraint.** The Tuner keeps every adapter, metric, evaluation and example,
228
+ and sizes data by the goal (hundreds for a persona, thousands for extraction or JSON). What runs
229
+ leave behind that *is* reclaimable, the fused model copies each run writes for the next and the
230
+ folders of failed runs, shows in the Disk pill; past `SLM_DISK_TIDY_GB` (20) it's suggested, and
231
+ one click clears it with rollback intact (checkpoints re-fuse from their adapters).
232
+ - **Storage & cleanup** (`/storage`, from the Disk pill or the sidebar): every base model the app
233
+ downloaded (and which projects use it), every project with the size of its runs, data and
234
+ exported models. Remove a model, delete an export, or delete a project (keeping its exports if
235
+ you like); each shows the space it freed and the meter updates at once.
236
+ - **A spend meter, read from OpenAI.** The pill in the Studio bar and the sidebar shows what the
237
+ OpenAI account has spent today and this month, straight from OpenAI's Costs API (no token
238
+ counting). It needs an organisation admin key in `.env` (`OPENAI_ADMIN_KEY`; the project key
239
+ can't read costs). It finds the OpenAI project your key belongs to by itself (`OPENAI_PROJECT_ID`
240
+ overrides). OpenAI updates the figure with a lag of a few hours; the meter refreshes every ten
241
+ minutes. OpenAI only, for now. An admin key can read and manage your whole organisation, so it
242
+ is optional: create a dedicated one, or leave it unset and the meter reads "spend not set up".
243
+ - **AI feedback instead of human clicks:** `ai_review_answers` has the local model answer each
244
+ prompt twice, and GPT-6 picks the better answer, writes the ideal one and critiques the flaws.
245
+ Each verdict becomes a DPO preference pair and, where the model was wrong, a corrected SFT
246
+ example. Human A/B judging is still available when you ask for it.
247
+ - **Base models built to be small.** `find_base_models` lists a curated catalog first (Qwen2.5,
248
+ Qwen3, SmolLM2/3, Llama 3.2, Gemma 3, Granite, Phi-4 mini) with licence, what each is best for
249
+ and why, ordered by the plan's task type; the Tuner shortlists 2–3 and proposes one.
250
+ - **Specialists for data.** The Tuner delegates the hunt to **DataScout** (an Agents-SDK agent
251
+ that searches from several angles, previews candidates in parallel and returns a ranked shortlist
252
+ with licence, mapping and fit score) and the cleaning plan to **DataPrep** (inspects rows, checks
253
+ a mapping against them, returns thresholds and sequence length). Their tool calls show in the
254
+ console under their names; the Tuner's own context stays small.
255
+ - **Big imports, then a sample.** Hub datasets stream in up to 200,000 rows with progress on the
256
+ canvas; `prepare_dataset(max_examples=…)` cleans, deduplicates and samples to the plan's target,
257
+ and the rest stays on disk as a pool for later rounds.
258
+ - **Smallest model that does the job:** about 0.5B by default, 1–1.5B when answers need real
259
+ explanation, 3B only if you ask or a smaller model has clearly failed. Models already in the local Hugging Face cache
260
+ are listed first and registered instantly, with no re-download.
261
+ - **Turns run on one long-lived event loop.** The SDK's shared OpenAI client binds to the first
262
+ loop it runs on, so a fresh `asyncio.run()` per turn fails with "Event loop is closed". Tools
263
+ run in worker threads so blocking work never stalls the stream. Messages that arrive mid-turn
264
+ (from you, a job, or finished comparisons) batch into the next turn.
265
+ - **Memory:** the SDK's `SQLiteSession` keeps the agent's context across turns and server
266
+ restarts; the visible transcript is stored separately.
267
+
268
+ ## Architecture
269
+
270
+ ```
271
+ web/ (React + Vite + TanStack Query + Recharts) ──REST + SSE──▶ FastAPI src/slm/api
272
+ │
273
+ models/ hub search, fit check, download agents/ provider (OpenAI | Claude | Ollama)
274
+ data/ scout tools, mapping, cleaning, splits scout · prep · observer · synth
275
+ train/ configs & presets, subprocess runner, actions: approved proposal → job
276
+ log parsing, diagnosis, 3-lane job worker
277
+ inference/ single resident model, streaming generation export/ fuse, quantize, model card
278
+ SQLite (SQLModel) + workspace/ on disk
279
+ ```
280
+
281
+ Design decisions worth knowing:
282
+
283
+ - **Training runs as a subprocess** (`mlx_lm lora`, `mlx_lm_lora.train`) from a generated YAML
284
+ config, and its log is parsed into metrics. A crash or OOM can't take down the server, and
285
+ all GPU memory comes back when the job ends.
286
+ - **Three job lanes**, one job each: `gpu` (training and export; evicts the chat model first),
287
+ `io` (downloads, imports, data prep) and `agent` (LLM agent runs).
288
+ - **All in-process MLX work runs on one dedicated thread.** MLX's thread-local compile cache
289
+ holds Python objects; on the main thread it's destroyed after the interpreter shuts down
290
+ and segfaults the process on exit.
291
+ - **Runs build on each other without copying the model.** A new SFT run continues the served
292
+ adapter on the shared base model (no fused copy per run; a project's history is small adapters),
293
+ unless you start from the base model to compare settings fairly. Only a DPO round and an export
294
+ write a fused model. Every checkpoint records its parent; exports list only the served model's
295
+ ancestry.
296
+ - **Every finished run is diagnosed** for divergence, overfitting, no improvement and
297
+ "memorised" validation (near-zero validation loss usually means the validation set overlaps
298
+ training). Warnings show on the run page and feed the Observer.
299
+
300
+ ## What's been verified (M1 Pro, 16 GB)
301
+
302
+ With `mlx-community/Qwen2.5-0.5B-Instruct-4bit`:
303
+ - **Full loop through the API:** SFT → A/B feedback → DPO → export. The exported model runs
304
+ standalone at ~245 tok/s in 0.35 GB.
305
+ - **Memory estimate:** 1.37 GB estimated vs 1.48 GB measured for a balanced-preset SFT run.
306
+ - **Learning rate:** 2e-4 diverges (loss spikes 1.9 → 7.9) and is flagged automatically;
307
+ 1e-4 trains cleanly.
308
+
309
+ ## Roadmap
310
+
311
+ Built since the first plan: the scored evaluation harness (exact match + judge), checkpoint
312
+ comparison and roll-back, adapter resumption between rounds, the storage manager, the spend meter,
313
+ the model catalog and the data specialists. Still ahead:
314
+
315
+ - near-duplicate detection (MinHash), language ID and PII scrubbing in cleaning;
316
+ - web search for off-Hub data;
317
+ - a machine-wide GPU lock across server processes, and a memory estimator recalibrated for 3B+;
318
+ - curricula, ORPO/GRPO, GGUF/Ollama export, a device compatibility matrix.
319
+
320
+ ## Share it: GGUF and Hugging Face
321
+
322
+ Every export in the Studio has two more buttons:
323
+
324
+ - **Make GGUF** converts the model (exactly as exported, built-in system prompt included) into GGUF
325
+ files for llama.cpp, Ollama and LM Studio: **Q4_K_M** (small, the usual choice) and **Q8_0**
326
+ (near-lossless). The first time, SLM Forge downloads llama.cpp's converter and its dependencies
327
+ (about 300 MB, into the workspace). Q4_K_M needs llama.cpp's quantizer: `brew install llama.cpp`.
328
+ Without it you get Q8_0.
329
+ - **Upload to Hugging Face** publishes the export (the MLX model, the GGUF files, the model card and
330
+ the base model's licence files) to a repository under your account, **public** unless you choose
331
+ private. It uses your Hugging Face login: `HF_TOKEN` in `.env` (a token that can write) or `uv run hf auth login`. The form shows the base
332
+ model's licence first; Llama models are only published with Meta's licence file, and nothing that
333
+ names a folder on your Mac is uploaded. Afterwards: `ollama run hf.co/<you>/<model>:Q4_K_M`.
334
+
335
+ The Tuner can do both too, as cards you confirm, when you ask it to share the model.
336
+
337
+ ## Privacy & data
338
+
339
+ Training and inference run on your Mac. Three things leave it:
340
+
341
+ - **OpenAI** (the Tuner, its specialists and the AI judge): your goal and chat, samples of your
342
+ dataset rows, the test set, and the local model's answers when they are scored or reviewed. Don't
343
+ put data you may not share with OpenAI through it, such as health records or other personal
344
+ data. Agent traces go to your OpenAI dashboard only if you set `SLM_OPENAI_TRACING=true`.
345
+ - **Hugging Face:** model and dataset downloads and dataset searches, and the models you choose to
346
+ publish. It uses `HF_TOKEN` from `.env` or your `hf auth login`; SLM Forge never stores it elsewhere.
347
+ - **GitHub and PyPI**, once, when the first GGUF export downloads llama.cpp's converter.
348
+ - **Anthropic or Ollama**, only if you choose them as `SLM_AGENT_PROVIDER`.
349
+
350
+ API keys stay in `.env` or your environment and are never logged. The server listens on
351
+ `127.0.0.1` only and has no login: don't expose it to a network. There is no telemetry.
352
+
353
+ ## Licences
354
+
355
+ SLM Forge is released under the [Apache License 2.0](LICENSE); third-party material in this
356
+ repository is listed in [NOTICE](NOTICE).
357
+
358
+ The models you build are yours to use, within the terms of what they are made from:
359
+
360
+ - **The base model's licence.** Each candidate shows its licence and conditions before you
361
+ confirm it. Qwen2.5-3B is research-only; Llama 3.2 needs "Built with Llama" and follows Meta's
362
+ acceptable use policy; Gemma passes its use restrictions on. Every export copies the base model's
363
+ licence files and writes the licence, its conditions and the required notices into its model
364
+ card.
365
+ - **The training data's licences.** Imported datasets keep their licence, and the model card lists
366
+ each one. Check that a dataset's licence allows your use before you train on it.
367
+ - **OpenAI's terms**, for examples the teacher model wrote or corrected. The model card says when
368
+ any were used.
369
+
370
+ This is a summary to help you check, not legal advice.
371
+
372
+ ## Contributing
373
+
374
+ Contributions are welcome: read [CONTRIBUTING.md](CONTRIBUTING.md) (setup, checks, and the
375
+ invariants in [AGENTS.md](AGENTS.md)) and the [Code of Conduct](CODE_OF_CONDUCT.md). Report
376
+ security problems privately, as described in [SECURITY.md](SECURITY.md).