Skip to main content Switch to mobile version lex4 0.4.4 The sub-4-bit inference engine & .lex4 format for desktop frontier AI (Blackwell SM121a + NVMe O_DIRECT paging).
pip install lex4 Copy PIP instructions
The sub-4-bit inference engine & .lex4 format for desktop frontier AI. Run a 320B-parameter frontier MoE (GLM-5.3-Flash) on a single 128 GB NVIDIA DGX Spark at 20–45 tok/s with 262K context, zero swap, and a live per-request fast / balanced / exact NVMe dial.
Until now, running a 320B Mixture-of-Experts model locally forced an ugly compromise:
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.
Quick Start (DGX Spark — 2 Commands)
Requires an NVIDIA DGX Spark (128 GB, Blackwell GB10 / SM121a) with Docker + NVIDIA Container Toolkit and 150 GB+ free NVMe space.
1. Install the zero-dependency lex4 CLI
curl -fsSL https://raw.githubusercontent.com/lex4-dev/lex4/main/install.sh | bash (Or via PyPI: pipx install lex4 / pip install lex4. The host CLI uses Python stdlib only — zero host PyTorch/CUDA packages needed.)
2. Verify your Spark and launch
lex4 doctor lex4 up --preset balanced Want a ChatGPT-like browser UI automatically wired on http://localhost:3000?
lex4 up --preset balanced --with-webui Want to chat right in your terminal?
lex4 chat What happens on lex4 up:
Pulls the pre-compiled ghcr.io/lex4-dev/lex4:spark image (SM121a CUDA/PTX kernels already compiled — zero compile wait).
Downloads 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.
Starts a single auto-restarting (unless-stopped) container running vLLM (:8000 internal) + the Lex4 Smart Proxy (:8888 OpenAI-compatible API).
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):
lex4 up --preset balanced --no-drafter Built-In RAM & Context Presets
Pick the footprint that fits how you use your Spark — or pass --ram-gb and --context for any custom split:
lex4 up --preset balanced # 83 GB experts, 262K context (default) lex4 up --preset low-ram # 64 GB experts, 262K context (~30 GiB free RAM) lex4 up --preset max-quality # 86 GB experts, 102K context (highest cache hit rate) lex4 up --ram-gb 76 --context 262144 # Custom RAM/context with automatic KV math Live Per-Request Mode Dial (Zero Restarts)
Every request can choose its own spot on the Quality ↔ Speed ↔ NVMe curve on the fly — without reloading weights or restarting the server:
1. In any chat UI (Open WebUI, Hermes, Telegram, lex4 chat) — prefix your message:
/fast log my weight 185.2 lbs /balanced write a thread-safe LRU cache in Python /exact prove that there are infinitely many primes congruent to 3 mod 4 2. Via OpenAI API (http://127.0.0.1:8888/v1/chat/completions):
from openai import OpenAI client = OpenAI(base_url="http://127.0.0.1:8888/v1", api_key="lex4-local") resp = client.chat.completions.create( model="GLM-5.3-Flash", messages=[{"role": "user", "content": "Solve x^3 - 6x^2 + 11x - 6 = 0"}], extra_body={"lex4_mode": "exact"}, # "fast" | "balanced" | "exact" ) print(resp.choices[0].message.content) 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.
Verified Benchmarks (1× NVIDIA DGX Spark, 128 GB)
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/.
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!
How Lex4 Works Under the Hood
.lex4 Sub-4-Bit Trellis-L14 Format (lex4/engine/format.py, codebooks.py): 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).
Every expert payload is 4096-byte aligned on disk for zero-copy O_DIRECT NVMe DMA.
Hand-Tuned Blackwell SM121a Kernels (lex4/engine/blackwell_mma.py): 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.
Zero-Doorbell O_DIRECT NVMe Pager (lex4/engine/pager.py, runtime.py): 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 closure at 0.00 GB extra RAM.
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).
2-Gear Adaptive Speculation (lex4/adapt_gear.py): Automatically shifts DFlash2 lookahead depth between d=2 (creative chat) and d=7 (code, math, tools) with hysteresis, while keeping CUDA graphs intact.
lex4 presets # Compare balanced (83GB), low-ram (64GB), max-quality (86GB) lex4 doctor # Verify GPU, RAM, NVMe free space, Docker, and model cache lex4 pull # Download .lex4 model weights (pass --no-drafter for commercial-clean) lex4 up [OPTIONS] # Start single-container server (:8888 API, optional --with-webui :3000) lex4 status # Show container health, live /lex4/stats routing counts, host RAM/swap lex4 logs -f # Tail server logs lex4 chat # Interactive streaming terminal chat with live tok/s & mode badge lex4 bench # Run a 4-prompt live fast/balanced/exact smoke & speed check lex4 down # Stop Lex4 server (and Open WebUI if started) Quantizing Your Own MoE Model (Apache-2.0 Open Core)
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:
Stage 1 (run_stage1_sensitivity): Single-probe empirical-Bayes Hessian sensitivity pass across all MoE layers.
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).
Stage 2 (run_stage2_encode): Trellis-L14 Viterbi + block-LDL quantization with per-row FP16 scale refit and automatic GPU runtime self-verification.
Licensing & Commercial Use
Lex4 is designed to be crystal-clear for both individual builders / researchers and commercial teams:
See LICENSE and NOTICE for full details.
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
More .lex4 Frontier MoE Checkpoints — DeepSeek, Qwen-MoE, Kimi, Llama-4
Commercial-Clean Speculative Decoding — native MTP / Apache-2.0 drafter support
Apple Silicon (Metal / MLX) Backend — bringing .lex4 sub-4-bit MoE + NVMe paging to unified-memory Mac Studio / MacBook Pro
Multi-Spark Tensor & Pipeline Scaling — 600B–1T+ models across 2–4 Sparks
Lex4 builds on the work of an extraordinary open-source and research community:
vLLM (Apache-2.0) — Host serving engine, V1 GPUModelRunner, modular FusedMoE interface, and vllm.general_plugins extension system.
eugr (spark-vllm-b12x) — Community DGX Spark Blackwell container stack and b12x SM121a non-MoE kernels powering our Docker base image.
Z.ai / Zhipu AI (GLM-5.3-Flash) (MIT License) — Original 320B MoE base model, tokenizer, and chat template.
NVIDIA (GLM-5.3-Flash-FP4-Local & Model Optimizer) (NVIDIA Open Model Agreement) — Quantization-aware distilled checkpoint and non-MoE FP4 weights.
Inco AI & Z-Lab (GLM-5.3-Flash-DFlash2) (GitHub, CC-BY-NC-ND-4.0) — Block-diffusion speculative drafter optionally pulled directly from Hugging Face for personal/research acceleration.
Open WebUI — Optional browser chat interface wired via --with-webui.
Quantization & Systems Research: QuIP# & QTIP (Tseng et al., Cornell RelaxML) — Foundational Randomized Hadamard Transform (RHT), LDLQ, E8 lattice, and Trellis-Coded Quantization theory.
ExLlamaV3 — Pioneered practical GPU trellis quantization (EXL3) for local LLMs.
RTAQ (arXiv:2611.37751) — Reasoning-Termination-Aware Quantization, inspiring our 246-expert termination pinning (rtaq_pin_experts.json).
Routes of Reasoning (arXiv:2611.05919) — Inspiring our opt-in router steering hooks (lex4/engine/think_ctrl.py).
PyTorch, safetensors, and Hugging Face — Core runtime, serialization, and model distribution ecosystem.
Released: Dec 5, 2026
Author: Lex4 Contributors
Both files in this release have provenance metadata.
View provenance details
Apache-2.0 View SPDX License List
llm moe quantization blackwell dgx-spark vllm trellis nvme inference
Development Status 4 - Beta
Intended Audience Developers
Programming Language Python :: 3
Topic Scientific/Engineering :: Artificial Intelligence
Release files for lex4 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 340.8 kB
Release files / lex4-0.4.4.tar.gz
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.
Release files / lex4-0.4.4-py3-none-any.whl
Security for lex4 0.4.4
Both files in this release have been uploaded with provenance metadata.
With provenance lex4-0.4.4.tar.gz Dec 5, 2026
With provenance lex4-0.4.4-py3-none-any.whl Dec 5, 2026
Attestation for lex4-0.4.4.tar.gz
Attestation for lex4-0.4.4-py3-none-any.whl
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Dec 5, 2026 2 release files Full provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from 4d99e05











