lex4 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lex4-0.4.4/LICENSE +165 -0
- lex4-0.4.4/NOTICE +31 -0
- lex4-0.4.4/PKG-INFO +273 -0
- lex4-0.4.4/README.md +240 -0
- lex4-0.4.4/lex4/__init__.py +5 -0
- lex4-0.4.4/lex4/adapt_gear.py +302 -0
- lex4-0.4.4/lex4/cli.py +880 -0
- lex4-0.4.4/lex4/engine/__init__.py +10 -0
- lex4-0.4.4/lex4/engine/_env.py +26 -0
- lex4-0.4.4/lex4/engine/blackwell_mma.py +2985 -0
- lex4-0.4.4/lex4/engine/codebooks.py +1086 -0
- lex4-0.4.4/lex4/engine/encoder.py +1112 -0
- lex4-0.4.4/lex4/engine/format.py +396 -0
- lex4-0.4.4/lex4/engine/kernels.py +1343 -0
- lex4-0.4.4/lex4/engine/pager.py +1875 -0
- lex4-0.4.4/lex4/engine/runtime.py +1064 -0
- lex4-0.4.4/lex4/engine/think_ctrl.py +549 -0
- lex4-0.4.4/lex4/engine/vllm_plugin.py +900 -0
- lex4-0.4.4/lex4/presets.py +165 -0
- lex4-0.4.4/lex4/proxy.py +1141 -0
- lex4-0.4.4/lex4.egg-info/PKG-INFO +273 -0
- lex4-0.4.4/lex4.egg-info/SOURCES.txt +32 -0
- lex4-0.4.4/lex4.egg-info/dependency_links.txt +1 -0
- lex4-0.4.4/lex4.egg-info/entry_points.txt +6 -0
- lex4-0.4.4/lex4.egg-info/requires.txt +11 -0
- lex4-0.4.4/lex4.egg-info/top_level.txt +1 -0
- lex4-0.4.4/pyproject.toml +64 -0
- lex4-0.4.4/setup.cfg +4 -0
- lex4-0.4.4/tests/test_adapt_gear.py +117 -0
- lex4-0.4.4/tests/test_format.py +256 -0
- lex4-0.4.4/tests/test_pager.py +528 -0
- lex4-0.4.4/tests/test_presets.py +80 -0
- lex4-0.4.4/tests/test_proxy.py +95 -0
- lex4-0.4.4/tests/test_runtime_gpu.py +265 -0
lex4-0.4.4/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to the Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this License, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright notices, patent notices,
|
|
102
|
+
trademark notices, and attribution notices from the Source
|
|
103
|
+
form of the Work, excluding those notices that do not
|
|
104
|
+
pertain to any part of the Work; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Work, in at least one of the
|
|
111
|
+
following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, or, within a display generated by the
|
|
114
|
+
Derivative Works, if and wherever such third-party notices
|
|
115
|
+
are normally distributed. The contents of the NOTICE file
|
|
116
|
+
are for informational purposes only and do not modify the
|
|
117
|
+
License. You may add Your own copyright notice within
|
|
118
|
+
Your Derivative Works and may provide additional or different
|
|
119
|
+
license terms and conditions for use, separate from the
|
|
120
|
+
License.
|
|
121
|
+
|
|
122
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
123
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
124
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
125
|
+
this License, without any additional terms or conditions.
|
|
126
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
127
|
+
the terms of any separate third-party license agreement you may have
|
|
128
|
+
executed with Licensor regarding such Contributions.
|
|
129
|
+
|
|
130
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
131
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
132
|
+
except as required for reasonable and customary use in describing the
|
|
133
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
134
|
+
|
|
135
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
136
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
137
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
138
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
139
|
+
implied, including, without limitation, any warranties or conditions
|
|
140
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
141
|
+
PARTICULAR PURPOSE. You are solely responsible for your own
|
|
142
|
+
consideration of the appropriateness of using or redistributing the
|
|
143
|
+
Work and assume any risks associated with Your exercise of permissions
|
|
144
|
+
under this License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Warranty. In no event and under no legal theory,
|
|
147
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
148
|
+
unless required by applicable law (such as deliberate and gross
|
|
149
|
+
negligence) or agreed to in writing, shall any Contributor be
|
|
150
|
+
liable to You for any damages, including any direct, indirect,
|
|
151
|
+
special, incidental, or consequential damages of any character arising
|
|
152
|
+
as a result of this License or out of the use or refusal to use the
|
|
153
|
+
Work and such Derivative Works.
|
|
154
|
+
|
|
155
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
156
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
157
|
+
and charge a fee for, acceptance of support, warranty, or indemnity
|
|
158
|
+
terms or other liability obligations and/or rights consistent with
|
|
159
|
+
this License. However, in accepting such obligations, You may act
|
|
160
|
+
only on Your own behalf and on Your sole responsibility, and not
|
|
161
|
+
on behalf of any other Contributor, and only if You agree to indemnify,
|
|
162
|
+
defend, and hold each Contributor harmless for any liability
|
|
163
|
+
associated with, or claims arising from, such acceptance.
|
|
164
|
+
|
|
165
|
+
END OF TERMS AND CONDITIONS
|
lex4-0.4.4/NOTICE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Lex4
|
|
2
|
+
Copyright 2026 Lex4 Contributors (https://lex4.dev)
|
|
3
|
+
|
|
4
|
+
This product includes software licensed under the Apache License, Version 2.0.
|
|
5
|
+
|
|
6
|
+
Third-Party Models & Optional Components (Not Bundled in This Repository)
|
|
7
|
+
-------------------------------------------------------------------------
|
|
8
|
+
Lex4 is an inference engine, binary format (.lex4), and quantization toolkit.
|
|
9
|
+
Model weights and optional speculative drafters are downloaded separately from
|
|
10
|
+
Hugging Face and remain subject to their respective upstream licenses:
|
|
11
|
+
|
|
12
|
+
1. GLM-5.3-Flash-LEX4-3.5bpw (Lex4-dev/GLM-5.3-Flash-LEX4-3.5bpw)
|
|
13
|
+
- Quantized derivative of NVIDIA GLM-5.3-Flash-FP4-Local
|
|
14
|
+
(based on zai-org/GLM-5.3-Flash, MIT License).
|
|
15
|
+
- Governed by the NVIDIA Open Model Agreement
|
|
16
|
+
(https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-agreement/),
|
|
17
|
+
which permits commercial and non-commercial use.
|
|
18
|
+
|
|
19
|
+
2. Optional DFlash2 Speculative Drafter (incoai/GLM-5.3-Flash-DFlash2)
|
|
20
|
+
- Published by Inco AI / Z-Lab under CC-BY-NC-ND-4.0 (Non-Commercial, No-Derivatives).
|
|
21
|
+
- Lex4 does NOT redistribute or modify DFlash2 weights; `lex4 pull` / `lex4 up`
|
|
22
|
+
fetches them directly from Hugging Face only when enabled for personal /
|
|
23
|
+
research use.
|
|
24
|
+
- For commercial deployments, pass `--no-drafter` to run a 100%
|
|
25
|
+
commercial-clean stack (Apache-2.0 engine + NVIDIA Open Model weights).
|
|
26
|
+
|
|
27
|
+
3. Container Runtime & Optional UI
|
|
28
|
+
- The DGX Spark Docker image builds on vLLM (Apache-2.0) and the community
|
|
29
|
+
`eugr/spark-vllm-b12x` container stack.
|
|
30
|
+
- Passing `--with-webui` pulls and runs Open WebUI directly from upstream
|
|
31
|
+
`ghcr.io/open-webui/open-webui:main`.
|
lex4-0.4.4/PKG-INFO
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lex4
|
|
3
|
+
Version: 0.4.4
|
|
4
|
+
Summary: The sub-4-bit inference engine & .lex4 format for desktop frontier AI (Blackwell SM121a + NVMe O_DIRECT paging).
|
|
5
|
+
Author: Lex4 Contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://lex4.dev
|
|
8
|
+
Project-URL: Repository, https://github.com/lex4-dev/lex4
|
|
9
|
+
Project-URL: Issues, https://github.com/lex4-dev/lex4/issues
|
|
10
|
+
Project-URL: Models, https://huggingface.co/Lex4-dev
|
|
11
|
+
Keywords: llm,moe,quantization,blackwell,dgx-spark,vllm,trellis,nvme,inference
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Provides-Extra: hf
|
|
25
|
+
Requires-Dist: huggingface_hub>=0.25.0; extra == "hf"
|
|
26
|
+
Provides-Extra: engine
|
|
27
|
+
Requires-Dist: torch>=2.5.0; extra == "engine"
|
|
28
|
+
Requires-Dist: numpy>=1.26.0; extra == "engine"
|
|
29
|
+
Requires-Dist: safetensors>=0.4.5; extra == "engine"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/lex4-dev/lex4/main/assets/lex4-banner.jpg" alt="Lex4 — The Sub-4-Bit Engine & .lex4 Format for Desktop Frontier AI" width="100%" />
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
<h1 align="center">Lex4</h1>
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<strong>The sub-4-bit inference engine & <code>.lex4</code> format for desktop frontier AI.</strong><br />
|
|
42
|
+
Run a 320B-parameter frontier MoE (<code>GLM-5.3-Flash</code>) on a <strong>single 128 GB NVIDIA DGX Spark</strong> at <strong>20–45 tok/s</strong> with <strong>262K context</strong>, <strong>zero swap</strong>, and a live per-request <code>fast / balanced / exact</code> NVMe dial.
|
|
43
|
+
</p>
|
|
44
|
+
|
|
45
|
+
<p align="center">
|
|
46
|
+
<a href="https://github.com/lex4-dev/lex4/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-76B900.svg" alt="Apache-2.0 License" /></a>
|
|
47
|
+
<img src="https://img.shields.io/badge/Hardware-NVIDIA%20Blackwell%20SM121a-76B900.svg" alt="Blackwell SM121a" />
|
|
48
|
+
<img src="https://img.shields.io/badge/Format-.lex4%20(3.50%20bpw%20Trellis--L14)-0071E3.svg" alt=".lex4 Format" />
|
|
49
|
+
<a href="https://huggingface.co/Lex4-dev/GLM-5.3-Flash-LEX4-3.5bpw"><img src="https://img.shields.io/badge/HuggingFace-Lex4--dev-FFD21E.svg" alt="Hugging Face" /></a>
|
|
50
|
+
<a href="https://lex4.dev"><img src="https://img.shields.io/badge/Web-lex4.dev-0A1328.svg" alt="lex4.dev" /></a>
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Why Lex4?
|
|
56
|
+
|
|
57
|
+
Until now, running a 320B Mixture-of-Experts model locally forced an ugly compromise:
|
|
58
|
+
|
|
59
|
+
| Approach (`GLM-5.3-Flash`, 320B MoE) | Hardware Required | Speed (Decode) | Code Quality vs. NVFP4 | Prose Quality vs. NVFP4 | Context / Stability |
|
|
60
|
+
|---|---:|---:|---:|---:|---|
|
|
61
|
+
| **NVIDIA Official NVFP4** (`4.27 bpw`, ~172 GB) | **2× DGX Spark** (~\$9.4K–\$12K+) | ~15–26 tok/s | Baseline (`0%`) | Baseline (`0%`) | 2 boxes + 200GbE link |
|
|
62
|
+
| **1-Spark Ultra-Low-Bit** (`2.01 bpw` all-in-RAM) | 1× DGX Spark | Fast | **+26.6% worse** | **+142.3% worse** | Severe prose/reasoning loss |
|
|
63
|
+
| **Naive CPU / SSD Offloading** | 1× DGX Spark | ~1–4 tok/s | Near-baseline | Near-baseline | Breaks CUDA graphs, stalls |
|
|
64
|
+
| **Lex4 (`3.50 bpw` `.lex4` + `O_DIRECT` Pager + SM121a)** | **1× DGX Spark** (~\$4.7K–\$6K) | **21–45 tok/s** | **`+0.17%`–`+1.00%`** *(matches 2-Spark)* | **`+2.91%`** *(Les Mis)* | **262K ctx, ~10 GiB free RAM, 0 swap** |
|
|
65
|
+
|
|
66
|
+
Lex4 hits **98.0%–99.4% of GB10's measured 234.1 GB/s physical DRAM bandwidth ceiling**, boots **83.5 GB** of experts in **20.1 seconds** via double-buffered `O_DIRECT` `QD=4` NVMe streaming (`4.16 GB/s`), and keeps full Blackwell CUDA graphs intact while paging cold experts asynchronously in the background.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quick Start (DGX Spark — 2 Commands)
|
|
71
|
+
|
|
72
|
+
Requires an **NVIDIA DGX Spark (128 GB, Blackwell GB10 / SM121a)** with Docker + NVIDIA Container Toolkit and **150 GB+ free NVMe space**.
|
|
73
|
+
|
|
74
|
+
### 1. Install the zero-dependency `lex4` CLI
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
curl -fsSL https://raw.githubusercontent.com/lex4-dev/lex4/main/install.sh | bash
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
*(Or via PyPI: `pipx install lex4` / `pip install lex4`. The host CLI uses Python stdlib only — zero host PyTorch/CUDA packages needed.)*
|
|
81
|
+
|
|
82
|
+
### 2. Verify your Spark and launch
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
lex4 doctor
|
|
86
|
+
lex4 up --preset balanced
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Want a ChatGPT-like browser UI automatically wired on `http://localhost:3000`?
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
lex4 up --preset balanced --with-webui
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Want to chat right in your terminal?
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
lex4 chat
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> **What happens on `lex4 up`:**
|
|
102
|
+
> 1. Pulls the pre-compiled **`ghcr.io/lex4-dev/lex4:spark`** image (SM121a CUDA/PTX kernels already compiled — zero compile wait).
|
|
103
|
+
> 2. Downloads [`Lex4-dev/GLM-5.3-Flash-LEX4-3.5bpw`](https://huggingface.co/Lex4-dev/GLM-5.3-Flash-LEX4-3.5bpw) (`~134 GB`) and the optional DFlash2 drafter (`incoai/GLM-5.3-Flash-DFlash2`) on first run.
|
|
104
|
+
> 3. Starts a single auto-restarting (`unless-stopped`) container running vLLM (`:8000` internal) + the **Lex4 Smart Proxy** (`:8888` OpenAI-compatible API).
|
|
105
|
+
|
|
106
|
+
For a **100% commercial-clean stack** (Apache-2.0 engine + NVIDIA Open Model Agreement weights, skipping the `CC-BY-NC-ND-4.0` DFlash2 drafter):
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
lex4 up --preset balanced --no-drafter
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Built-In RAM & Context Presets
|
|
115
|
+
|
|
116
|
+
Pick the footprint that fits how you use your Spark — or pass `--ram-gb` and `--context` for any custom split:
|
|
117
|
+
|
|
118
|
+
| Preset | Resident Experts | Context Window | FP8 KV Cache | Free OS RAM | Best For |
|
|
119
|
+
|---|---:|---:|---:|---:|---|
|
|
120
|
+
| **`balanced`** *(default)* | **83 GB** (`62.7%`) | **262,144** (`262K`) | `8.0 GiB` (~347K tok) | **~9.8 GiB** | **Flagship daily driver** — long-context agents, coding, chat |
|
|
121
|
+
| **`low-ram`** | **64 GB** (`48.0%`) | **262,144** (`262K`) | `8.0 GiB` (~347K tok) | **~29–31 GiB** | Heavy multitasking, IDEs, browsers, extra Docker containers |
|
|
122
|
+
| **`max-quality`** | **86 GB** (`64.9%`) | **102,400** (`102K`) | `4.0 GiB` (~171K tok) | **~11.4 GiB** | Peak warm-cache hit rate when ≤102K context is plenty |
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
lex4 up --preset balanced # 83 GB experts, 262K context (default)
|
|
126
|
+
lex4 up --preset low-ram # 64 GB experts, 262K context (~30 GiB free RAM)
|
|
127
|
+
lex4 up --preset max-quality # 86 GB experts, 102K context (highest cache hit rate)
|
|
128
|
+
lex4 up --ram-gb 76 --context 262144 # Custom RAM/context with automatic KV math
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Live Per-Request Mode Dial (Zero Restarts)
|
|
134
|
+
|
|
135
|
+
Every request can choose its own spot on the **Quality ↔ Speed ↔ NVMe** curve on the fly — without reloading weights or restarting the server:
|
|
136
|
+
|
|
137
|
+
| Mode | Behavior | NVMe Traffic | Typical Speed (DGX Spark) | When to Use |
|
|
138
|
+
|---|---|---:|---:|---|
|
|
139
|
+
| **`auto`** *(proxy default)* | Routes quick logs, greetings, short Q&A & context compressions to `fast`; routes coding, math, tools & long prompts to `balanced` | Low | `0.36–0.65s` TTFT / `30–39 tok/s` | Everyday agents, Open WebUI, Hermes, Cursor |
|
|
140
|
+
| **`fast`** (`/fast <msg>`) | Resident-only rerouting, full CUDA graphs, **zero SSD reads** | **0.0 GB** | `0.36–0.57s` TTFT, `25–35 tok/s` | Instant replies, diary logs, background compressions |
|
|
141
|
+
| **`balanced`** (`/balanced <msg>`) | Warm adaptive background NVMe paging + full CUDA graphs | Light | `0.60–0.80s` TTFT, `28–39 tok/s` | Daily coding, reasoning, multi-turn tool use |
|
|
142
|
+
| **`exact`** (`/exact` or `/ultra`) | Synchronous 12-slot `O_DIRECT` `QD=4` exact miss-fetch waves (`100%` full-checkpoint parity, target-only eager bypass) | Heavy | `5.2–9.8 tok/s` | Competition math, hard debugging, verification |
|
|
143
|
+
|
|
144
|
+
### Using the Mode Dial
|
|
145
|
+
|
|
146
|
+
**1. In any chat UI (Open WebUI, Hermes, Telegram, `lex4 chat`) — prefix your message:**
|
|
147
|
+
```text
|
|
148
|
+
/fast log my weight 185.2 lbs
|
|
149
|
+
/balanced write a thread-safe LRU cache in Python
|
|
150
|
+
/exact prove that there are infinitely many primes congruent to 3 mod 4
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**2. Via OpenAI API (`http://127.0.0.1:8888/v1/chat/completions`):**
|
|
154
|
+
```python
|
|
155
|
+
from openai import OpenAI
|
|
156
|
+
|
|
157
|
+
client = OpenAI(base_url="http://127.0.0.1:8888/v1", api_key="lex4-local")
|
|
158
|
+
resp = client.chat.completions.create(
|
|
159
|
+
model="GLM-5.3-Flash",
|
|
160
|
+
messages=[{"role": "user", "content": "Solve x^3 - 6x^2 + 11x - 6 = 0"}],
|
|
161
|
+
extra_body={"lex4_mode": "exact"}, # "fast" | "balanced" | "exact"
|
|
162
|
+
)
|
|
163
|
+
print(resp.choices[0].message.content)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Every response includes `X-Lex4-Mode` and `X-Lex4-Mode-Source` headers, and live routing telemetry is served at `GET http://127.0.0.1:8888/lex4/stats`.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Verified Benchmarks (1× NVIDIA DGX Spark, 128 GB)
|
|
171
|
+
|
|
172
|
+
All numbers below are direct measured runs on a single 128 GB DGX Spark (`GLM-5.3-Flash-LEX4-3.5bpw`, `133.2 GB` MoE on disk, 40-task cold held-out suite across `chat`, `tools`, `coding`, and `hard_math` with zero prefix cache reuse between modes). Raw JSON artifacts live in [`benchmarks/results/`](https://github.com/lex4-dev/lex4/tree/main/benchmarks/results).
|
|
173
|
+
|
|
174
|
+
<!-- BENCH_TABLE_START -->
|
|
175
|
+
| Preset (Resident RAM / Context) | Mode (Effort) | Chat | Tools | Coding | Cold Hard Math | Overall | Decode Speed | Avg TTFT | NVMe Read | Free RAM |
|
|
176
|
+
|---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
|
|
177
|
+
| **`balanced` (83 GB / 262K)** | `fast` (low) | `8/8` (`100%`) | `8/8` (`100%`) | `6/10` (`60%`) | `4/14` (`28.6%`) | `26/40` (`65.0%`) | `25.6 tok/s` | `0.54 s` | `0.0 GB` | `9.9 GiB` |
|
|
178
|
+
| **`balanced` (83 GB / 262K)** | `balanced` (high) | `8/8` (`100%`) | `8/8` (`100%`) | **`9/10` (`90%`)** | `7/14` (`50.0%`) | **`32/40` (`80.0%`)** | **`28.3 tok/s`** | **`0.76 s`** | `438 GB` | `9.9 GiB` |
|
|
179
|
+
| **`balanced` (83 GB / 262K)** | `exact` (high) | — | — | — | **`12/14` (`85.7%`)** | — | **`8.6 tok/s`** | **`3.47 s`** | `5.2 TB` | `9.9 GiB` |
|
|
180
|
+
| **`low-ram` (64 GB / 262K)** | `fast` (low) | `8/8` (`100%`) | `8/8` (`100%`) | `3/10` (`30%`) | `5/14` (`35.7%`) | `24/40` (`60.0%`) | `29.6 tok/s` | `0.50 s` | `0.0 GB` | `31.5 GiB` |
|
|
181
|
+
| **`low-ram` (64 GB / 262K)** | `balanced` (high) | `8/8` (`100%`) | `8/8` (`100%`) | `7/10` (`70%`) | `5/14` (`35.7%`) | `28/40` (`70.0%`) | `28.7 tok/s` | `0.75 s` | `658 GB` | `31.5 GiB` |
|
|
182
|
+
| **`low-ram` (64 GB / 262K)** | `exact` (high) | — | — | — | **`11/14` (`78.6%`)** | — | `5.2 tok/s` | `6.11 s` | `8.6 TB` | `31.5 GiB` |
|
|
183
|
+
| **`max-quality` (86 GB / 102K)** | `fast` (low) | `8/8` (`100%`) | `8/8` (`100%`) | `6/10` (`60%`) | `5/14` (`35.7%`) | `27/40` (`67.5%`) | `26.2 tok/s` | `0.57 s` | `0.0 GB` | `11.3 GiB` |
|
|
184
|
+
| **`max-quality` (86 GB / 102K)** | `balanced` (high) | `8/8` (`100%`) | `8/8` (`100%`) | `8/10` (`80%`) | `9/14` (`64.3%`) | `33/40` (`82.5%`) | `30.0 tok/s` | `0.80 s` | `559 GB` | `11.4 GiB` |
|
|
185
|
+
| **`max-quality` (86 GB / 102K)** | `exact` (high) | — | — | — | **`12/14` (`85.7%`)** | — | `8.6 tok/s` | `3.92 s` | `5.9 TB` | `11.4 GiB` |
|
|
186
|
+
<!-- BENCH_TABLE_END -->
|
|
187
|
+
|
|
188
|
+
*Key takeaway: even at **`64 GB` (`low-ram`)** with `31.5 GiB` free OS RAM, flipping a single hard math prompt to `/exact` recovers **`11/14` (`78.6%`, `0` truncations)** on demand — a `+42.9%` jump over `balanced` on cold prompts!*
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## How Lex4 Works Under the Hood
|
|
193
|
+
|
|
194
|
+
1. **`.lex4` Sub-4-Bit Trellis-L14 Format (`lex4/engine/format.py`, `codebooks.py`):**
|
|
195
|
+
- Compresses `GLM-5.3-Flash`'s 328 GB of MoE experts to **133.2 GB** (`3.50 bpw` average across 5 Hessian-allocated tiers) with `< 1%` perplexity delta at full residency (`+0.27%` code, `+0.91%` literary prose vs. NVFP4 reference).
|
|
196
|
+
- Every expert payload is **4096-byte aligned** on disk for zero-copy `O_DIRECT` NVMe DMA.
|
|
197
|
+
2. **Hand-Tuned Blackwell SM121a Kernels (`lex4/engine/blackwell_mma.py`):**
|
|
198
|
+
- Direct PTX `mma.m16n8k32` + zero-spill unified decode GEMV hitting **229–232.6 GB/s** out of GB10's **234.1 GB/s** physical DRAM ceiling (**98.0%–99.4% speed of light**), plus a zero-spill cooperative BF16 GEMV kernel for unquantized dense/drafter layers.
|
|
199
|
+
3. **Zero-Doorbell `O_DIRECT` NVMe Pager (`lex4/engine/pager.py`, `runtime.py`):**
|
|
200
|
+
- Allocates RAM per layer via **Shannon entropy water-filling** (100% resident in unpredictable early layers, dynamically paged in spikier deep layers) and pins the **246 RTAQ termination experts** that govern clean `</think>` closure at `0.00 GB` extra RAM.
|
|
201
|
+
- Uses `O_DIRECT` `libc.pread` with **QD=4 parallel staging + 12 rolling wave slots** (`13.12 GB/s` cold multi-file read — **10.5× faster** than buffered I/O, **+0 MiB** OS swap, and **20.1 s** total MoE boot load).
|
|
202
|
+
4. **2-Gear Adaptive Speculation (`lex4/adapt_gear.py`):**
|
|
203
|
+
- Automatically shifts DFlash2 lookahead depth between `d=2` (creative chat) and `d=7` (code, math, tools) with hysteresis, while keeping CUDA graphs intact.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## CLI Reference
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
lex4 presets # Compare balanced (83GB), low-ram (64GB), max-quality (86GB)
|
|
211
|
+
lex4 doctor # Verify GPU, RAM, NVMe free space, Docker, and model cache
|
|
212
|
+
lex4 pull # Download .lex4 model weights (pass --no-drafter for commercial-clean)
|
|
213
|
+
lex4 up [OPTIONS] # Start single-container server (:8888 API, optional --with-webui :3000)
|
|
214
|
+
lex4 status # Show container health, live /lex4/stats routing counts, host RAM/swap
|
|
215
|
+
lex4 logs -f # Tail server logs
|
|
216
|
+
lex4 chat # Interactive streaming terminal chat with live tok/s & mode badge
|
|
217
|
+
lex4 bench # Run a 4-prompt live fast/balanced/exact smoke & speed check
|
|
218
|
+
lex4 down # Stop Lex4 server (and Open WebUI if started)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Quantizing Your Own MoE Model (Apache-2.0 Open Core)
|
|
224
|
+
|
|
225
|
+
Lex4's universal 2-stage cross-layer convex RD encoder (`lex4/engine/encoder.py`) is fully open-source under **Apache-2.0** and auto-parses Hugging Face `config.json` across GLM, DeepSeek-V3/R1, Qwen3-MoE, Llama-4, Mixtral, and OLMoE:
|
|
226
|
+
|
|
227
|
+
1. **Stage 1 (`run_stage1_sensitivity`):** Single-probe empirical-Bayes Hessian sensitivity pass across all MoE layers.
|
|
228
|
+
2. **Global Convex RD (`allocate_global_rd`):** Exact `O(N log N)` Pareto bit allocation across all `layers × experts × {gate_up, down}` for any target bpw (`2.5–3.8 bpw`).
|
|
229
|
+
3. **Stage 2 (`run_stage2_encode`):** Trellis-L14 Viterbi + block-LDL quantization with per-row FP16 scale refit and automatic GPU runtime self-verification.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Licensing & Commercial Use
|
|
234
|
+
|
|
235
|
+
Lex4 is designed to be crystal-clear for both **individual builders / researchers** and **commercial teams**:
|
|
236
|
+
|
|
237
|
+
| Component | License | Commercial Use |
|
|
238
|
+
|---|---|---|
|
|
239
|
+
| **Lex4 Engine, Kernels, `.lex4` Format, Encoder, CLI & Proxy** (this repo) | **Apache-2.0** | Yes |
|
|
240
|
+
| **`Lex4-dev/GLM-5.3-Flash-LEX4-3.5bpw`** (derivative of NVIDIA `GLM-5.3-Flash-FP4-Local` / `zai-org/GLM-5.3-Flash`) | **NVIDIA Open Model Agreement** | Yes |
|
|
241
|
+
| **Optional `incoai/GLM-5.3-Flash-DFlash2` drafter** *(not redistributed by Lex4; fetched directly from HF)* | **CC-BY-NC-ND-4.0** | **No** (personal / research only — pass `--no-drafter` for commercial deployments) |
|
|
242
|
+
|
|
243
|
+
See [LICENSE](https://github.com/lex4-dev/lex4/blob/main/LICENSE) and [NOTICE](https://github.com/lex4-dev/lex4/blob/main/NOTICE) for full details.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Roadmap
|
|
248
|
+
|
|
249
|
+
- [x] **Blackwell SM121a (`DGX Spark`)** — 98–99.4% DRAM roofline, `O_DIRECT` `QD=4` pager, live `fast / balanced / exact` mode dial, smart auto-routing proxy, `lex4` CLI & Docker stack
|
|
250
|
+
- [ ] **More `.lex4` Frontier MoE Checkpoints** — DeepSeek, Qwen-MoE, Kimi, Llama-4
|
|
251
|
+
- [ ] **Commercial-Clean Speculative Decoding** — native MTP / Apache-2.0 drafter support
|
|
252
|
+
- [ ] **Apple Silicon (Metal / MLX) Backend** — bringing `.lex4` sub-4-bit MoE + NVMe paging to unified-memory Mac Studio / MacBook Pro
|
|
253
|
+
- [ ] **Multi-Spark Tensor & Pipeline Scaling** — 600B–1T+ models across 2–4 Sparks
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Acknowledgments
|
|
258
|
+
|
|
259
|
+
Lex4 builds on the work of an extraordinary open-source and research community:
|
|
260
|
+
|
|
261
|
+
- **[vLLM](https://github.com/vllm-project/vllm)** *(Apache-2.0)* — Host serving engine, V1 `GPUModelRunner`, modular `FusedMoE` interface, and `vllm.general_plugins` extension system.
|
|
262
|
+
- **[eugr (`spark-vllm-b12x`)](https://hub.docker.com/r/eugr/spark-vllm-b12x)** — Community DGX Spark Blackwell container stack and `b12x` SM121a non-MoE kernels powering our Docker base image.
|
|
263
|
+
- **[Z.ai / Zhipu AI (`GLM-5.3-Flash`)](https://huggingface.co/zai-org/GLM-5.3-Flash)** *(MIT License)* — Original 320B MoE base model, tokenizer, and chat template.
|
|
264
|
+
- **[NVIDIA (`GLM-5.3-Flash-FP4-Local` & Model Optimizer)](https://huggingface.co/nvidia/GLM-5.3-Flash-FP4-Local)** *([NVIDIA Open Model Agreement](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-agreement/))* — Quantization-aware distilled checkpoint and non-MoE FP4 weights.
|
|
265
|
+
- **[Inco AI & Z-Lab (`GLM-5.3-Flash-DFlash2`)](https://huggingface.co/incoai/GLM-5.3-Flash-DFlash2)** *([GitHub](https://github.com/z-lab/dflash), `CC-BY-NC-ND-4.0`)* — Block-diffusion speculative drafter optionally pulled directly from Hugging Face for personal/research acceleration.
|
|
266
|
+
- **[Open WebUI](https://github.com/open-webui/open-webui)** — Optional browser chat interface wired via `--with-webui`.
|
|
267
|
+
- **Quantization & Systems Research:**
|
|
268
|
+
- **QuIP# & QTIP** *(Tseng et al., Cornell RelaxML)* — Foundational Randomized Hadamard Transform (RHT), LDLQ, E8 lattice, and Trellis-Coded Quantization theory.
|
|
269
|
+
- **[ExLlamaV3](https://github.com/turboderp-org/exllamav3)** — Pioneered practical GPU trellis quantization (EXL3) for local LLMs.
|
|
270
|
+
- **RTAQ** *(`arXiv:2611.37751`)* — Reasoning-Termination-Aware Quantization, inspiring our 246-expert termination pinning (`rtaq_pin_experts.json`).
|
|
271
|
+
- **Routes of Reasoning** *(`arXiv:2611.05919`)* — Inspiring our opt-in router steering hooks (`lex4/engine/think_ctrl.py`).
|
|
272
|
+
- **PyTorch, `safetensors`, and Hugging Face** — Core runtime, serialization, and model distribution ecosystem.
|
|
273
|
+
|