mlx-beam 0.1.0.dev5__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.
- mlx_beam-0.1.0.dev5/.gitignore +13 -0
- mlx_beam-0.1.0.dev5/CHANGELOG.md +11 -0
- mlx_beam-0.1.0.dev5/LICENSE +202 -0
- mlx_beam-0.1.0.dev5/NOTICE +8 -0
- mlx_beam-0.1.0.dev5/PKG-INFO +73 -0
- mlx_beam-0.1.0.dev5/README.md +45 -0
- mlx_beam-0.1.0.dev5/mlx_beam/__init__.py +8 -0
- mlx_beam-0.1.0.dev5/mlx_beam/_version.py +24 -0
- mlx_beam-0.1.0.dev5/mlx_beam/cli.py +68 -0
- mlx_beam-0.1.0.dev5/pyproject.toml +79 -0
- mlx_beam-0.1.0.dev5/tests/test_cli.py +90 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to mlx-beam. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
|
|
5
|
+
PEP 440 with SemVer meaning (`0.y` may break, `0.y.z` fixes).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Project skeleton: `beam --version`, `beam doctor`, packaging with hatch-vcs,
|
|
11
|
+
pre-commit (black, isort, ruff), CI on Apple silicon, contribution rules.
|
|
@@ -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,8 @@
|
|
|
1
|
+
mlx-beam
|
|
2
|
+
Copyright 2026 the mlx-beam contributors
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0; see LICENSE.
|
|
5
|
+
|
|
6
|
+
This product will include vendored components under their own licenses
|
|
7
|
+
(each with its license file under mlx_beam/_vendor/). VENDORED.md lists
|
|
8
|
+
every vendored part with its upstream, version, license and local changes.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mlx-beam
|
|
3
|
+
Version: 0.1.0.dev5
|
|
4
|
+
Summary: B.E.A.M. - Batched Engine for Apple Metal: an MLX inference engine for hybrid and MoE models on Apple silicon.
|
|
5
|
+
Project-URL: Homepage, https://github.com/p4ik/mlx-beam
|
|
6
|
+
Project-URL: Repository, https://github.com/p4ik/mlx-beam
|
|
7
|
+
Project-URL: Changelog, https://github.com/p4ik/mlx-beam/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Issues, https://github.com/p4ik/mlx-beam/issues
|
|
9
|
+
Author: the mlx-beam contributors
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: apple-silicon,inference,llm,mlx,moe
|
|
14
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Operating System :: MacOS
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: mlx>=0.32; sys_platform == 'darwin'
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pre-commit>=4; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# mlx-beam
|
|
30
|
+
|
|
31
|
+
**B.E.A.M. — Batched Engine for Apple Metal.** An [MLX](https://github.com/ml-explore/mlx) inference engine for hybrid-attention and mixture-of-experts language models on Apple silicon.
|
|
32
|
+
|
|
33
|
+
> **Work in progress.** See the status table below and the [changelog](CHANGELOG.md).
|
|
34
|
+
|
|
35
|
+
## What it is for
|
|
36
|
+
|
|
37
|
+
Models like Qwen3.8 (Gated DeltaNet + attention) and Qwen3.8-Flash-Next (125B-A6B MoE with an on-disk n-gram table) do not fit the assumptions of a plain transformer server: their recurrent state cannot be trimmed like a KV cache, their experts do not fit in memory, and speculative decoding under batching needs a rollback that most engines lack. B.E.A.M. is built around those cases:
|
|
38
|
+
|
|
39
|
+
- a prefix cache with recurrent-state checkpoints, so a long conversation resumes from disk instead of re-prefilling;
|
|
40
|
+
- multi-token prediction inside continuous batching;
|
|
41
|
+
- expert streaming from SSD with a resident pool, for models larger than RAM;
|
|
42
|
+
- a small, explicit OpenAI-compatible API, with everything else as optional extras.
|
|
43
|
+
|
|
44
|
+
The engine reads standard MLX checkpoints and the B.E.A.M. package layout (`extras/` next to the shards; see the model cards under [huggingface.co/p4ik](https://huggingface.co/p4ik)).
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
uv tool install "mlx-beam @ git+https://github.com/p4ik/mlx-beam"
|
|
50
|
+
beam doctor
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Inside an existing uv project: `uv add "mlx-beam @ git+https://github.com/p4ik/mlx-beam"`, then `uv run beam doctor`.
|
|
54
|
+
|
|
55
|
+
`beam doctor` prints the Python, MLX, device and memory it sees (`--json` for scripts) and exits non-zero when MLX is missing or fails to load. It is the only command so far.
|
|
56
|
+
|
|
57
|
+
## Status
|
|
58
|
+
|
|
59
|
+
| Piece | State |
|
|
60
|
+
|---|---|
|
|
61
|
+
| CLI, packaging, CI | skeleton |
|
|
62
|
+
| vendored mlx-lm base | planned |
|
|
63
|
+
| prefix cache with recurrent-state checkpoints | planned |
|
|
64
|
+
| MTP in the batch | planned |
|
|
65
|
+
| expert streaming | planned |
|
|
66
|
+
|
|
67
|
+
## Contributing
|
|
68
|
+
|
|
69
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Working rules for people and agents are in [AGENTS.md](AGENTS.md).
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
Apache-2.0. Vendored components keep their own licenses; see [NOTICE](NOTICE) and `VENDORED.md`.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# mlx-beam
|
|
2
|
+
|
|
3
|
+
**B.E.A.M. — Batched Engine for Apple Metal.** An [MLX](https://github.com/ml-explore/mlx) inference engine for hybrid-attention and mixture-of-experts language models on Apple silicon.
|
|
4
|
+
|
|
5
|
+
> **Work in progress.** See the status table below and the [changelog](CHANGELOG.md).
|
|
6
|
+
|
|
7
|
+
## What it is for
|
|
8
|
+
|
|
9
|
+
Models like Qwen3.8 (Gated DeltaNet + attention) and Qwen3.8-Flash-Next (125B-A6B MoE with an on-disk n-gram table) do not fit the assumptions of a plain transformer server: their recurrent state cannot be trimmed like a KV cache, their experts do not fit in memory, and speculative decoding under batching needs a rollback that most engines lack. B.E.A.M. is built around those cases:
|
|
10
|
+
|
|
11
|
+
- a prefix cache with recurrent-state checkpoints, so a long conversation resumes from disk instead of re-prefilling;
|
|
12
|
+
- multi-token prediction inside continuous batching;
|
|
13
|
+
- expert streaming from SSD with a resident pool, for models larger than RAM;
|
|
14
|
+
- a small, explicit OpenAI-compatible API, with everything else as optional extras.
|
|
15
|
+
|
|
16
|
+
The engine reads standard MLX checkpoints and the B.E.A.M. package layout (`extras/` next to the shards; see the model cards under [huggingface.co/p4ik](https://huggingface.co/p4ik)).
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
uv tool install "mlx-beam @ git+https://github.com/p4ik/mlx-beam"
|
|
22
|
+
beam doctor
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Inside an existing uv project: `uv add "mlx-beam @ git+https://github.com/p4ik/mlx-beam"`, then `uv run beam doctor`.
|
|
26
|
+
|
|
27
|
+
`beam doctor` prints the Python, MLX, device and memory it sees (`--json` for scripts) and exits non-zero when MLX is missing or fails to load. It is the only command so far.
|
|
28
|
+
|
|
29
|
+
## Status
|
|
30
|
+
|
|
31
|
+
| Piece | State |
|
|
32
|
+
|---|---|
|
|
33
|
+
| CLI, packaging, CI | skeleton |
|
|
34
|
+
| vendored mlx-lm base | planned |
|
|
35
|
+
| prefix cache with recurrent-state checkpoints | planned |
|
|
36
|
+
| MTP in the batch | planned |
|
|
37
|
+
| expert streaming | planned |
|
|
38
|
+
|
|
39
|
+
## Contributing
|
|
40
|
+
|
|
41
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Working rules for people and agents are in [AGENTS.md](AGENTS.md).
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
Apache-2.0. Vendored components keep their own licenses; see [NOTICE](NOTICE) and `VENDORED.md`.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.1.0.dev5'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 1, 0, 'dev5')
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""The `beam` command line."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import platform
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from mlx_beam import __version__
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def doctor(as_json: bool = False) -> int:
|
|
12
|
+
"""Report what this machine offers: Python, MLX, device, memory."""
|
|
13
|
+
report = {
|
|
14
|
+
"mlx_beam": __version__,
|
|
15
|
+
"python": platform.python_version(),
|
|
16
|
+
"platform": f"{platform.system()} {platform.release()} {platform.machine()}",
|
|
17
|
+
"mlx": None,
|
|
18
|
+
"device": None,
|
|
19
|
+
"memory_gb": None,
|
|
20
|
+
"ok": False,
|
|
21
|
+
"error": None,
|
|
22
|
+
}
|
|
23
|
+
try:
|
|
24
|
+
import mlx.core as mx
|
|
25
|
+
except ModuleNotFoundError:
|
|
26
|
+
report["error"] = "mlx is not installed (it runs on Apple silicon only)"
|
|
27
|
+
except ImportError as e:
|
|
28
|
+
# Installed but the extension did not load (Metal unavailable, wrong wheel).
|
|
29
|
+
report["error"] = f"mlx is installed but failed to load: {e!r}"
|
|
30
|
+
else:
|
|
31
|
+
report["mlx"] = getattr(mx, "__version__", "?")
|
|
32
|
+
try:
|
|
33
|
+
info = mx.device_info() if hasattr(mx, "device_info") else {}
|
|
34
|
+
report["device"] = info.get("device_name") or str(mx.default_device())
|
|
35
|
+
mem = info.get("memory_size")
|
|
36
|
+
if mem:
|
|
37
|
+
report["memory_gb"] = round(mem / 2**30, 1)
|
|
38
|
+
report["ok"] = True
|
|
39
|
+
except Exception as e: # noqa: BLE001 - the error text is the finding
|
|
40
|
+
report["error"] = f"mlx loaded but the device query failed: {e!r}"
|
|
41
|
+
if as_json:
|
|
42
|
+
print(json.dumps(report, indent=2))
|
|
43
|
+
else:
|
|
44
|
+
width = max(len(k) for k in report)
|
|
45
|
+
for key, value in report.items():
|
|
46
|
+
print(f"{key:<{width}} {value}")
|
|
47
|
+
return 0 if report["ok"] else 1
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def main(argv: list[str] | None = None) -> int:
|
|
51
|
+
parser = argparse.ArgumentParser(
|
|
52
|
+
prog="beam", description="B.E.A.M. - Batched Engine for Apple Metal"
|
|
53
|
+
)
|
|
54
|
+
parser.add_argument(
|
|
55
|
+
"--version", action="version", version=f"mlx-beam {__version__}"
|
|
56
|
+
)
|
|
57
|
+
sub = parser.add_subparsers(dest="command")
|
|
58
|
+
p_doctor = sub.add_parser("doctor", help="show Python, MLX, device and memory")
|
|
59
|
+
p_doctor.add_argument("--json", action="store_true", help="machine-readable output")
|
|
60
|
+
args = parser.parse_args(argv)
|
|
61
|
+
if args.command == "doctor":
|
|
62
|
+
return doctor(as_json=args.json)
|
|
63
|
+
parser.print_help()
|
|
64
|
+
return 0
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
sys.exit(main())
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27", "hatch-vcs>=0.4"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mlx-beam"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "B.E.A.M. - Batched Engine for Apple Metal: an MLX inference engine for hybrid and MoE models on Apple silicon."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
authors = [{ name = "the mlx-beam contributors" }]
|
|
14
|
+
keywords = ["mlx", "apple-silicon", "llm", "inference", "moe"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: Apache Software License",
|
|
20
|
+
"Operating System :: MacOS",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"mlx>=0.32; sys_platform == 'darwin'",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = ["pytest>=8", "pre-commit>=4"]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
beam = "mlx_beam.cli:main"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/p4ik/mlx-beam"
|
|
37
|
+
Repository = "https://github.com/p4ik/mlx-beam"
|
|
38
|
+
Changelog = "https://github.com/p4ik/mlx-beam/blob/main/CHANGELOG.md"
|
|
39
|
+
Issues = "https://github.com/p4ik/mlx-beam/issues"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.version]
|
|
42
|
+
source = "vcs"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.version.raw-options]
|
|
45
|
+
# PyPI refuses local labels (+g<hash>); .dev builds from main must be uploadable.
|
|
46
|
+
local_scheme = "no-local-version"
|
|
47
|
+
# main counts towards the next minor (0.1.0 -> 0.2.0.devN); a release-* branch
|
|
48
|
+
# counts towards the next patch (0.1.1.devN). Measured 2026-09-14 against the
|
|
49
|
+
# three schemes; the default would count 0.1.1.devN on main.
|
|
50
|
+
version_scheme = "release-branch-semver"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.hooks.vcs]
|
|
53
|
+
version-file = "mlx_beam/_version.py"
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.wheel]
|
|
56
|
+
packages = ["mlx_beam"]
|
|
57
|
+
|
|
58
|
+
[tool.hatch.build.targets.sdist]
|
|
59
|
+
only-include = ["mlx_beam", "tests", "README.md", "LICENSE", "NOTICE", "CHANGELOG.md"]
|
|
60
|
+
|
|
61
|
+
[tool.black]
|
|
62
|
+
line-length = 88
|
|
63
|
+
target-version = ["py311"]
|
|
64
|
+
|
|
65
|
+
[tool.isort]
|
|
66
|
+
profile = "black"
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
line-length = 88
|
|
70
|
+
target-version = "py311"
|
|
71
|
+
extend-exclude = ["mlx_beam/_vendor"]
|
|
72
|
+
|
|
73
|
+
[tool.ruff.lint]
|
|
74
|
+
select = ["E", "F", "W", "B", "UP"]
|
|
75
|
+
ignore = ["E501"]
|
|
76
|
+
|
|
77
|
+
[tool.pytest.ini_options]
|
|
78
|
+
testpaths = ["tests"]
|
|
79
|
+
markers = ["exactness: bit-exact comparisons on tiny models (Apple silicon only)"]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from mlx_beam import __version__
|
|
7
|
+
from mlx_beam.cli import doctor, main
|
|
8
|
+
|
|
9
|
+
PEP440 = re.compile(
|
|
10
|
+
r"^\d+(\.\d+)*((a|b|rc)\d+)?(\.post\d+)?(\.dev\d+)?(\+[0-9A-Za-z.]+)?$"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_version_is_pep440():
|
|
15
|
+
assert PEP440.match(__version__), __version__
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_version_flag(capsys):
|
|
19
|
+
with pytest.raises(SystemExit) as exc:
|
|
20
|
+
main(["--version"])
|
|
21
|
+
assert exc.value.code == 0
|
|
22
|
+
assert __version__ in capsys.readouterr().out
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_doctor_json_has_the_fields(capsys):
|
|
26
|
+
doctor(as_json=True)
|
|
27
|
+
report = json.loads(capsys.readouterr().out)
|
|
28
|
+
assert set(report) == {
|
|
29
|
+
"mlx_beam",
|
|
30
|
+
"python",
|
|
31
|
+
"platform",
|
|
32
|
+
"mlx",
|
|
33
|
+
"device",
|
|
34
|
+
"memory_gb",
|
|
35
|
+
"ok",
|
|
36
|
+
"error",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_doctor_exit_code_follows_mlx(capsys):
|
|
41
|
+
"""Exit 0 iff mlx imports; on Apple silicon it must."""
|
|
42
|
+
import platform
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
import mlx.core # noqa: F401
|
|
46
|
+
|
|
47
|
+
has_mlx = True
|
|
48
|
+
except ImportError:
|
|
49
|
+
has_mlx = False
|
|
50
|
+
rc = doctor(as_json=True)
|
|
51
|
+
capsys.readouterr()
|
|
52
|
+
assert rc == (0 if has_mlx else 1)
|
|
53
|
+
if platform.system() == "Darwin" and platform.machine() == "arm64":
|
|
54
|
+
assert has_mlx, "mlx must be installed on Apple silicon"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_doctor_keeps_the_load_error(monkeypatch, capsys):
|
|
58
|
+
"""An mlx that is installed but fails to load is reported with its error."""
|
|
59
|
+
import builtins
|
|
60
|
+
|
|
61
|
+
real_import = builtins.__import__
|
|
62
|
+
|
|
63
|
+
def failing_import(name, *args, **kwargs):
|
|
64
|
+
if name == "mlx.core":
|
|
65
|
+
raise ImportError("dlopen: Metal not available")
|
|
66
|
+
return real_import(name, *args, **kwargs)
|
|
67
|
+
|
|
68
|
+
monkeypatch.setattr(builtins, "__import__", failing_import)
|
|
69
|
+
rc = doctor(as_json=True)
|
|
70
|
+
report = json.loads(capsys.readouterr().out)
|
|
71
|
+
assert rc == 1 and report["ok"] is False
|
|
72
|
+
assert (
|
|
73
|
+
"failed to load" in report["error"] and "Metal not available" in report["error"]
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_doctor_reports_missing_package(monkeypatch, capsys):
|
|
78
|
+
import builtins
|
|
79
|
+
|
|
80
|
+
real_import = builtins.__import__
|
|
81
|
+
|
|
82
|
+
def missing_import(name, *args, **kwargs):
|
|
83
|
+
if name == "mlx.core":
|
|
84
|
+
raise ModuleNotFoundError("No module named 'mlx'")
|
|
85
|
+
return real_import(name, *args, **kwargs)
|
|
86
|
+
|
|
87
|
+
monkeypatch.setattr(builtins, "__import__", missing_import)
|
|
88
|
+
rc = doctor(as_json=True)
|
|
89
|
+
report = json.loads(capsys.readouterr().out)
|
|
90
|
+
assert rc == 1 and "not installed" in report["error"]
|