dowands commited on
Commit
24ef3cd
·
verified ·
1 Parent(s): 69d1dac

Add files using upload-large-folder tool

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
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.
LICENSE_NOTICE.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # License notice (NeoJev)
2
+
3
+ This folder is a derivative of **Qwen3.8-27B** by the Qwen team, Alibaba Group, released under the Apache License 2.0 (https://huggingface.co/Qwen/Qwen3.8-27B). The weights here come from the MLX 4-bit conversion `mlx-community/Qwen3.8-27B-4bit` (Apache-2.0).
4
+
5
+ Changes made:
6
+
7
+ - kept only the first 56 of 64 decoder layers, the embeddings, the final norm and the LM head; removed the vision tower
8
+ - added `decider_head.npz`, a readout head trained by self-distillation from the full 64-layer model on public data (sources listed in README.md)
9
+ - added `decider.py` (MLX) and `decider_cuda.py` (PyTorch/CUDA), inference code
10
+
11
+ The whole folder is distributed under the Apache License 2.0; the full text, with the original "Copyright 2026 Alibaba Cloud" notice, is in `LICENSE`. This project is not affiliated with Alibaba, the Qwen team, or TypeSafe AI.
README.md ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen3.8-27B
4
+ library_name: mlx
5
+ pipeline_tag: text-classification
6
+ tags:
7
+ - mlx
8
+ - neojev
9
+ - jev
10
+ - system-one
11
+ - typed-decisions
12
+ - classification
13
+ - calibration
14
+ - apple-silicon
15
+ ---
16
+
17
+
18
+ # NeoJev-Qwen3.8-27B-L56-MLX
19
+
20
+ **NeoJev** gives you typed, probabilistic decisions from Qwen3.8-27B in **one forward pass**, on Apple Silicon (MLX) or NVIDIA GPUs (PyTorch). You pass any text (the *state*) and a set of questions; you get back one of the options you supplied, a probability for every option, and a confidence. Nothing is generated and nothing is parsed, so an answer outside your schema is impossible by construction.
21
+
22
+ NeoJev is an open, local take on the "System One model" idea popularized by TypeSafe AI's Jev (typed decisions instead of text). It is an independent project and is **not** affiliated with or endorsed by TypeSafe AI.
23
+
24
+ | backend | code | weights | measured on | mean accuracy | median / p99 latency |
25
+ |---|---|---|---|---|---|
26
+ | Apple Silicon (MLX) | `decider.py` | [dowands/NeoJev-Qwen3.8-27B-L56-MLX](https://huggingface.co/dowands/NeoJev-Qwen3.8-27B-L56-MLX) (4-bit, 56 layers) | M5 Pro 64 GB | 0.727 | 310 / 571 ms |
27
+ | NVIDIA GPU (PyTorch) | `decider_cuda.py` | [dowands/NeoJev-Qwen3.8-27B-L56](https://huggingface.co/dowands/NeoJev-Qwen3.8-27B-L56) (FP8, 56 layers) | L20 48 GB | 0.724 | 107 / 133 ms |
28
+
29
+ Both backends share the same readout head (`decider_head.npz`); it transferred from MLX 4-bit to CUDA FP8 without re-training.
30
+
31
+ ## Quick start (Apple Silicon)
32
+
33
+ This repository is the **MLX build** (4-bit, 56 layers, 13.4 GB). For NVIDIA GPUs use [dowands/NeoJev-Qwen3.8-27B-L56](https://huggingface.co/dowands/NeoJev-Qwen3.8-27B-L56).
34
+
35
+ ```bash
36
+ pip install mlx==0.32.2 mlx-lm==0.31.3 numpy huggingface_hub
37
+ huggingface-cli download dowands/NeoJev-Qwen3.8-27B-L56-MLX decider.py --local-dir .
38
+ ```
39
+
40
+ ```python
41
+ from decider import Decider
42
+ d = Decider("dowands/NeoJev-Qwen3.8-27B-L56-MLX") # downloads the weights and the readout head on first use
43
+ d.ask(
44
+ "Customer emailed twice about a failed refund for order #4417 and says they will dispute the charge tomorrow.",
45
+ {
46
+ "queue": {"type": "choice", "options": ["Billing and Payments", "Technical Support", "Sales"],
47
+ "prompt": "Which team should handle this ticket?"},
48
+ "urgency": {"type": "score", "levels": ["low", "medium", "high"], "prompt": "How urgent is it?"},
49
+ "churn": {"type": "noul", "statement": "The customer is likely to leave."},
50
+ },
51
+ )
52
+ # {"queue": {"value": "Billing and Payments", "probs": {...}, "confidence": 0.87}, "urgency": {..., "expected_index": 1.37},
53
+ # "churn": {"value": 0.41, ...}, "_tokens": 43}
54
+ ```
55
+
56
+ Question types:
57
+
58
+ | type | fields | returns |
59
+ |---|---|---|
60
+ | `choice` | `options` (2 to 16), `prompt` | the chosen option, per-option probabilities |
61
+ | `score` | `levels` (ordered), `prompt` | the chosen level, per-level probabilities, `expected_index` |
62
+ | `noul` | `statement` | probability that the statement is true |
63
+
64
+ `cache_schema=True` (default) puts the questions first and caches them across calls with the same question set; use it when you ask the same questions about many texts. Use `cache_schema=False` for one-off questions whose options change every call (for example multiple-choice QA).
65
+
66
+ ## How it works
67
+
68
+ 1. **Layout.** The questions are prefilled once per schema and cached. Each call only runs the state plus one short trigger per question (`Q1:`, `Q2:`, ...), all in a single forward pass. The answer for each question is read at its trigger position.
69
+ 2. **Early exit.** Only the first 56 of the 64 decoder layers are kept (13.4 GB of weights instead of about 16 GB), which cuts compute by 12.5%.
70
+ 3. **Label-free readout head.** Reading the option logits directly from layer 56 is poor (the plain "logit lens" gets 0.663 mean accuracy on our evaluation set). A small head, `h + (h U) V + b + c[position]` (rank 1024, followed by the model's own final norm and LM head), maps the layer-56 state to the option distribution. It was trained by **self-distillation**: the target is the full 64-layer model's option distribution in the original prompt layout, on 4,000 texts x randomly generated questions (10,035 questions). **No labels are used**, so the head is task-agnostic and you do not need any data to use it.
71
+ 4. **Calibration.** One global temperature (T = 1.373), fitted once on public labels from the distillation sources.
72
+ 5. **Token budget.** Each call is capped at 160 tokens by default; longer states keep their first 40% and last 60% of tokens.
73
+
74
+ Distillation sources (texts only, none overlap the evaluation tasks below): SetFit bbc-news, 20_newsgroups, enron_spam, subj, sst5, toxic_conversations, amazon_counterfactual_en, student-question-categories, CR, rte, mrpc, qnli; cais/mmlu; allenai/qasc; ehovy/race; openlifescienceai/medmcqa.
75
+
76
+ ## Evaluation
77
+
78
+ These 11 tasks are held out from training: none of their texts, questions or labels were used. There are 500 test items per task and 5,500 calls in total. The baseline is the same base model with all 64 layers, reading the option logits zero-shot in the natural layout (state first, one question at a time).
79
+
80
+ | task / question | baseline acc / ECE | this model acc / ECE |
81
+ |---|---|---|
82
+ | customer-support-tickets / queue (10-way) | 0.264 / 0.480 | 0.322 / 0.060 |
83
+ | customer-support-tickets / priority | 0.420 / 0.341 | 0.380 / 0.251 |
84
+ | customer-support-tickets / type | 0.584 / 0.207 | 0.454 / 0.138 |
85
+ | yelp_review_full / stars (1-5) | 0.592 / 0.240 | 0.534 / 0.079 |
86
+ | yelp_review_full / 4-5 stars (yes/no) | 0.916 / 0.020 | 0.850 / 0.189 |
87
+ | ag_news / topic | 0.870 / 0.096 | 0.874 / 0.071 |
88
+ | boolq | 0.854 / 0.069 | 0.804 / 0.098 |
89
+ | dair-ai/emotion | 0.596 / 0.250 | 0.588 / 0.073 |
90
+ | glue/mnli | 0.870 / 0.059 | 0.838 / 0.113 |
91
+ | commonsense_qa | 0.840 / 0.068 | 0.804 / 0.050 |
92
+ | openbookqa | 0.924 / 0.031 | 0.908 / 0.089 |
93
+ | ai2_arc (challenge) | 0.964 / 0.017 | 0.962 / 0.111 |
94
+ | sciq | 0.990 / 0.008 | 0.992 / 0.081 |
95
+ | tweet_eval / irony | 0.874 / 0.138 | 0.866 / 0.189 |
96
+ | **mean** | **0.754 / 0.145** | **0.727 / 0.114** |
97
+
98
+ The mean accuracy is 2.7 points lower than the baseline (paired bootstrap 95% CI: -3.6 to -1.9).
99
+
100
+ **NVIDIA backend** (same 11 tasks, 500 items each, `Qwen/Qwen3.8-27B-FP8` with the first 56 layers, NVIDIA L20 48 GB, torch 2.11 + cu128, transformers 5.16.1, flash-linear-attention, causal-conv1d): mean accuracy **0.724**, mean ECE 0.103, latency median 107 ms / p90 132 ms / p99 133 ms, 99.96% of calls under 500 ms, peak GPU memory 25.8 GB. Two of the 5,500 calls took 9 to 14 s, most likely Triton autotuning on a new input shape. With a 1,000-token budget (no truncation) the accuracy was 0.724 and p99 208 ms, so the 160-token default costs almost nothing here.
101
+
102
+ **Latency** was measured on an Apple M5 Pro with 64 GB, MLX 0.32.2 and mlx-lm 0.31.3, one call at a time, with a remote-desktop session running during the measurement:
103
+
104
+ | | median | p90 | p99 | under 500 ms |
105
+ |---|---|---|---|---|
106
+ | baseline (64 layers, natural layout) | 560 ms | | | |
107
+ | this model | 310 ms | 475 ms | 571 ms | 93.2% |
108
+
109
+ Latency is roughly linear in tokens per call. Short texts (tweets, one-line tickets) take 180 to 300 ms; the 160-token cap is what keeps long texts near 500 ms. Lower `token_budget` if you need a hard ceiling. Background GPU load (screen sharing, other ML jobs) moves these numbers noticeably, because the display and the model share the GPU.
110
+
111
+ ## How it compares
112
+
113
+ All methods were run on the same machine and the same held-out items (the first 200 test items of each of the 11 tasks, 14 questions, 2,200 calls). Accuracy is averaged over the 14 questions.
114
+
115
+ | method | mean accuracy | mean ECE | median latency per call | format errors |
116
+ |---|---|---|---|---|
117
+ | Qwen3.8-27B, all 64 layers, option logits (upper reference) | 0.745 | 0.160 | 563 ms | 0% |
118
+ | **this model** | **0.721** | **0.117** | **310 ms** | 0% (by construction) |
119
+ | Qwen3-Embedding-8B, similarity to each option | 0.599 | 0.165 | 3,472 ms* | 0% |
120
+ | Qwen3.5-0.8B, option logits | 0.554 | 0.181 | 28 ms | 0% |
121
+ | facebook/bart-large-mnli, HF zero-shot pipeline | 0.488 | 0.153 | 292 ms | 0% |
122
+ | always the most common answer | 0.357 | | | |
123
+
124
+ A second comparison adds the way most people use an LLM for this, which is to ask the full model to write a JSON answer. That is slower, so it ran on the first 100 items per task:
125
+
126
+ | method (100 items/task) | mean accuracy | median latency | format errors |
127
+ |---|---|---|---|
128
+ | Qwen3.8-27B, 64 layers, writes JSON (greedy, thinking off) | 0.739 | 1,757 ms | 0% |
129
+ | Qwen3.8-27B, 64 layers, option logits | 0.736 | 562 ms | 0% |
130
+ | **this model** | **0.711** | **309 ms** | 0% |
131
+
132
+ Reading the tables:
133
+
134
+ - This model is 2.4 to 2.8 points below the full model (depending on the item subset; 2.7 on all 500 items per task), and 5.7 times faster than asking the full model for JSON.
135
+ - It is 12 to 23 points above the other models that fit on a laptop and answer arbitrary questions zero-shot.
136
+ - The customer-support-tickets labels are synthetic and noisy: every method sits near the majority baseline there.
137
+ - bart-large-mnli was used through the generic zero-shot pipeline (options as labels in a template), not its native NLI format, so its MNLI score (0.33) does not reflect its NLI ability.
138
+
139
+ \* The embedding baseline was served by a local llama.cpp server (Q4_K_M), one request per call; its latency is not optimized.
140
+
141
+ On standard public benchmarks within the held-out set (500-item zero-shot subsets, this model): ARC-Challenge 0.962, OpenBookQA 0.908, CommonsenseQA 0.804, SciQ 0.992, BoolQ 0.804, MNLI 0.838, AG News 0.874. These are not comparable to leaderboard numbers that use few-shot prompts, chain of thought or the full test sets.
142
+
143
+ ## Compared with other open Jev-style models (JevBench)
144
+
145
+ [JevBench](https://github.com/fstandhartinger/jevbench) (MIT, Benchmark Heaven) is the independent benchmark most Jev-class projects report on. We ran NeoJev on its **231 public items** with JevBench's own scoring code. Each question was translated the same way for every item, and the translation was fixed before the run (`scripts/run_jevbench.py`). The table below compares NeoJev with the **most downloaded or most starred** open peers that JevBench measured. Peer numbers come from JevBench's published v1.4 results (repo commit `26eb72d`, 24 Sep 2026); download and star counts were read on 25 Sep 2026.
146
+
147
+ | system | popularity | base | weights (memory) | public accuracy (231) | p50 / p95 latency | where the latency was measured | JevBench v1.4 score (rank of 76) |
148
+ |---|---|---|---|---|---|---|---|
149
+ | **NeoJev (this model), CUDA** | new | Qwen3.8-27B, 56 layers | 25.8 GB peak GPU (FP8) | **0.866** | **0.131 / 1.33 s** | NVIDIA L20, in-process, serial | not yet submitted |
150
+ | **NeoJev (this model), MLX** | new | Qwen3.8-27B, 56 layers | 13.4 GB (4-bit) | **0.870** | 0.51 / 8.4 s | Apple M5 Pro, in-process, serial | not yet submitted |
151
+ | Jev 1.13.0 (TypeSafe AI, closed) | | closed | n/a | 0.866 | 0.65 / 0.72 s | production API over the network | 63.3 (#1) |
152
+ | decider-2b (Mapika) | 130,658 HF downloads | Qwen3.5-2B | 3.8 GB | 0.710 | 0.26 / 0.28 s | JevBench server, network | 30.7 (#30) |
153
+ | openJev Verdict 1.4 | 19,449 HF downloads | ModernBERT-base 151M | about 0.6 GB (est.) | 0.576 | 0.31 / 0.92 s | CPU, 4 threads | 19.0 (#45) |
154
+ | Winnow-12B Q8 | 3,929 HF downloads | Gemma 4 12B | about 13 GB (est., Q8) | 0.857 | 0.23 / 0.41 s | JevBench server, network | 55.6 (#4) |
155
+ | Bespoke Nimble 9B | 2,624 HF downloads | Qwen3.5-9B + LoRA | about 18 GB (est., BF16) | 0.797 | 0.39 / 0.65 s | JevBench server, network | 18.7 (#47) |
156
+ | JevK5 v0.2 | 2,236 HF downloads | Qwen3.5-4B | 8.4 GB | 0.853 | not published | | 62.0 (#2) |
157
+ | JevOne (Juspay) | 1,174 HF downloads | Qwen3.6-35B-A3B | about 70 GB (est., BF16) | 0.896 | 0.087 / 0.145 s | RTX PRO 6000 96 GB, local | 25.5 (#38) |
158
+ | kev 8B | 6,785 GitHub stars | Qwen3-8B + LoRA | about 16 GB (est., BF16) | 0.714 | 0.59 / 1.15 s | JevBench server, network | 25.6 (#37) |
159
+ | SemIf (formerly OpenJev) | 4,250 GitHub stars | Qwen3.5-4B frozen | about 8 GB (est., BF16) | 0.810 | 0.20 / 0.32 s | RTX PRO 4500 32 GB | 47.7 (#8) |
160
+ | SimpleJev Qwen3.8-27B | 525 GitHub stars | Qwen3.8-27B frozen | about 54 GB (est., BF16) | 0.866 | 1.01 / 1.88 s | JevBench server, network | 34.6 (#25) |
161
+ | OpenJev (razorback16, NVFP4) | 404 GitHub stars | DiffusionGemma 26B-A4B | about 15 GB (est., NVFP4) | 0.818 | 0.24 / 0.31 s | RTX PRO 4500 32 GB | 36.9 (#21) |
162
+ | openjev-sglang | 321 GitHub stars | Qwen3.6-35B-A3B | about 70 GB (est., BF16) | 0.853 | 0.68 / 0.73 s | JevBench server, network | 27.7 (#33) |
163
+
164
+ How to read it:
165
+
166
+ - **Accuracy.** On the public items NeoJev matches Jev 1.13.0 and the other Qwen3.8-27B systems (0.862 to 0.870). It is above every popular small model: 0.71 for the most downloaded one, 0.85 for JevK5. Among open systems, only JevOne and NInfer Qwen3.8-Flash-Next (both 0.896, on 35B-class MoE models) and thinking-mode systems score higher. Frontier APIs (GPT, DeepSeek, Gemini) score higher as well.
167
+ - **Speed and memory.** Among the 27B-class systems, NeoJev's p50 is 0.13 s on an L20. SimpleJev and reflex-27b show 1.0 s and 1.9 s in JevBench's runs (with a network hop, on other hardware, so treat this as an order of magnitude only). NeoJev also needs about half the memory of a BF16 27B, because it runs 56 of 64 layers of the FP8 checkpoint. Its p95 is dominated by the long documents of the hard tier; the easy and standard tiers take 0.11 s.
168
+ - **Latency is not directly comparable across rows.** Many JevBench rows include a network round trip from JevBench's server, and every row ran on different hardware.
169
+ - **Why NeoJev has no official score.** The official JevBench score also needs the held-out and sealed items (which only JevBench runs; v1.4 adds 308 fresh sealed decisions), a judge tier, calibration and a cost figure. JevBench's own README applies a ×2 + 0.15 s latency adjustment to self-hosted endpoints.
170
+ - **Where the memory figures come from.** They are the published repository size where one exists (decider-2b, JevK5); otherwise they are an estimate of parameters × precision, marked "est.".
171
+
172
+ ## Limitations
173
+
174
+ - **2.7 points below the full model on average**, and worse on some questions: up to -13 points on the third question of a three-question schema (`customer-support-tickets / type`). Questions placed third or later in one call read less reliably, and answers change with question order (the same question can get a different confidence in position 1 and position 2). Keep the order fixed for a given use case, put the most important question first, or split long schemas across calls.
175
+ - **Yes/no statements are weaker than multiple choice** in this layout (-5 to -7 points on boolq and yelp 4-5 stars).
176
+ - **Calibration is not uniform.** The mean ECE is 0.114, but some questions sit at 0.19 to 0.25. If you have a few hundred labelled examples for your task, fit your own temperature on them.
177
+ - Choice questions support at most 16 options. The model was evaluated on English only.
178
+ - Long inputs are truncated to the token budget, so detail in the middle of a long text is lost.
179
+ - Needs Apple Silicon (MLX, about 15 GB of free unified memory) or an FP8-capable NVIDIA GPU with about 26 GB of memory. On the NVIDIA side the FP8 kernel path was tested on an L20 (Ada) only.
180
+
181
+ ## License
182
+
183
+ Apache-2.0, derived from [Qwen/Qwen3.8-27B](https://huggingface.co/Qwen/Qwen3.8-27B) (Apache-2.0) via `mlx-community/Qwen3.8-27B-4bit`. See `LICENSE_NOTICE.md`.
chat_template.jinja ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set image_count = namespace(value=0) %}
2
+ {%- set video_count = namespace(value=0) %}
3
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
4
+ {%- if content is string %}
5
+ {{- content }}
6
+ {%- elif content is iterable and content is not mapping %}
7
+ {%- for item in content %}
8
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
9
+ {%- if is_system_content %}
10
+ {{- raise_exception('System message cannot contain images.') }}
11
+ {%- endif %}
12
+ {%- if do_vision_count %}
13
+ {%- set image_count.value = image_count.value + 1 %}
14
+ {%- endif %}
15
+ {%- if add_vision_id %}
16
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
17
+ {%- endif %}
18
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
19
+ {%- elif 'video' in item or item.type == 'video' %}
20
+ {%- if is_system_content %}
21
+ {{- raise_exception('System message cannot contain videos.') }}
22
+ {%- endif %}
23
+ {%- if do_vision_count %}
24
+ {%- set video_count.value = video_count.value + 1 %}
25
+ {%- endif %}
26
+ {%- if add_vision_id %}
27
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
28
+ {%- endif %}
29
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
+ {%- elif 'text' in item %}
31
+ {{- item.text }}
32
+ {%- else %}
33
+ {{- raise_exception('Unexpected item type in content.') }}
34
+ {%- endif %}
35
+ {%- endfor %}
36
+ {%- elif content is none or content is undefined %}
37
+ {{- '' }}
38
+ {%- else %}
39
+ {{- raise_exception('Unexpected content type.') }}
40
+ {%- endif %}
41
+ {%- endmacro %}
42
+ {%- if not messages %}
43
+ {{- raise_exception('No messages provided.') }}
44
+ {%- endif %}
45
+ {%- set reasoning_instructions = '' %}
46
+ {%- if enable_thinking is undefined or enable_thinking is true %}
47
+ {%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %}
48
+ {%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %}
49
+ {{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }}
50
+ {%- endif %}
51
+ {%- if resolved_reasoning_effort == 'xhigh' %}
52
+ {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
53
+ {%- elif resolved_reasoning_effort == 'low' %}
54
+ {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
55
+ {%- endif %}
56
+ {%- endif %}
57
+ {%- if tools and tools is iterable and tools is not mapping %}
58
+ {{- '<|im_start|>system\n' }}
59
+ {%- if reasoning_instructions %}
60
+ {{- reasoning_instructions + '\n\n' }}
61
+ {%- endif %}
62
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
63
+ {%- for tool in tools %}
64
+ {{- "\n" }}
65
+ {{- tool | tojson }}
66
+ {%- endfor %}
67
+ {{- "\n</tools>" }}
68
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
69
+ {%- if messages[0].role == 'system' %}
70
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
71
+ {%- if content %}
72
+ {{- '\n\n' + content }}
73
+ {%- endif %}
74
+ {%- endif %}
75
+ {{- '<|im_end|>\n' }}
76
+ {%- else %}
77
+ {%- if messages[0].role == 'system' %}
78
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
79
+ {%- if content %}
80
+ {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' }}
81
+ {%- elif reasoning_instructions %}
82
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
83
+ {%- endif %}
84
+ {%- elif reasoning_instructions %}
85
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
86
+ {%- endif %}
87
+ {%- endif %}
88
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
89
+ {%- for message in messages[::-1] %}
90
+ {%- set index = (messages|length - 1) - loop.index0 %}
91
+ {%- if ns.multi_step_tool and message.role == "user" %}
92
+ {%- set content = render_content(message.content, false)|trim %}
93
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
94
+ {%- set ns.multi_step_tool = false %}
95
+ {%- set ns.last_query_index = index %}
96
+ {%- endif %}
97
+ {%- endif %}
98
+ {%- endfor %}
99
+ {%- if ns.multi_step_tool %}
100
+ {{- raise_exception('No user query found in messages.') }}
101
+ {%- endif %}
102
+ {%- for message in messages %}
103
+ {%- set content = render_content(message.content, true)|trim %}
104
+ {%- if message.role == "system" %}
105
+ {%- if not loop.first %}
106
+ {{- raise_exception('System message must be at the beginning.') }}
107
+ {%- endif %}
108
+ {%- elif message.role == "user" %}
109
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
110
+ {%- elif message.role == "assistant" %}
111
+ {%- set reasoning_content = '' %}
112
+ {%- if message.reasoning_content is string %}
113
+ {%- set reasoning_content = message.reasoning_content %}
114
+ {%- endif %}
115
+ {%- set reasoning_content = reasoning_content|trim %}
116
+ {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %}
117
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
118
+ {%- else %}
119
+ {{- '<|im_start|>' + message.role + '\n' + content }}
120
+ {%- endif %}
121
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
122
+ {%- for tool_call in message.tool_calls %}
123
+ {%- if tool_call.function is defined %}
124
+ {%- set tool_call = tool_call.function %}
125
+ {%- endif %}
126
+ {%- if loop.first %}
127
+ {%- if content|trim %}
128
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
129
+ {%- else %}
130
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
131
+ {%- endif %}
132
+ {%- else %}
133
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
134
+ {%- endif %}
135
+ {%- if tool_call.arguments is defined and tool_call.arguments != '' %}
136
+ {%- for args_name, args_value in tool_call.arguments|items %}
137
+ {{- '<parameter=' + args_name + '>\n' }}
138
+ {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
139
+ {{- args_value }}
140
+ {{- '\n</parameter>\n' }}
141
+ {%- endfor %}
142
+ {%- endif %}
143
+ {{- '</function>\n</tool_call>' }}
144
+ {%- endfor %}
145
+ {%- endif %}
146
+ {{- '<|im_end|>\n' }}
147
+ {%- elif message.role == "tool" %}
148
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
149
+ {{- '<|im_start|>user' }}
150
+ {%- endif %}
151
+ {{- '\n<tool_response>\n' }}
152
+ {{- content }}
153
+ {{- '\n</tool_response>' }}
154
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
155
+ {{- '<|im_end|>\n' }}
156
+ {%- elif loop.last %}
157
+ {{- '<|im_end|>\n' }}
158
+ {%- endif %}
159
+ {%- else %}
160
+ {{- raise_exception('Unexpected message role.') }}
161
+ {%- endif %}
162
+ {%- endfor %}
163
+ {%- if add_generation_prompt %}
164
+ {{- '<|im_start|>assistant\n' }}
165
+ {%- if enable_thinking is defined and enable_thinking is false %}
166
+ {{- '<think>\n\n</think>\n\n' }}
167
+ {%- else %}
168
+ {{- '<think>\n' }}
169
+ {%- endif %}
170
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3_5ForConditionalGeneration"
4
+ ],
5
+ "do_sample": true,
6
+ "eos_token_id": [
7
+ 248046,
8
+ 248044
9
+ ],
10
+ "generation_config": {
11
+ "bos_token_id": 248044,
12
+ "do_sample": true,
13
+ "eos_token_id": [
14
+ 248046,
15
+ 248044
16
+ ],
17
+ "pad_token_id": 248044,
18
+ "temperature": 1.0,
19
+ "top_k": 20,
20
+ "top_p": 0.95
21
+ },
22
+ "image_token_id": 248056,
23
+ "language_model_only": true,
24
+ "model_type": "qwen3_5",
25
+ "quantization": {
26
+ "group_size": 64,
27
+ "bits": 4,
28
+ "mode": "affine"
29
+ },
30
+ "quantization_config": {
31
+ "group_size": 64,
32
+ "bits": 4,
33
+ "mode": "affine"
34
+ },
35
+ "temperature": 1.0,
36
+ "text_config": {
37
+ "attention_bias": false,
38
+ "attention_dropout": 0.0,
39
+ "attn_output_gate": true,
40
+ "bos_token_id": 248044,
41
+ "dtype": "bfloat16",
42
+ "eos_token_id": 248044,
43
+ "full_attention_interval": 4,
44
+ "head_dim": 256,
45
+ "hidden_act": "silu",
46
+ "hidden_size": 5120,
47
+ "initializer_range": 0.02,
48
+ "intermediate_size": 17408,
49
+ "layer_types": [
50
+ "linear_attention",
51
+ "linear_attention",
52
+ "linear_attention",
53
+ "full_attention",
54
+ "linear_attention",
55
+ "linear_attention",
56
+ "linear_attention",
57
+ "full_attention",
58
+ "linear_attention",
59
+ "linear_attention",
60
+ "linear_attention",
61
+ "full_attention",
62
+ "linear_attention",
63
+ "linear_attention",
64
+ "linear_attention",
65
+ "full_attention",
66
+ "linear_attention",
67
+ "linear_attention",
68
+ "linear_attention",
69
+ "full_attention",
70
+ "linear_attention",
71
+ "linear_attention",
72
+ "linear_attention",
73
+ "full_attention",
74
+ "linear_attention",
75
+ "linear_attention",
76
+ "linear_attention",
77
+ "full_attention",
78
+ "linear_attention",
79
+ "linear_attention",
80
+ "linear_attention",
81
+ "full_attention",
82
+ "linear_attention",
83
+ "linear_attention",
84
+ "linear_attention",
85
+ "full_attention",
86
+ "linear_attention",
87
+ "linear_attention",
88
+ "linear_attention",
89
+ "full_attention",
90
+ "linear_attention",
91
+ "linear_attention",
92
+ "linear_attention",
93
+ "full_attention",
94
+ "linear_attention",
95
+ "linear_attention",
96
+ "linear_attention",
97
+ "full_attention",
98
+ "linear_attention",
99
+ "linear_attention",
100
+ "linear_attention",
101
+ "full_attention",
102
+ "linear_attention",
103
+ "linear_attention",
104
+ "linear_attention",
105
+ "full_attention"
106
+ ],
107
+ "linear_conv_kernel_dim": 4,
108
+ "linear_key_head_dim": 128,
109
+ "linear_num_key_heads": 16,
110
+ "linear_num_value_heads": 48,
111
+ "linear_value_head_dim": 128,
112
+ "mamba_ssm_dtype": "float32",
113
+ "max_position_embeddings": 262144,
114
+ "model_type": "qwen3_5_text",
115
+ "mtp_num_hidden_layers": 1,
116
+ "mtp_use_dedicated_embeddings": false,
117
+ "num_attention_heads": 24,
118
+ "num_hidden_layers": 56,
119
+ "num_key_value_heads": 4,
120
+ "output_gate_type": "swish",
121
+ "pad_token_id": null,
122
+ "partial_rotary_factor": 0.25,
123
+ "rms_norm_eps": 1e-06,
124
+ "rope_parameters": {
125
+ "mrope_interleaved": true,
126
+ "mrope_section": [
127
+ 11,
128
+ 11,
129
+ 10
130
+ ],
131
+ "partial_rotary_factor": 0.25,
132
+ "rope_theta": 10000000,
133
+ "rope_type": "default"
134
+ },
135
+ "tie_word_embeddings": false,
136
+ "use_cache": true,
137
+ "vocab_size": 248320
138
+ },
139
+ "tie_word_embeddings": false,
140
+ "top_k": 20,
141
+ "top_p": 0.95,
142
+ "transformers_version": "5.8.0.dev0",
143
+ "video_token_id": 248057,
144
+ "vision_end_token_id": 248054,
145
+ "vision_start_token_id": 248053
146
+ }
decider.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Typed, probabilistic decisions from Qwen3.8-27B in one forward pass (Apple Silicon, MLX).
2
+
3
+ You pass a STATE (any text) and a dict of QUESTIONS. Each question is one of
4
+
5
+ {"type": "choice", "options": [...], "prompt": "..."} pick one option (up to 16)
6
+ {"type": "score", "levels": [...], "prompt": "..."} ordered levels; also returns the expected level index
7
+ {"type": "noul", "statement": "..."} probability that the statement is true
8
+
9
+ and get back, per question, the chosen value, a probability for every option and a confidence.
10
+ Answers can only be one of the options you supplied: nothing is generated or parsed.
11
+
12
+ How it works
13
+ * the model is Qwen3.8-27B truncated to its first 56 layers (of 64)
14
+ * the questions go first and are prefilled once per schema, then cached; each call only
15
+ processes the state plus one short trigger per question, in a single forward pass
16
+ * a small label-free readout head (trained by self-distillation from the full 64-layer model)
17
+ maps the layer-56 hidden state at each trigger to the option probabilities
18
+ * each call is capped at token_budget tokens (default 160, which keeps a call under ~500 ms on an
19
+ M5 Pro); longer states are cut in the middle (first 40% and last 60% of their tokens are kept)
20
+ * "probs" maps option text to probability; if two options share the same text use "probs_list"
21
+
22
+ from decider import Decider
23
+ d = Decider("dowands/NeoJev-Qwen3.8-27B-L56-MLX") # or a local folder
24
+ d.ask("Customer says the refund for order 4417 never arrived and they will dispute the charge.",
25
+ {"queue": {"type": "choice", "options": ["Billing", "Technical", "Sales"],
26
+ "prompt": "Which team should handle this?"},
27
+ "urgency": {"type": "score", "levels": ["low", "medium", "high"], "prompt": "How urgent is it?"},
28
+ "churn": {"type": "noul", "statement": "The customer is likely to leave."}})
29
+ """
30
+ import json
31
+ import os
32
+
33
+ import mlx.core as mx
34
+ import mlx.nn as nn
35
+ import numpy as np
36
+ from mlx_lm import load
37
+ from mlx_lm.models.base import create_attention_mask, create_ssm_mask
38
+ from mlx_lm.models.cache import ArraysCache, KVCache
39
+
40
+ LETTERS = "ABCDEFGHIJKLMNOP"
41
+ VOCAB = list(LETTERS) + ["Yes", "No"]
42
+ SYSTEM = ("You are a decision engine. You get a list of QUESTIONS and a STATE. For each question, "
43
+ "answer with exactly one option label.")
44
+
45
+
46
+ def _block(i, name, spec):
47
+ t = spec["type"]
48
+ if t == "noul":
49
+ return f"Q{i} ({name}): Is this statement true? \"{spec['statement']}\"\nOPTIONS: Yes / No", ["Yes", "No"], ["Yes", "No"]
50
+ opts = spec["options"] if t == "choice" else spec["levels"]
51
+ if len(opts) > len(LETTERS):
52
+ raise ValueError(f"question {name!r}: at most {len(LETTERS)} options are supported")
53
+ labels = list(LETTERS[: len(opts)])
54
+ lines = "\n".join(f"{l}. {o}" for l, o in zip(labels, opts))
55
+ return f"Q{i} ({name}): {spec.get('prompt', 'Which option fits best?')}\nOPTIONS:\n{lines}", labels, opts
56
+
57
+
58
+ def _copy(cache):
59
+ out = []
60
+ for c in cache:
61
+ if isinstance(c, KVCache):
62
+ t = KVCache()
63
+ if c.keys is not None:
64
+ t.keys, t.values, t.offset = c.keys[..., : c.offset, :], c.values[..., : c.offset, :], c.offset
65
+ else:
66
+ t = ArraysCache(len(c.cache))
67
+ t.cache = list(c.cache)
68
+ out.append(t)
69
+ return out
70
+
71
+
72
+ class Decider:
73
+ def __init__(self, path="dowands/NeoJev-Qwen3.8-27B-L56-MLX", token_budget=160):
74
+ if not os.path.isdir(path): # a Hugging Face repo id: fetch weights, head and config once
75
+ from huggingface_hub import snapshot_download
76
+ path = snapshot_download(path)
77
+ self.model, self.tok = load(path)
78
+ self.lm = self.model.language_model
79
+ self.budget = token_budget
80
+ t = self.tok.apply_chat_template(
81
+ [{"role": "system", "content": SYSTEM}, {"role": "user", "content": "<<U>>"}],
82
+ tokenize=False, add_generation_prompt=True, enable_thinking=False)
83
+ self.head, self.tail = t.split("<<U>>")
84
+ z = np.load(os.path.join(path, "decider_head.npz"))
85
+ self.U, self.V, self.b, self.c = (mx.array(z[k]) for k in ("U", "V", "b", "c"))
86
+ self.T = float(z["T"])
87
+ self.n_pos = int(z["n_pos"])
88
+ ids = []
89
+ for l in VOCAB:
90
+ e = self.tok.encode(" " + l, add_special_tokens=False)
91
+ ids.append(e[0] if len(e) == 1 else self.tok.encode(l, add_special_tokens=False)[0])
92
+ head = self.lm.lm_head
93
+ ix = mx.array(ids)
94
+ if isinstance(head, nn.QuantizedLinear):
95
+ self.W = mx.dequantize(head.weight[ix], head.scales[ix], head.biases[ix], head.group_size, head.bits)
96
+ else:
97
+ self.W = head.weight[ix]
98
+ self.W = self.W.astype(mx.float32)
99
+ self.norm_w = self.lm.model.norm.weight.astype(mx.float32)
100
+ self.eps = self.lm.model.norm.eps
101
+ self._schema_cache = {}
102
+
103
+ def _enc(self, s):
104
+ return self.tok.encode(s, add_special_tokens=False)
105
+
106
+ def _run(self, ids, cache):
107
+ m = self.lm.model
108
+ h = m.embed_tokens(mx.array([ids]))
109
+ fa = create_attention_mask(h, cache[m.fa_idx])
110
+ ssm = create_ssm_mask(h, cache[m.ssm_idx])
111
+ for layer, c in zip(m.layers, cache):
112
+ h = layer(h, mask=ssm if layer.is_linear else fa, cache=c)
113
+ return h[0] # pre-norm residual stream of the last layer
114
+
115
+ def _prefix(self, key, text):
116
+ if key not in self._schema_cache:
117
+ cache = self.lm.make_cache()
118
+ self._run(self._enc(text), cache)
119
+ mx.eval([c.state for c in cache])
120
+ self._schema_cache[key] = cache
121
+ return self._schema_cache[key]
122
+
123
+ def _cap(self, state, reserved):
124
+ limit = max(32, self.budget - reserved)
125
+ ids = self._enc(state)
126
+ if len(ids) <= limit:
127
+ return state
128
+ h = int(limit * 0.4)
129
+ return self.tok.decode(ids[:h]) + " ... " + self.tok.decode(ids[-(limit - h):])
130
+
131
+ def ask(self, state, questions, cache_schema=True):
132
+ """cache_schema=True: questions first, cached across calls with the same schema (use for a fixed
133
+ set of questions asked about many states). False: state first, question after, nothing cached
134
+ (use for one-off questions whose options change every call, e.g. multiple-choice QA)."""
135
+ blocks, meta = [], []
136
+ for i, (name, spec) in enumerate(questions.items(), 1):
137
+ b, labels, opts = _block(i, name, spec)
138
+ blocks.append(b)
139
+ meta.append((i, name, spec, labels, opts))
140
+ qtext = "QUESTIONS:\n" + "\n\n".join(blocks)
141
+ trig_n = sum(len(self._enc(("" if k == 0 else "\n") + f"Q{i}:")) for k, (i, *_ ) in enumerate(meta))
142
+ reserved = len(self._enc(self.tail)) + trig_n + 4
143
+ if cache_schema:
144
+ # key keeps question order: the Q1/Q2... numbering in the cached prefix depends on it
145
+ base = self._prefix(json.dumps(list(questions.items()), sort_keys=True), self.head + qtext + "\n\nSTATE:\n")
146
+ body = self._cap(state, reserved)
147
+ else:
148
+ base = self._prefix("__head__", self.head)
149
+ reserved += len(self._enc("STATE:\n\n\n" + qtext))
150
+ body = "STATE:\n" + self._cap(state, reserved) + "\n\n" + qtext
151
+ seq = self._enc(body + self.tail)
152
+ pos = []
153
+ for k, (i, *_ ) in enumerate(meta):
154
+ seq += self._enc(("" if k == 0 else "\n") + f"Q{i}:")
155
+ pos.append(len(seq) - 1)
156
+ h = self._run(seq, _copy(base))[mx.array(pos)].astype(mx.float32)
157
+ pb = self.c[mx.array(np.minimum(np.arange(len(meta)), self.n_pos - 1))]
158
+ x = h + (h @ self.U) @ self.V + self.b + pb
159
+ x = x * mx.rsqrt(mx.mean(x * x, axis=-1, keepdims=True) + self.eps) * self.norm_w
160
+ logits = x @ self.W.T
161
+ mx.eval(logits)
162
+ res = {}
163
+ for k, (i, name, spec, labels, opts) in enumerate(meta):
164
+ z = np.array(logits[k][mx.array([VOCAB.index(l) for l in labels])]) / self.T
165
+ p = np.exp(z - np.logaddexp.reduce(z))
166
+ j = int(p.argmax())
167
+ r = {"probs": {str(o): float(v) for o, v in zip(opts, p)}, "probs_list": [float(v) for v in p],
168
+ "confidence": float(p[j])}
169
+ if spec["type"] == "noul":
170
+ r["value"] = float(p[0])
171
+ else:
172
+ r["value"] = opts[j]
173
+ if spec["type"] == "score":
174
+ r["expected_index"] = float((p * np.arange(len(p))).sum())
175
+ res[name] = r
176
+ res["_tokens"] = len(seq)
177
+ return res
178
+
179
+
180
+ if __name__ == "__main__":
181
+ import sys
182
+ import time
183
+ d = Decider(sys.argv[1] if len(sys.argv) > 1 else "dowands/NeoJev-Qwen3.8-27B-L56-MLX")
184
+ qs = {"queue": {"type": "choice", "options": ["Billing and Payments", "Technical Support", "Sales"],
185
+ "prompt": "Which team should handle this ticket?"},
186
+ "urgency": {"type": "score", "levels": ["low", "medium", "high"], "prompt": "How urgent is it?"},
187
+ "churn": {"type": "noul", "statement": "The customer is likely to leave."}}
188
+ s = "Customer emailed twice about a failed refund for order #4417 and says they will dispute the charge tomorrow."
189
+ d.ask(s, qs)
190
+ t = time.perf_counter()
191
+ out = d.ask(s, qs)
192
+ print(json.dumps(out, indent=1))
193
+ print(f"{(time.perf_counter() - t) * 1000:.0f} ms")
decider_head.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dba517b90eca8e71fc5785a0585dcbb89ca8abb0d64d1786870aa766a3bab0a7
3
+ size 42047132
generation_config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 248044,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 248046,
6
+ 248044
7
+ ],
8
+ "pad_token_id": 248044,
9
+ "temperature": 1.0,
10
+ "top_k": 20,
11
+ "top_p": 0.95
12
+ }
model-00001.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51ba1c6d7255b42f1bfc56f823027cd87a041555a057b7e3e5a3543a1bec1fe8
3
+ size 5378450721
model-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b1fcac93f901bcd5130d63bdb4fa2d6e2553e05fbd4e40d25161863707dc3c3
3
+ size 5368925771
model-00003.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bf2ac898721ee1f537d1ba9ca9d9db5adc69f19ee4a26dffeac4279d091f56b2
3
+ size 2672828549
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
requirements-mlx.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # NeoJev MLX backend (tested 2026-09-24 on Apple M5 Pro, macOS)
2
+ mlx==0.32.2
3
+ mlx-lm==0.31.3
4
+ numpy
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06b9509352d2af50381ab2247e083b80d32d5c0aba91c272ca9ff729b6a0e523
3
+ size 19989325
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "audio_bos_token": "<|audio_start|>",
4
+ "audio_eos_token": "<|audio_end|>",
5
+ "audio_token": "<|audio_pad|>",
6
+ "backend": "tokenizers",
7
+ "bos_token": null,
8
+ "clean_up_tokenization_spaces": false,
9
+ "eos_token": "<|im_end|>",
10
+ "errors": "replace",
11
+ "image_token": "<|image_pad|>",
12
+ "is_local": true,
13
+ "local_files_only": false,
14
+ "model_max_length": 262144,
15
+ "model_specific_special_tokens": {
16
+ "audio_bos_token": "<|audio_start|>",
17
+ "audio_eos_token": "<|audio_end|>",
18
+ "audio_token": "<|audio_pad|>",
19
+ "image_token": "<|image_pad|>",
20
+ "video_token": "<|video_pad|>",
21
+ "vision_bos_token": "<|vision_start|>",
22
+ "vision_eos_token": "<|vision_end|>"
23
+ },
24
+ "pad_token": "<|endoftext|>",
25
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
26
+ "processor_class": "Qwen3VLProcessor",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null,
30
+ "video_token": "<|video_pad|>",
31
+ "vision_bos_token": "<|vision_start|>",
32
+ "vision_eos_token": "<|vision_end|>"
33
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff