Image-Text-to-Text
MLX
Safetensors
qwen3_5
decision-model
decision-making
calibration
jevbench
apple-silicon
conversational
8-bit precision
Instructions to use netprojects/h2o-lightning-4b-mlx-q8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use netprojects/h2o-lightning-4b-mlx-q8 with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("netprojects/h2o-lightning-4b-mlx-q8") config = load_config("netprojects/h2o-lightning-4b-mlx-q8") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use netprojects/h2o-lightning-4b-mlx-q8 with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "netprojects/h2o-lightning-4b-mlx-q8"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "netprojects/h2o-lightning-4b-mlx-q8" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent
How to use netprojects/h2o-lightning-4b-mlx-q8 with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "netprojects/h2o-lightning-4b-mlx-q8"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default netprojects/h2o-lightning-4b-mlx-q8
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use netprojects/h2o-lightning-4b-mlx-q8 with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "netprojects/h2o-lightning-4b-mlx-q8"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "netprojects/h2o-lightning-4b-mlx-q8" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
H2O-Lightning-4B v1.4.0 (previous build: v1.3.1 tag)
Browse files- .h2o_revision +1 -1
- LICENSE +202 -0
- README.md +16 -29
- example_receipt.png +0 -0
- h2o_lightning_shim.py +57 -75
- model.safetensors +2 -2
- model.safetensors.index.json +1 -1
- serve_config.json +41 -42
.h2o_revision
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
d42875078bafb155af14d609d85071091418e83f
|
LICENSE
ADDED
|
@@ -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 2026 Alibaba Cloud
|
| 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.
|
README.md
CHANGED
|
@@ -8,26 +8,32 @@ tags: [mlx, decision-model, decision-making, calibration, jevbench, qwen3_5, app
|
|
| 8 |
---
|
| 9 |
# H2O-Lightning-4B — MLX 8-bit
|
| 10 |
|
| 11 |
-
An 8-bit MLX conversion (affine, group size 64; mlx-vlm 0.7.8) of [h2oai/h2o-lightning-4b](https://huggingface.co/h2oai/h2o-lightning-4b) **v1.
|
| 12 |
|
| 13 |
Published by [NetProjects](https://netprojects.com) (Internet Projects Ltd). Not affiliated with H2O.ai.
|
| 14 |
|
| 15 |
-
This is a **decision model**, not a chat model. It returns a probability for each answer option, not text.
|
| 16 |
|
| 17 |
> **Serve it with the H2O shim, not with `mlx_lm.server` or a plain `mlx_vlm` generate call.** The generic "Use this model" snippets Hugging Face shows for MLX models do not return the label probabilities this model is made for. The commands below set it up with H2O's official shim, unmodified, on top of [h2o-lightning-mlx](https://github.com/internet-projects/h2o-lightning-mlx), which reads the label log-probabilities with a float32 head, as the original does on vLLM.
|
| 18 |
|
| 19 |
| JevBench public (231, JevBench v1.2.1, `--adapter typesafe`) | two-way | one-way |
|
| 20 |
|---|---|---|
|
| 21 |
-
| this checkpoint | **
|
| 22 |
-
| original weights on MLX (bf16) |
|
| 23 |
-
| H2O's model card (vLLM) |
|
| 24 |
-
| vs bf16 on MLX |
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
-
**Two-way reading.** H2O v1.3 answers under two attention patterns, and two-way is its recommended default. This build serves both from one engine: a request picks `"attention_mode": "two-way"` or `"one-way"`, and two-way is the default. Before its first two-way answer, H2O's shim checks the engine against the answers H2O recorded on the release weights; this build matches them to within 0.
|
| 29 |
|
| 30 |
-
**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
**Limits** (as for the original): mostly evaluated in English; works best with about 16 answer options or fewer; no explanations and no video input.
|
| 33 |
|
|
@@ -37,26 +43,7 @@ hf download netprojects/h2o-lightning-4b-mlx-q8 --local-dir mlx-q8
|
|
| 37 |
MODEL=mlx-q8 ./serve.sh # http://127.0.0.1:8741/v1/systemone
|
| 38 |
```
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
Measured on a MacBook Pro M5 Max (128 GB) on 23 October 2026, with no other models running, through `serve.sh` (`/v1/systemone`, one request at a time, over HTTP on the same Mac) with H2O v1.3.1. Times are per decision, from the client's side, so they include the shim and HTTP. The facade's prefix cache was off and the weights stayed loaded. Medians of 3 passes or runs after a warm-up.
|
| 43 |
-
|
| 44 |
-
| Mode | Input | Median per decision (95th percentile) | Decisions per second | Memory in use at peak |
|
| 45 |
-
|---|---|---|---|---|
|
| 46 |
-
| two-way | 120 JevBench items (median 130 tokens) | 66 ms (70 ms) | 12.5 | 8.1 GB |
|
| 47 |
-
| two-way | one record of about 2,000 tokens | 466 ms | 2.15 | 6.9 GB |
|
| 48 |
-
| two-way | one 4K-token state | 994 ms | 1.01 | 8.2 GB |
|
| 49 |
-
| two-way | one 16K-token state | 5.5 s | 0.18 | 22.4 GB |
|
| 50 |
-
| two-way | one 32K-token state | 15.8 s | 0.06 | 55.0 GB |
|
| 51 |
-
| one-way | 120 JevBench items (median 130 tokens) | 68 ms (73 ms) | 12.1 | 7.7 GB |
|
| 52 |
-
| one-way | one record of about 2,000 tokens | 447 ms | 2.24 | 6.8 GB |
|
| 53 |
-
| one-way | one 4K-token state | 961 ms | 1.04 | 7.7 GB |
|
| 54 |
-
| one-way | one 16K-token state | 4.1 s | 0.24 | 8.3 GB |
|
| 55 |
-
| one-way | one 32K-token state | 9.1 s | 0.11 | 8.9 GB |
|
| 56 |
-
|
| 57 |
-
Peak memory grows much faster with the prompt in two-way mode: 22 GB at 16K tokens and 55 GB at 32K tokens, against 8 GB and 9 GB in one-way mode. For long inputs on a Mac with less than 64 GB, use one-way mode (send `"attention_mode": "one-way"`, or start `serve.sh` with `TWO_WAY=0`). The shim keeps states to 32,000 tokens (the start and the end of longer ones), so the 32K rows are 32,098 tokens with the template.
|
| 58 |
-
|
| 59 |
-
**Versions.** `main` is H2O v1.3.1 (updated 19 October 2026). The previous build, H2O v1.2.3 (one-way, 205 / 231), stays available with `hf download netprojects/h2o-lightning-4b-mlx-q8 --revision v1.2.3`; use it with `git checkout v1.2.3` in the GitHub repo.
|
| 60 |
|
| 61 |
**Full precision:** use the original weights, [h2oai/h2o-lightning-4b](https://huggingface.co/h2oai/h2o-lightning-4b), with the same repo and shim. There is no separate bf16 copy here.
|
| 62 |
|
|
|
|
| 8 |
---
|
| 9 |
# H2O-Lightning-4B — MLX 8-bit
|
| 10 |
|
| 11 |
+
An 8-bit MLX conversion (affine, group size 64; mlx-vlm 0.7.8) of [h2oai/h2o-lightning-4b](https://huggingface.co/h2oai/h2o-lightning-4b) **v1.4.0**, for Apple Silicon. 4.8 GB. Supports H2O's **two-way reading** and **Box questions**.
|
| 12 |
|
| 13 |
Published by [NetProjects](https://netprojects.com) (Internet Projects Ltd). Not affiliated with H2O.ai.
|
| 14 |
|
| 15 |
+
This is a **decision model**, not a chat model. It returns a probability for each answer option (or, for a Box question, a bounding box), not free text.
|
| 16 |
|
| 17 |
> **Serve it with the H2O shim, not with `mlx_lm.server` or a plain `mlx_vlm` generate call.** The generic "Use this model" snippets Hugging Face shows for MLX models do not return the label probabilities this model is made for. The commands below set it up with H2O's official shim, unmodified, on top of [h2o-lightning-mlx](https://github.com/internet-projects/h2o-lightning-mlx), which reads the label log-probabilities with a float32 head, as the original does on vLLM.
|
| 18 |
|
| 19 |
| JevBench public (231, JevBench v1.2.1, `--adapter typesafe`) | two-way | one-way |
|
| 20 |
|---|---|---|
|
| 21 |
+
| this checkpoint | **206 / 231** (48/48 · 72/72 · 86/111) | 202 / 231 |
|
| 22 |
+
| original weights on MLX (bf16) | 206 / 231 | 203 / 231 |
|
| 23 |
+
| H2O's model card (vLLM) | 206 / 231 | — |
|
| 24 |
+
| vs bf16 on MLX | **231 / 231 answers identical**; probability drift mean 0.002, p95 0.012 | 230 / 231 identical |
|
| 25 |
|
| 26 |
+
The same score as H2O's own result, tier by tier; the recommended MLX build.
|
| 27 |
|
| 28 |
+
**Two-way reading.** H2O v1.3+ answers under two attention patterns, and two-way is its recommended default. This build serves both from one engine: a request picks `"attention_mode": "two-way"` or `"one-way"`, and two-way is the default. Before its first two-way answer, H2O's shim checks the engine against the answers H2O recorded on the release weights; this build matches them to within 0.012 (tolerance 0.05).
|
| 29 |
|
| 30 |
+
**Box questions** (always on since v1.4.0): ask for a bounding box of a named object in an image and get `box`, a calibrated `confidence`, `present` and `found`. The facade answers H2O's guided box generation exactly as the shim requests it. On H2O's receipt example, the box for the total-amount line has confidence 0.96.
|
| 31 |
+
|
| 32 |
+
**Speed** (MacBook Pro M5 Max, 25 October 2026, through `serve.sh`, one request at a time): about 63 ms per JevBench item; a 2,000-token record in 0.45 s two-way and 0.39 s one-way; a 32K-token state in 14.5 s two-way and 7.7 s one-way. **Two-way memory grows quickly with long inputs** (MLX peak 55 GB at 32K tokens, against 8.9 GB one-way): for long inputs on a Mac with less than 64 GB, use one-way.
|
| 33 |
+
|
| 34 |
+
**Images.** Image input works through the unchanged shim. On H2O's own receipt example this build gives the same answers as the original weights. It is not a reproduction of H2O's image benchmark.
|
| 35 |
+
|
| 36 |
+
**About v1.4.0** (from H2O's card): a new fine-tune with images in its training data, stronger than v1.3.2 on H2O's held-out decision skills, and weaker on retrieval (product-search relevance) and on choosing a function to call. If your work is mostly tool-call selection, compare with the `v1.3.1` revision on your own data.
|
| 37 |
|
| 38 |
**Limits** (as for the original): mostly evaluated in English; works best with about 16 answer options or fewer; no explanations and no video input.
|
| 39 |
|
|
|
|
| 43 |
MODEL=mlx-q8 ./serve.sh # http://127.0.0.1:8741/v1/systemone
|
| 44 |
```
|
| 45 |
|
| 46 |
+
**Versions.** `main` is H2O v1.4.0 (updated 25 October 2026). Earlier builds stay available: H2O v1.3.1 (two-way, 203 / 231) with `--revision v1.3.1`, and H2O v1.2.3 (one-way, 205 / 231) with `--revision v1.2.3`; use each with the matching tag in the GitHub repo (`git checkout v1.3.1`).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
**Full precision:** use the original weights, [h2oai/h2o-lightning-4b](https://huggingface.co/h2oai/h2o-lightning-4b), with the same repo and shim. There is no separate bf16 copy here.
|
| 49 |
|
example_receipt.png
ADDED
|
h2o_lightning_shim.py
CHANGED
|
@@ -32,31 +32,25 @@ IMAGES (only when serve_config.json has an "image" block, and only for a request
|
|
| 32 |
`logprob_token_ids` readout, so the prompt is the text prompt plus the image tokens. A request without an image
|
| 33 |
takes the text path above, unchanged.
|
| 34 |
|
| 35 |
-
TWO-WAY READING (the recommended default
|
| 36 |
-
The weights were trained to answer under two attention patterns: one-way (causal, the readout above
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
(
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
engine serves the model; label_rows.lightning belongs to the served model.safetensors (its sha256, hashed once
|
| 55 |
-
into .model_sha256.json beside the weights) and holds the labels' token ids; the pooled state is not normalised;
|
| 56 |
-
the engine's answers to three fixed probes are within two_way.probe_tolerance of the answers recorded on the
|
| 57 |
-
release weights (two_way.probe_reference), so other weights, another dtype or an engine started without the
|
| 58 |
-
override are refused; with the one-way engine up as well, the two engines must answer the probes apart. Any
|
| 59 |
-
failure is a 503, kept 10 s (SHIM_TWO_WAY_RETRY_SECONDS) before the engine is checked again.
|
| 60 |
|
| 61 |
STATUS CODES (an evaluation runner stops after three consecutive failures unless a failure is a 422): a request this
|
| 62 |
system cannot answer -- too many options, a malformed question, a prompt over vLLM's context -- is a 422, scored as
|
|
@@ -942,10 +936,15 @@ class Contract:
|
|
| 942 |
self.max_pixels = int(mp) if mp else int(im.get("max_pixels", 0) or 0)
|
| 943 |
self.image_temperature = float(it) if it else float(im.get("temperature", self.temperature))
|
| 944 |
|
| 945 |
-
# the Box question (box.py):
|
|
|
|
|
|
|
| 946 |
bx = cfg.get("box") or {}
|
| 947 |
-
|
| 948 |
-
|
|
|
|
|
|
|
|
|
|
| 949 |
self.box_convention = os.environ.get("LIGHTNING_BOX_CONVENTION") or bx.get("convention") or "qwen1000"
|
| 950 |
self.box_temperature = float(os.environ.get("LIGHTNING_BOX_TEMPERATURE") or bx.get("temperature") or 1.0)
|
| 951 |
self.box_max_tokens = int(bx.get("max_tokens") or 64)
|
|
@@ -974,8 +973,9 @@ class Contract:
|
|
| 974 |
raise ValueError("box.generation_calibration: a must be in [0.2, 3] and b in [-5, 5] (the identity is a=1, b=0)")
|
| 975 |
if self.box_confidence not in ("tightness", "generation"):
|
| 976 |
raise ValueError("box.confidence must be tightness or generation")
|
| 977 |
-
|
| 978 |
-
|
|
|
|
| 979 |
if self.images and not self.chat:
|
| 980 |
raise ValueError("images need prompt.chat_template: the image path renders through the chat template")
|
| 981 |
if self.images and not (1 <= self.max_images <= 16 and 0.05 <= self.image_temperature <= 20.0):
|
|
@@ -1064,20 +1064,13 @@ def box_generation_args(c):
|
|
| 1064 |
return {"top_logprobs": c.box_top_logprobs} if c.box_confidence == "generation" else {}
|
| 1065 |
|
| 1066 |
|
| 1067 |
-
|
| 1068 |
-
|
|
|
|
|
|
|
| 1069 |
BOX_NOUL_TEXTS = {"true": "the statement holds", "false": "it does not"} # the trained yes/no texts
|
| 1070 |
|
| 1071 |
|
| 1072 |
-
def box_gate(c, questions):
|
| 1073 |
-
"""A 400 for any box question while serve_config box.enabled is off (the default)."""
|
| 1074 |
-
if getattr(c, "box_enabled", False):
|
| 1075 |
-
return
|
| 1076 |
-
entries = questions.values() if isinstance(questions, dict) else questions if isinstance(questions, list) else ()
|
| 1077 |
-
if any(isinstance(q, dict) and q.get("type") == "box" for q in entries):
|
| 1078 |
-
raise BadRequest(BOX_DISABLED)
|
| 1079 |
-
|
| 1080 |
-
|
| 1081 |
def bind_assets(body):
|
| 1082 |
"""The request's `assets` bound into the request: every reference becomes an image (assets.py); a bad map is a 400."""
|
| 1083 |
if not isinstance(body, dict) or ("assets" not in body and "_parts" not in body):
|
|
@@ -1094,15 +1087,6 @@ def bind_assets(body):
|
|
| 1094 |
# the Box grounding's constrained decode: an engine refusal naming one of these means it has no structured outputs
|
| 1095 |
GUIDED_UNAVAILABLE = re.compile(r"response_format|structured.?output|guided|grammar|json_schema|xgrammar|outlines", re.I)
|
| 1096 |
|
| 1097 |
-
|
| 1098 |
-
class _GuidedFallbacks:
|
| 1099 |
-
"""How often the Box grounding generation had to go unguided (an engine without structured outputs)."""
|
| 1100 |
-
|
| 1101 |
-
count = 0
|
| 1102 |
-
warned = False
|
| 1103 |
-
|
| 1104 |
-
|
| 1105 |
-
GUIDED_FALLBACKS = _GuidedFallbacks()
|
| 1106 |
_BOX_LOG = logging.getLogger("lightning.box")
|
| 1107 |
|
| 1108 |
|
|
@@ -1233,11 +1217,11 @@ class VLLM:
|
|
| 1233 |
"continue_final_message": True, "add_special_tokens": False,
|
| 1234 |
"chat_template_kwargs": {"enable_thinking": False}})["tokens"]
|
| 1235 |
|
| 1236 |
-
guided_fallback_max_tokens = 64 # the unguided budget when the schema is refused (box.max_tokens)
|
| 1237 |
-
|
| 1238 |
def chat_generate(self, messages, max_tokens=64, max_pixels=0, json_schema=None, top_logprobs=0):
|
| 1239 |
"""(text, prompt_tokens): one chat generation at temperature 0, thinking off (the Box grounding call);
|
| 1240 |
-
`json_schema`: the reply constrained to it (vLLM structured outputs, the OpenAI response_format shape).
|
|
|
|
|
|
|
| 1241 |
body = {"model": self.model, "messages": messages, "max_tokens": int(max_tokens), "temperature": 0,
|
| 1242 |
"chat_template_kwargs": {"enable_thinking": False}}
|
| 1243 |
if top_logprobs: # box.confidence "generation": the reply's per-token logprobs
|
|
@@ -1253,17 +1237,10 @@ class VLLM:
|
|
| 1253 |
status, r = self.call("POST", "/v1/chat/completions", guided)
|
| 1254 |
if status != 200 or not isinstance(r, dict):
|
| 1255 |
detail = json.dumps(r)[:500] if isinstance(r, dict) else str(r)[:500]
|
| 1256 |
-
if status
|
| 1257 |
-
|
| 1258 |
-
|
| 1259 |
-
|
| 1260 |
-
GUIDED_FALLBACKS.count += 1
|
| 1261 |
-
if not GUIDED_FALLBACKS.warned:
|
| 1262 |
-
GUIDED_FALLBACKS.warned = True
|
| 1263 |
-
_BOX_LOG.warning("box guided decoding unavailable on %s: free generation (%s)", self.base,
|
| 1264 |
-
detail[:200])
|
| 1265 |
-
body["max_tokens"] = int(max(max_tokens, self.guided_fallback_max_tokens))
|
| 1266 |
-
r = self.post("/v1/chat/completions", body, item_errors=(400, 422))
|
| 1267 |
try:
|
| 1268 |
text = r["choices"][0]["message"]["content"]
|
| 1269 |
except (KeyError, IndexError, TypeError) as e:
|
|
@@ -1365,12 +1342,12 @@ class Shim:
|
|
| 1365 |
return m # one engine serves both through the per-request flag
|
| 1366 |
if m == "bidirectional" and self.p is None:
|
| 1367 |
raise BadRequest("attention_mode bidirectional: two-way attention is not running on this deployment "
|
| 1368 |
-
"(serve.sh TWO_WAY=1, the default
|
| 1369 |
-
"
|
| 1370 |
if m == "causal" and self.v is None:
|
| 1371 |
raise BadRequest("attention_mode causal: one-way attention is not running on this deployment (the two-way "
|
| 1372 |
-
"engine alone is up); start serve.sh with TWO_WAY=0 for one-way only, or with "
|
| 1373 |
-
"
|
| 1374 |
return m
|
| 1375 |
|
| 1376 |
def check_two_way(self):
|
|
@@ -1603,7 +1580,6 @@ class Shim:
|
|
| 1603 |
return self.decide_questions(body)
|
| 1604 |
t0 = time.time()
|
| 1605 |
mode = self.mode(body)
|
| 1606 |
-
box_gate(self.c, body["questions"])
|
| 1607 |
if "assets" in body and not self.c.images:
|
| 1608 |
raise BadRequest("unsupported_assets: this model reads text only; image assets are not supported")
|
| 1609 |
body = bind_assets(body) # `assets`: references become images (a 400 on a bad map)
|
|
@@ -1614,8 +1590,8 @@ class Shim:
|
|
| 1614 |
raise BadRequest("a box question needs an image deployment")
|
| 1615 |
if self.v is None:
|
| 1616 |
raise BadRequest("a box question is a generation and needs the one-way (generate-mode) vLLM, which is not "
|
| 1617 |
-
"running:
|
| 1618 |
-
"
|
| 1619 |
if "state" not in body:
|
| 1620 |
raise Unprocessable("expected a JSON object with `state` and a `questions` object")
|
| 1621 |
self.check_backend()
|
|
@@ -1647,9 +1623,8 @@ class Shim:
|
|
| 1647 |
def generate(image_uri, prompt):
|
| 1648 |
system = _box.SYSTEM_BY_CONVENTION.get(c.box_convention, _box.SYSTEM)
|
| 1649 |
messages = chat_messages(system, prompt, "", [image_uri])[:-1] # no prefill: a free generation
|
| 1650 |
-
schema = _box.SCHEMAS
|
| 1651 |
-
n = min(c.box_max_tokens, _box.GUIDED_MAX_TOKENS)
|
| 1652 |
-
self.v.guided_fallback_max_tokens = c.box_max_tokens
|
| 1653 |
return self.v.chat_generate(messages, n, c.max_pixels, json_schema=schema, **box_generation_args(c))
|
| 1654 |
|
| 1655 |
def read_noul(image_uri, question_text):
|
|
@@ -1857,7 +1832,8 @@ class Shim:
|
|
| 1857 |
"temperature": c.image_temperature, "verified": bool(self.chat_ok)}}
|
| 1858 |
if c.images else {}),
|
| 1859 |
"attention_mode": self.default_mode(),
|
| 1860 |
-
"modes": [m for m, e in (("causal", self.v), ("bidirectional", self.p)) if e is not None]
|
|
|
|
| 1861 |
**({"two_way": {**c.two_way.describe(), "backend": f"vllm {self.p.base}", "verified": bool(self.two_way_ok),
|
| 1862 |
"probe_anchor_distance": self.two_way_anchor, "probe_separation": self.two_way_separation}}
|
| 1863 |
if self.p is not None else {})}
|
|
@@ -2052,6 +2028,12 @@ def make_handler(shim):
|
|
| 2052 |
shim.check_backend()
|
| 2053 |
except (UpstreamError, Unprocessable) as e:
|
| 2054 |
return self._send(503, {**shim.health(), "error": str(e)})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2055 |
return self._send(200, shim.health())
|
| 2056 |
if self.path.startswith("/v1/models"):
|
| 2057 |
return self._send(200, {"object": "list", "data": [{"id": shim.c.model, "readout": "native label "
|
|
|
|
| 32 |
`logprob_token_ids` readout, so the prompt is the text prompt plus the image tokens. A request without an image
|
| 33 |
takes the text path above, unchanged.
|
| 34 |
|
| 35 |
+
TWO-WAY READING (the recommended default; serve.sh TWO_WAY=1)
|
| 36 |
+
The weights were trained to answer under two attention patterns: one-way (causal, the readout above) and two-way
|
| 37 |
+
(bidirectional attention on the full-attention layers; the Gated DeltaNet layers stay causal). serve.sh serves
|
| 38 |
+
two-way on ONE generate-mode engine of the vLLM build with per-request attention (github.com/h2oai/vllm, commit
|
| 39 |
+
6bc6d5a839923abd64ab1f63a513258d74a5e16f; SHIM_TWO_WAY_FLAG=1): a two-way read carries vllm_xargs
|
| 40 |
+
attention_mode=bidirectional and comes back through the same `logprob_token_ids` readout; the same engine answers
|
| 41 |
+
one-way requests and Box questions. TWO_WAY=0 serves one-way only, on stock vLLM (the shim started with --vllm).
|
| 42 |
+
A request chooses with `"attention_mode": "bidirectional"` or `"causal"` (also "two-way" / "one-way"); without it
|
| 43 |
+
the deployment's default applies (two-way on the one engine; serve_config.json two_way.default /
|
| 44 |
+
SHIM_ATTENTION_MODE). A request for a mode that is not running is a 400, never a silent answer in the other mode;
|
| 45 |
+
every response states the mode it was read in. The two-way temperatures and yes/no floor are the block's own
|
| 46 |
+
(two_way.temperature, two_way.noul_floor, two_way.image_temperature; the SHIM_* overrides apply to both modes); a
|
| 47 |
+
missing one falls back to the one-way value with a WARNING line. Before the first two-way answer the shim reads
|
| 48 |
+
three fixed probes flagged and unflagged: the flagged answers must be within two_way.probe_tolerance of the
|
| 49 |
+
answers recorded on the release weights (two_way.probe_reference) and differ from the unflagged ones (an engine
|
| 50 |
+
without the build ignores the flag); any failure is a 503, kept 10 s (SHIM_TWO_WAY_RETRY_SECONDS) before the
|
| 51 |
+
engine is checked again. The earlier two-engine layout (a pooling-runner engine, --vllm-two-way, reading the final
|
| 52 |
+
hidden state with label_rows.lightning and pooled_readout.py) is still accepted by the shim for a manual start but
|
| 53 |
+
is no longer supported by serve.sh or the model card.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
STATUS CODES (an evaluation runner stops after three consecutive failures unless a failure is a 422): a request this
|
| 56 |
system cannot answer -- too many options, a malformed question, a prompt over vLLM's context -- is a 422, scored as
|
|
|
|
| 936 |
self.max_pixels = int(mp) if mp else int(im.get("max_pixels", 0) or 0)
|
| 937 |
self.image_temperature = float(it) if it else float(im.get("temperature", self.temperature))
|
| 938 |
|
| 939 |
+
# the Box question (box.py): always answered on an image deployment (no on/off switch; the grounding is a
|
| 940 |
+
# guided generation, refused with BOX_NEEDS_GUIDED by an engine without structured outputs); the grounding
|
| 941 |
+
# convention, the readout temperature
|
| 942 |
bx = cfg.get("box") or {}
|
| 943 |
+
old = [k for k in BOX_REMOVED_SWITCHES if os.environ.get(k, "").strip()] + \
|
| 944 |
+
[f"box.{k}" for k in ("enabled", "guided") if k in bx]
|
| 945 |
+
if old:
|
| 946 |
+
sys.stderr.write(f"shim: {', '.join(old)} ignored: box questions are always answered on an image "
|
| 947 |
+
f"deployment, by guided generation (there is no box on/off setting)\n")
|
| 948 |
self.box_convention = os.environ.get("LIGHTNING_BOX_CONVENTION") or bx.get("convention") or "qwen1000"
|
| 949 |
self.box_temperature = float(os.environ.get("LIGHTNING_BOX_TEMPERATURE") or bx.get("temperature") or 1.0)
|
| 950 |
self.box_max_tokens = int(bx.get("max_tokens") or 64)
|
|
|
|
| 973 |
raise ValueError("box.generation_calibration: a must be in [0.2, 3] and b in [-5, 5] (the identity is a=1, b=0)")
|
| 974 |
if self.box_confidence not in ("tightness", "generation"):
|
| 975 |
raise ValueError("box.confidence must be tightness or generation")
|
| 976 |
+
if self.images and self.box_mode in ("generate", "hybrid") and self.box_convention not in _sibling("box").SCHEMAS:
|
| 977 |
+
raise ValueError(f"box convention {self.box_convention!r} has no guided-generation schema (box mode "
|
| 978 |
+
f"{self.box_mode!r} generates the box): use one of {sorted(_sibling('box').SCHEMAS)}")
|
| 979 |
if self.images and not self.chat:
|
| 980 |
raise ValueError("images need prompt.chat_template: the image path renders through the chat template")
|
| 981 |
if self.images and not (1 <= self.max_images <= 16 and 0.05 <= self.image_temperature <= 20.0):
|
|
|
|
| 1064 |
return {"top_logprobs": c.box_top_logprobs} if c.box_confidence == "generation" else {}
|
| 1065 |
|
| 1066 |
|
| 1067 |
+
BOX_NEEDS_GUIDED = ("unsupported_question_type: question type `box` (a bounding box) needs guided generation (structured "
|
| 1068 |
+
"outputs, a JSON schema) and this engine refused it; serve vLLM with structured outputs on. Other "
|
| 1069 |
+
"question types are unaffected")
|
| 1070 |
+
BOX_REMOVED_SWITCHES = ("LIGHTNING_BOX_ENABLED", "LIGHTNING_BOX_GUIDED") # no longer settings: ignored, said once
|
| 1071 |
BOX_NOUL_TEXTS = {"true": "the statement holds", "false": "it does not"} # the trained yes/no texts
|
| 1072 |
|
| 1073 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1074 |
def bind_assets(body):
|
| 1075 |
"""The request's `assets` bound into the request: every reference becomes an image (assets.py); a bad map is a 400."""
|
| 1076 |
if not isinstance(body, dict) or ("assets" not in body and "_parts" not in body):
|
|
|
|
| 1087 |
# the Box grounding's constrained decode: an engine refusal naming one of these means it has no structured outputs
|
| 1088 |
GUIDED_UNAVAILABLE = re.compile(r"response_format|structured.?output|guided|grammar|json_schema|xgrammar|outlines", re.I)
|
| 1089 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1090 |
_BOX_LOG = logging.getLogger("lightning.box")
|
| 1091 |
|
| 1092 |
|
|
|
|
| 1217 |
"continue_final_message": True, "add_special_tokens": False,
|
| 1218 |
"chat_template_kwargs": {"enable_thinking": False}})["tokens"]
|
| 1219 |
|
|
|
|
|
|
|
| 1220 |
def chat_generate(self, messages, max_tokens=64, max_pixels=0, json_schema=None, top_logprobs=0):
|
| 1221 |
"""(text, prompt_tokens): one chat generation at temperature 0, thinking off (the Box grounding call);
|
| 1222 |
+
`json_schema`: the reply constrained to it (vLLM structured outputs, the OpenAI response_format shape). An
|
| 1223 |
+
engine that refuses the schema (no structured outputs) refuses the box question: a 422 with BOX_NEEDS_GUIDED,
|
| 1224 |
+
never an unguided generation."""
|
| 1225 |
body = {"model": self.model, "messages": messages, "max_tokens": int(max_tokens), "temperature": 0,
|
| 1226 |
"chat_template_kwargs": {"enable_thinking": False}}
|
| 1227 |
if top_logprobs: # box.confidence "generation": the reply's per-token logprobs
|
|
|
|
| 1237 |
status, r = self.call("POST", "/v1/chat/completions", guided)
|
| 1238 |
if status != 200 or not isinstance(r, dict):
|
| 1239 |
detail = json.dumps(r)[:500] if isinstance(r, dict) else str(r)[:500]
|
| 1240 |
+
if status in (400, 422) and GUIDED_UNAVAILABLE.search(detail):
|
| 1241 |
+
_BOX_LOG.warning("box question refused: guided decoding unavailable on %s (%s)", self.base, detail[:200])
|
| 1242 |
+
raise Unprocessable(BOX_NEEDS_GUIDED)
|
| 1243 |
+
self.refuse("/v1/chat/completions", status, r, (400, 422))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1244 |
try:
|
| 1245 |
text = r["choices"][0]["message"]["content"]
|
| 1246 |
except (KeyError, IndexError, TypeError) as e:
|
|
|
|
| 1342 |
return m # one engine serves both through the per-request flag
|
| 1343 |
if m == "bidirectional" and self.p is None:
|
| 1344 |
raise BadRequest("attention_mode bidirectional: two-way attention is not running on this deployment "
|
| 1345 |
+
"(serve.sh with TWO_WAY=1, the default, serves it on one engine of the per-request "
|
| 1346 |
+
"attention build; see the model card)")
|
| 1347 |
if m == "causal" and self.v is None:
|
| 1348 |
raise BadRequest("attention_mode causal: one-way attention is not running on this deployment (the two-way "
|
| 1349 |
+
"engine alone is up); start serve.sh with TWO_WAY=0 for one-way only, or with the default one "
|
| 1350 |
+
"engine of the per-request attention build, which serves both")
|
| 1351 |
return m
|
| 1352 |
|
| 1353 |
def check_two_way(self):
|
|
|
|
| 1580 |
return self.decide_questions(body)
|
| 1581 |
t0 = time.time()
|
| 1582 |
mode = self.mode(body)
|
|
|
|
| 1583 |
if "assets" in body and not self.c.images:
|
| 1584 |
raise BadRequest("unsupported_assets: this model reads text only; image assets are not supported")
|
| 1585 |
body = bind_assets(body) # `assets`: references become images (a 400 on a bad map)
|
|
|
|
| 1590 |
raise BadRequest("a box question needs an image deployment")
|
| 1591 |
if self.v is None:
|
| 1592 |
raise BadRequest("a box question is a generation and needs the one-way (generate-mode) vLLM, which is not "
|
| 1593 |
+
"running: start serve.sh with the default one engine of the per-request attention build "
|
| 1594 |
+
"(it serves both readings), or with TWO_WAY=0")
|
| 1595 |
if "state" not in body:
|
| 1596 |
raise Unprocessable("expected a JSON object with `state` and a `questions` object")
|
| 1597 |
self.check_backend()
|
|
|
|
| 1623 |
def generate(image_uri, prompt):
|
| 1624 |
system = _box.SYSTEM_BY_CONVENTION.get(c.box_convention, _box.SYSTEM)
|
| 1625 |
messages = chat_messages(system, prompt, "", [image_uri])[:-1] # no prefill: a free generation
|
| 1626 |
+
schema = _box.SCHEMAS[c.box_convention] # always guided (the Contract checked the convention)
|
| 1627 |
+
n = min(c.box_max_tokens, _box.GUIDED_MAX_TOKENS)
|
|
|
|
| 1628 |
return self.v.chat_generate(messages, n, c.max_pixels, json_schema=schema, **box_generation_args(c))
|
| 1629 |
|
| 1630 |
def read_noul(image_uri, question_text):
|
|
|
|
| 1832 |
"temperature": c.image_temperature, "verified": bool(self.chat_ok)}}
|
| 1833 |
if c.images else {}),
|
| 1834 |
"attention_mode": self.default_mode(),
|
| 1835 |
+
"modes": ([m for m, e in (("causal", self.v), ("bidirectional", self.p)) if e is not None]
|
| 1836 |
+
+ (["bidirectional"] if self.two_way_flag and self.p is None else [])),
|
| 1837 |
**({"two_way": {**c.two_way.describe(), "backend": f"vllm {self.p.base}", "verified": bool(self.two_way_ok),
|
| 1838 |
"probe_anchor_distance": self.two_way_anchor, "probe_separation": self.two_way_separation}}
|
| 1839 |
if self.p is not None else {})}
|
|
|
|
| 2028 |
shim.check_backend()
|
| 2029 |
except (UpstreamError, Unprocessable) as e:
|
| 2030 |
return self._send(503, {**shim.health(), "error": str(e)})
|
| 2031 |
+
# SHIM_READY_FILE (set by serve.sh): not ready until that file exists, i.e. until the launcher's warm-up
|
| 2032 |
+
# has passed; "/health?live=1" answers meanwhile (the launcher's own check)
|
| 2033 |
+
flag = os.environ.get("SHIM_READY_FILE", "").strip()
|
| 2034 |
+
live = urllib.parse.parse_qs(urllib.parse.urlsplit(self.path).query).get("live") == ["1"]
|
| 2035 |
+
if flag and not os.path.exists(flag) and not live:
|
| 2036 |
+
return self._send(503, {**shim.health(), "ok": False, "warming": True})
|
| 2037 |
return self._send(200, shim.health())
|
| 2038 |
if self.path.startswith("/v1/models"):
|
| 2039 |
return self._send(200, {"object": "list", "data": [{"id": shim.c.model, "readout": "native label "
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5d84c671e5bc282ccabc005bf5faea41a2d673bd133e19617ab41b57dbcc6c16
|
| 3 |
+
size 5136694595
|
model.safetensors.index.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"metadata": {
|
| 3 |
-
"total_size":
|
| 4 |
},
|
| 5 |
"weight_map": {
|
| 6 |
"language_model.model.embed_tokens.biases": "model.safetensors",
|
|
|
|
| 1 |
{
|
| 2 |
"metadata": {
|
| 3 |
+
"total_size": 5136540672
|
| 4 |
},
|
| 5 |
"weight_map": {
|
| 6 |
"language_model.model.embed_tokens.biases": "model.safetensors",
|
serve_config.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
{
|
| 2 |
"box": {
|
| 3 |
-
"enabled": false,
|
| 4 |
"mode": "generate",
|
| 5 |
"confidence": "generation",
|
| 6 |
"presence": true,
|
|
@@ -80,29 +79,29 @@
|
|
| 80 |
"x",
|
| 81 |
"y",
|
| 82 |
"z",
|
| 83 |
-
"
|
| 84 |
-
"
|
| 85 |
-
"
|
| 86 |
-
"
|
| 87 |
-
"
|
| 88 |
-
"
|
| 89 |
-
"
|
| 90 |
-
"
|
| 91 |
-
"
|
| 92 |
-
"
|
| 93 |
-
"
|
| 94 |
-
"
|
| 95 |
-
"
|
| 96 |
-
"
|
| 97 |
-
"
|
| 98 |
-
"
|
| 99 |
-
"
|
| 100 |
-
"
|
| 101 |
-
"
|
| 102 |
-
"
|
| 103 |
-
"
|
| 104 |
-
"
|
| 105 |
-
"
|
| 106 |
"in",
|
| 107 |
"er",
|
| 108 |
"on",
|
|
@@ -304,39 +303,39 @@
|
|
| 304 |
"probe_reference": [
|
| 305 |
{
|
| 306 |
"outage": {
|
| 307 |
-
"true": 0.
|
| 308 |
-
"false": 0.
|
| 309 |
},
|
| 310 |
"team": {
|
| 311 |
-
"payments": 0.
|
| 312 |
-
"web": 0.
|
| 313 |
-
"support": 0.
|
| 314 |
}
|
| 315 |
},
|
| 316 |
{
|
| 317 |
"lost": {
|
| 318 |
-
"true": 0.
|
| 319 |
-
"false": 0.
|
| 320 |
},
|
| 321 |
"next": {
|
| 322 |
-
"wait": 0.
|
| 323 |
-
"trace": 0.
|
| 324 |
-
"refund": 0.
|
| 325 |
}
|
| 326 |
},
|
| 327 |
{
|
| 328 |
"tone": {
|
| 329 |
-
"0": 0.
|
| 330 |
-
"1": 0.
|
| 331 |
-
"2": 0.
|
| 332 |
},
|
| 333 |
"issue": {
|
| 334 |
-
"battery": 0.
|
| 335 |
-
"screen": 0.
|
| 336 |
-
"support": 0.
|
| 337 |
-
"none": 0.
|
| 338 |
}
|
| 339 |
}
|
| 340 |
]
|
| 341 |
}
|
| 342 |
-
}
|
|
|
|
| 1 |
{
|
| 2 |
"box": {
|
|
|
|
| 3 |
"mode": "generate",
|
| 4 |
"confidence": "generation",
|
| 5 |
"presence": true,
|
|
|
|
| 79 |
"x",
|
| 80 |
"y",
|
| 81 |
"z",
|
| 82 |
+
"α",
|
| 83 |
+
"β",
|
| 84 |
+
"γ",
|
| 85 |
+
"δ",
|
| 86 |
+
"ε",
|
| 87 |
+
"ζ",
|
| 88 |
+
"η",
|
| 89 |
+
"θ",
|
| 90 |
+
"ι",
|
| 91 |
+
"κ",
|
| 92 |
+
"λ",
|
| 93 |
+
"μ",
|
| 94 |
+
"ν",
|
| 95 |
+
"ξ",
|
| 96 |
+
"ο",
|
| 97 |
+
"π",
|
| 98 |
+
"σ",
|
| 99 |
+
"τ",
|
| 100 |
+
"υ",
|
| 101 |
+
"φ",
|
| 102 |
+
"χ",
|
| 103 |
+
"ψ",
|
| 104 |
+
"ω",
|
| 105 |
"in",
|
| 106 |
"er",
|
| 107 |
"on",
|
|
|
|
| 303 |
"probe_reference": [
|
| 304 |
{
|
| 305 |
"outage": {
|
| 306 |
+
"true": 0.685144,
|
| 307 |
+
"false": 0.314856
|
| 308 |
},
|
| 309 |
"team": {
|
| 310 |
+
"payments": 0.820955,
|
| 311 |
+
"web": 0.094504,
|
| 312 |
+
"support": 0.084542
|
| 313 |
}
|
| 314 |
},
|
| 315 |
{
|
| 316 |
"lost": {
|
| 317 |
+
"true": 0.133666,
|
| 318 |
+
"false": 0.866334
|
| 319 |
},
|
| 320 |
"next": {
|
| 321 |
+
"wait": 0.122635,
|
| 322 |
+
"trace": 0.818608,
|
| 323 |
+
"refund": 0.058757
|
| 324 |
}
|
| 325 |
},
|
| 326 |
{
|
| 327 |
"tone": {
|
| 328 |
+
"0": 0.095027,
|
| 329 |
+
"1": 0.755358,
|
| 330 |
+
"2": 0.149615
|
| 331 |
},
|
| 332 |
"issue": {
|
| 333 |
+
"battery": 0.047393,
|
| 334 |
+
"screen": 0.877561,
|
| 335 |
+
"support": 0.0401,
|
| 336 |
+
"none": 0.034946
|
| 337 |
}
|
| 338 |
}
|
| 339 |
]
|
| 340 |
}
|
| 341 |
+
}
|