mlx-beam-vision 0.1.0a5__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 (40) hide show
  1. mlx_beam_vision-0.1.0a5/.gitignore +14 -0
  2. mlx_beam_vision-0.1.0a5/LICENSE +202 -0
  3. mlx_beam_vision-0.1.0a5/NOTICE +6 -0
  4. mlx_beam_vision-0.1.0a5/PKG-INFO +60 -0
  5. mlx_beam_vision-0.1.0a5/README.md +33 -0
  6. mlx_beam_vision-0.1.0a5/mlx_beam_vision/__init__.py +8 -0
  7. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/VENDORED.md +23 -0
  8. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/LICENSE +21 -0
  9. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/__init__.py +0 -0
  10. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/base.py +39 -0
  11. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/gemma4/__init__.py +0 -0
  12. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/gemma4/config.py +146 -0
  13. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/gemma4/vision.py +562 -0
  14. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/granite4_vision/__init__.py +0 -0
  15. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/granite4_vision/config.py +88 -0
  16. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/granite4_vision/downsampling.py +194 -0
  17. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/granite4_vision/qformer.py +222 -0
  18. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/granite4_vision/vision.py +209 -0
  19. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/muse_glimmer/__init__.py +0 -0
  20. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/muse_glimmer/config.py +129 -0
  21. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/muse_glimmer/vision.py +313 -0
  22. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/pixtral/__init__.py +0 -0
  23. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/pixtral/config.py +69 -0
  24. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/pixtral/vision.py +325 -0
  25. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/qwen3_vl/__init__.py +0 -0
  26. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/qwen3_vl/config.py +127 -0
  27. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_vendor/mlx_vlm/qwen3_vl/vision.py +447 -0
  28. mlx_beam_vision-0.1.0a5/mlx_beam_vision/_version.py +24 -0
  29. mlx_beam_vision-0.1.0a5/mlx_beam_vision/cache.py +56 -0
  30. mlx_beam_vision-0.1.0a5/mlx_beam_vision/families/__init__.py +152 -0
  31. mlx_beam_vision-0.1.0a5/mlx_beam_vision/families/gemma4.py +124 -0
  32. mlx_beam_vision-0.1.0a5/mlx_beam_vision/families/granite4_vision.py +241 -0
  33. mlx_beam_vision-0.1.0a5/mlx_beam_vision/families/mistral3.py +180 -0
  34. mlx_beam_vision-0.1.0a5/mlx_beam_vision/families/muse_glimmer.py +114 -0
  35. mlx_beam_vision-0.1.0a5/mlx_beam_vision/families/qwen3_vl.py +88 -0
  36. mlx_beam_vision-0.1.0a5/mlx_beam_vision/frontend.py +236 -0
  37. mlx_beam_vision-0.1.0a5/mlx_beam_vision/provider.py +46 -0
  38. mlx_beam_vision-0.1.0a5/mlx_beam_vision/weights.py +50 -0
  39. mlx_beam_vision-0.1.0a5/pyproject.toml +62 -0
  40. mlx_beam_vision-0.1.0a5/tests/test_qwen3_vl.py +713 -0
@@ -0,0 +1,14 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .venv/
5
+ dist/
6
+ build/
7
+ .ruff_cache/
8
+ .pytest_cache/
9
+ mlx_beam/_version.py
10
+ packages/*/*/_version.py
11
+ docs/site/node_modules/
12
+ docs/site/dist/
13
+ docs/site/.astro/
14
+ .DS_Store
@@ -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,6 @@
1
+ mlx-beam-vision
2
+ Copyright 2026 the mlx-beam contributors
3
+
4
+ This product includes software developed as part of mlx-vlm
5
+ (https://github.com/Blaizzy/mlx-vlm), MIT License; see
6
+ mlx_beam_vision/_vendor/VENDORED.md and mlx_beam_vision/_vendor/mlx_vlm/LICENSE.
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.5
2
+ Name: mlx-beam-vision
3
+ Version: 0.1.0a5
4
+ Summary: Vision towers for mlx-beam: images in the prompt, served by the checkpoint's own tower.
5
+ Project-URL: Homepage, https://p4ik.github.io/mlx-beam/
6
+ Project-URL: Repository, https://github.com/p4ik/mlx-beam
7
+ Author: the mlx-beam contributors
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Keywords: apple-silicon,inference,mlx,vision,vlm
12
+ Classifier: Development Status :: 2 - Pre-Alpha
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Requires-Python: >=3.11
18
+ Requires-Dist: mlx-beam
19
+ Requires-Dist: mlx>=0.32; sys_platform == 'darwin'
20
+ Requires-Dist: numpy
21
+ Requires-Dist: pillow>=10
22
+ Requires-Dist: transformers>=5.15
23
+ Provides-Extra: dev
24
+ Requires-Dist: mlx[cpu]>=0.32; (sys_platform == 'linux') and extra == 'dev'
25
+ Requires-Dist: pytest>=8; extra == 'dev'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # mlx-beam-vision
29
+
30
+ The towers that let [mlx-beam](https://github.com/p4ik/mlx-beam) see. Install
31
+ it next to the engine (`pip install mlx-beam[vision]`, or this package by
32
+ name) and a checkpoint that ships a vision tower serves images: an
33
+ `image_url` part with a `data:` URL in a chat request, the checkpoint's own
34
+ processor renders the template, the tower encodes the image, and the
35
+ engine's prefill takes the image's features in place of the placeholder
36
+ tokens - beside text-only requests in the same batch, with the prefix cache
37
+ keyed on the image's digest. Without this package the engine answers image
38
+ input with a 400 that names the `vision` extra.
39
+
40
+ Towers vendored from [mlx-vlm](https://github.com/Blaizzy/mlx-vlm) (MIT,
41
+ see `mlx_beam_vision/_vendor/VENDORED.md`):
42
+
43
+ | Family | Models | Notes |
44
+ |---|---|---|
45
+ | `qwen3_vl` | Qwen3-VL, Qwen3.5, Qwen3.8 | DeepStack applied: the tower's intermediate features are added after the text model's first layers |
46
+ | `mistral3` | Mistral Small 3.x (Pixtral tower) | the image's rows are separate spans (`[IMG_BREAK]` between them) |
47
+ | `gemma4` | Gemma 4 E2B, E4B | image only; audio is not served yet. The 12B (`gemma4_unified`, encoder-free, its image tokens attending bidirectionally in the text model) is refused with that reason until the text trunk takes such a mask |
48
+ | `muse_glimmer` | Muse Glimmer | the projector's norm matches the text model's input norm |
49
+ | `granite4_vision` | Granite Vision 4.1 | AnyRes tiles, window Q-Former projectors; nothing at the embedding, every projector's features added ahead of its text layer |
50
+
51
+ Not yet: audio and video input, quantized towers (the towers load at model
52
+ precision; a package that ships a quantized tower is refused with a
53
+ message). An image above 32 megapixels is refused before it is decoded.
54
+
55
+ Every family is exercised in the tests on a tiny random tower against a
56
+ direct forward; the real towers and processors are validated on Apple
57
+ silicon with the checkpoints themselves.
58
+
59
+ `/health.vision` reports the family, the tower, the processor and the
60
+ feature cache (encoder outputs by image digest, bounded in bytes).
@@ -0,0 +1,33 @@
1
+ # mlx-beam-vision
2
+
3
+ The towers that let [mlx-beam](https://github.com/p4ik/mlx-beam) see. Install
4
+ it next to the engine (`pip install mlx-beam[vision]`, or this package by
5
+ name) and a checkpoint that ships a vision tower serves images: an
6
+ `image_url` part with a `data:` URL in a chat request, the checkpoint's own
7
+ processor renders the template, the tower encodes the image, and the
8
+ engine's prefill takes the image's features in place of the placeholder
9
+ tokens - beside text-only requests in the same batch, with the prefix cache
10
+ keyed on the image's digest. Without this package the engine answers image
11
+ input with a 400 that names the `vision` extra.
12
+
13
+ Towers vendored from [mlx-vlm](https://github.com/Blaizzy/mlx-vlm) (MIT,
14
+ see `mlx_beam_vision/_vendor/VENDORED.md`):
15
+
16
+ | Family | Models | Notes |
17
+ |---|---|---|
18
+ | `qwen3_vl` | Qwen3-VL, Qwen3.5, Qwen3.8 | DeepStack applied: the tower's intermediate features are added after the text model's first layers |
19
+ | `mistral3` | Mistral Small 3.x (Pixtral tower) | the image's rows are separate spans (`[IMG_BREAK]` between them) |
20
+ | `gemma4` | Gemma 4 E2B, E4B | image only; audio is not served yet. The 12B (`gemma4_unified`, encoder-free, its image tokens attending bidirectionally in the text model) is refused with that reason until the text trunk takes such a mask |
21
+ | `muse_glimmer` | Muse Glimmer | the projector's norm matches the text model's input norm |
22
+ | `granite4_vision` | Granite Vision 4.1 | AnyRes tiles, window Q-Former projectors; nothing at the embedding, every projector's features added ahead of its text layer |
23
+
24
+ Not yet: audio and video input, quantized towers (the towers load at model
25
+ precision; a package that ships a quantized tower is refused with a
26
+ message). An image above 32 megapixels is refused before it is decoded.
27
+
28
+ Every family is exercised in the tests on a tiny random tower against a
29
+ direct forward; the real towers and processors are validated on Apple
30
+ silicon with the checkpoints themselves.
31
+
32
+ `/health.vision` reports the family, the tower, the processor and the
33
+ feature cache (encoder outputs by image digest, bounded in bytes).
@@ -0,0 +1,8 @@
1
+ """mlx-beam-vision: the towers that let mlx-beam see."""
2
+
3
+ try:
4
+ from mlx_beam_vision._version import __version__
5
+ except ImportError: # pragma: no cover - source tree without a build
6
+ __version__ = "0.0.0+unknown"
7
+
8
+ __all__ = ["__version__"]
@@ -0,0 +1,23 @@
1
+ # Vendored in mlx-beam-vision
2
+
3
+ The vision towers come from [mlx-vlm](https://github.com/Blaizzy/mlx-vlm)
4
+ (MIT; `mlx_vlm/LICENSE`), wheel 0.7.1 on PyPI. Each tower is the model
5
+ family's `vision.py` and `config.py` under `mlx_vlm/models/<family>/`,
6
+ copied unchanged and served from `mlx_vlm/<family>/` here; `base.py` holds
7
+ the two pieces they import (`BaseModelConfig`, `ensure_fused_sdpa`), copied
8
+ from `mlx_vlm/models/base.py`. What mlx-vlm does around a tower - the
9
+ processor, the merge of image features into the text embeddings, the
10
+ language model - is not vendored: the processor is the checkpoint's own
11
+ through transformers, the merge is mlx-beam's prefill (image spans), the
12
+ language model is mlx-beam's.
13
+
14
+ | Family here | Upstream directory | Serves |
15
+ |---|---|---|
16
+ | `qwen3_vl` | `mlx_vlm/models/qwen3_vl/` (`vision.py`, `config.py`) | Qwen3-VL, Qwen3.5, Qwen3.8 (the same tower; DeepStack features returned alongside) |
17
+ | `pixtral` | `mlx_vlm/models/pixtral/` (`vision.py`, `config.py`) | Mistral 3 (the projector is ours, after upstream's `mistral3.py`) |
18
+ | `gemma4` | `mlx_vlm/models/gemma4/` (`vision.py`, `config.py`) | Gemma 4 E-series (the embedder is ours, after upstream's `gemma4.py`); upstream's `gemma4_unified/` (the encoder-free 12B) is not taken - its image tokens need a bidirectional mask in the text model |
19
+ | `muse_glimmer` | `mlx_vlm/models/muse_glimmer/` (`vision.py`, `config.py`) | Muse Glimmer (adapter and projection ours, after upstream's `muse_glimmer.py`) |
20
+ | `granite4_vision` | `mlx_vlm/models/granite4_vision/` (`vision.py`, `config.py`, `downsampling.py`, `qformer.py`) | Granite Vision 4.1 (the packing and per-layer routing ours, after upstream's `granite4_vision.py`) |
21
+
22
+ `tools/vendor_diff.py` in the repository root compares these files against
23
+ the wheel (`tools/vendor.toml`, part `mlx-vlm-vision`).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright © 2025 Prince Canuma
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,39 @@
1
+ # Copyright © 2024 Apple Inc. and the mlx-vlm contributors. MIT License.
2
+ #
3
+ # The two pieces the vendored towers import from mlx_vlm/models/base.py,
4
+ # copied verbatim; the rest of that module (processors, features) stays out.
5
+
6
+ import inspect
7
+ from dataclasses import dataclass
8
+
9
+ import mlx.core as mx
10
+
11
+
12
+ @dataclass
13
+ class BaseModelConfig:
14
+ @classmethod
15
+ def from_dict(cls, params):
16
+ if not params:
17
+ return cls()
18
+ return cls(
19
+ **{
20
+ k: v
21
+ for k, v in params.items()
22
+ if k in inspect.signature(cls).parameters
23
+ }
24
+ )
25
+
26
+ def to_dict(self):
27
+ return {k: v for k, v in self.__dict__.items() if v is not None}
28
+
29
+
30
+ def ensure_fused_sdpa(q, k, v, scale, mask=None):
31
+ fused_dims = (64, 80, 128) # supported by MLX's fused SDPA kernel
32
+ d = q.shape[-1]
33
+ target = next((t for t in fused_dims if d <= t), d)
34
+ if target != d:
35
+ pad = [(0, 0)] * (q.ndim - 1) + [(0, target - d)]
36
+ q, k, v = mx.pad(q, pad), mx.pad(k, pad), mx.pad(v, pad)
37
+ return mx.fast.scaled_dot_product_attention(q, k, v, scale=scale, mask=mask)[
38
+ ..., :d
39
+ ]
@@ -0,0 +1,146 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import Dict, List, Optional
3
+
4
+ from ..base import BaseModelConfig
5
+
6
+
7
+ @dataclass
8
+ class AudioConfig(BaseModelConfig):
9
+ hidden_size: int = 1024
10
+ num_hidden_layers: int = 12
11
+ num_attention_heads: int = 8
12
+ hidden_act: str = "silu"
13
+ subsampling_conv_channels: tuple = (128, 32)
14
+ conv_kernel_size: int = 5
15
+ residual_weight: float = 0.5
16
+ attention_chunk_size: int = 12
17
+ attention_context_left: int = 13
18
+ attention_context_right: int = 0
19
+ attention_logit_cap: float = 50.0
20
+ attention_invalid_logits_value: float = -1e9
21
+ use_clipped_linears: bool = True
22
+ rms_norm_eps: float = 1e-6
23
+ gradient_clipping: float = 10000000000.0
24
+ output_proj_dims: Optional[int] = 1536
25
+
26
+
27
+ @dataclass
28
+ class VisionConfig(BaseModelConfig):
29
+ model_type: str = "gemma4_vision"
30
+ hidden_size: int = 768
31
+ intermediate_size: int = 3072
32
+ num_hidden_layers: int = 16
33
+ num_attention_heads: int = 12
34
+ num_key_value_heads: int = 12
35
+ head_dim: int = 64
36
+ global_head_dim: int = 64
37
+ hidden_activation: str = "gelu_pytorch_tanh"
38
+ rms_norm_eps: float = 1e-6
39
+ max_position_embeddings: int = 131072
40
+ attention_bias: bool = False
41
+ attention_dropout: float = 0.0
42
+ use_bidirectional_attention: str = "vision"
43
+ layer_types: Optional[List[str]] = None
44
+ rope_parameters: Optional[Dict] = None
45
+ default_output_length: int = 280
46
+ patch_size: int = 16
47
+ position_embedding_size: int = 10240
48
+ pooling_kernel_size: int = 3
49
+ use_clipped_linears: bool = False
50
+ standardize: bool = False
51
+
52
+ def __post_init__(self):
53
+ if self.layer_types is None:
54
+ self.layer_types = ["full_attention"] * self.num_hidden_layers
55
+ if self.rope_parameters is None:
56
+ self.rope_parameters = {"rope_theta": 100.0, "rope_type": "default"}
57
+
58
+
59
+ @dataclass
60
+ class TextConfig(BaseModelConfig):
61
+ model_type: str = "gemma4_text"
62
+ hidden_size: int = 1536
63
+ num_hidden_layers: int = 35
64
+ intermediate_size: int = 6144
65
+ num_attention_heads: int = 8
66
+ head_dim: int = 256
67
+ global_head_dim: int = 512
68
+ global_partial_rotary_factor: float = 0.25
69
+ rms_norm_eps: float = 1e-6
70
+ vocab_size: int = 262144
71
+ vocab_size_per_layer_input: int = 262144
72
+ num_key_value_heads: int = 1
73
+ num_global_key_value_heads: Optional[int] = None
74
+ num_kv_shared_layers: int = 20
75
+ pad_token_id: int = 0
76
+ hidden_activation: str = "gelu_pytorch_tanh"
77
+ hidden_size_per_layer_input: int = 256
78
+ rope_traditional: bool = False
79
+ partial_rotary_factor: float = 1.0
80
+ rope_parameters: Optional[Dict] = None
81
+ sliding_window: int = 512
82
+ sliding_window_pattern: int = 5
83
+ _sliding_window_pattern: int = 5
84
+ max_position_embeddings: int = 131072
85
+ attention_bias: bool = False
86
+ attention_dropout: float = 0.0
87
+ attention_k_eq_v: bool = False
88
+ use_bidirectional_attention: Optional[str] = None
89
+ final_logit_softcapping: float = 30.0
90
+ use_double_wide_mlp: bool = True
91
+ enable_moe_block: bool = False
92
+ use_second_mlp_block: bool = False
93
+ exact_speculative_verify: bool = False
94
+ num_experts: Optional[int] = None
95
+ top_k_experts: Optional[int] = None
96
+ moe_intermediate_size: Optional[int] = None
97
+ layer_types: Optional[List[str]] = None
98
+ tie_word_embeddings: bool = True
99
+
100
+ def __post_init__(self):
101
+ if self.rope_parameters is None:
102
+ self.rope_parameters = {
103
+ "full_attention": {
104
+ "partial_rotary_factor": 1.0,
105
+ "rope_theta": 1000000.0,
106
+ "rope_type": "proportional",
107
+ },
108
+ "sliding_attention": {
109
+ "partial_rotary_factor": 1.0,
110
+ "rope_theta": 10000.0,
111
+ "rope_type": "default",
112
+ },
113
+ }
114
+ if self.layer_types is None:
115
+ pattern = ["sliding_attention"] * (self.sliding_window_pattern - 1) + [
116
+ "full_attention"
117
+ ]
118
+ self.layer_types = (pattern * (self.num_hidden_layers // len(pattern) + 1))[
119
+ : self.num_hidden_layers
120
+ ]
121
+
122
+
123
+ @dataclass
124
+ class ModelConfig(BaseModelConfig):
125
+ text_config: TextConfig = field(default_factory=TextConfig)
126
+ vision_config: VisionConfig = field(default_factory=VisionConfig)
127
+ audio_config: Optional[AudioConfig] = None
128
+ model_type: str = "gemma4"
129
+ vocab_size: int = 262144
130
+ ignore_index: int = -100
131
+ image_token_id: int = 258880
132
+ audio_token_id: int = 258881
133
+ video_token_id: Optional[int] = None
134
+ boi_token_id: int = 255999
135
+ eoi_token_id: int = 258882
136
+ boa_token_id: int = 256000
137
+ eoa_token_id: int = 258883
138
+ hidden_size: int = 1536
139
+ pad_token_id: int = 0
140
+ vision_soft_tokens_per_image: int = 280
141
+ vision_soft_tokens_per_video_frame: int = 70
142
+ audio_soft_tokens_per_image: int = 750
143
+ audio_ms_per_token: int = 40
144
+ eos_token_id: Optional[List[int]] = None
145
+ tie_word_embeddings: bool = True
146
+ initializer_range: float = 0.02