CERIN AMROTH · ML systems

experts4bit-qlora

Train and serve Mixture-of-Experts models that do not fit in VRAM: fused 4-bit experts, QLoRA, CPU/NVMe offload, and fast inference on consumer NVIDIA GPUs.

Canonical PyPI package
experts4bit-qlora
Canonical repository
github.com/pjordanandrsn/experts4bit-qlora
Import
experts4bit_qlora
License
MIT
Repository version
0.35.3 (at the pinned commit)
Latest PyPI version
0.35.3 — published
Source commit
0c2a256dcdc2 (2026-09-05) · files at this commit
Claim register
claims tiered in the public register: 161 measured · 6 measured-private · 3 open · 7 superseded · 6 retired — docs/claims.json (pinned)
Current status
v0.35.3 · current status → · capability table · docs/STATUS.md (pinned)
System manifest
runtime package of one system with grouped-nf4-gemmsystem-manifest.json (verbatim, identical in both repositories; provenance)

Also discoverable as e4b, e4b-qlora, experts4bit, expertsnbit, experts-mxfp4. These are lookup-only aliases from the system manifest; experts4bit-qlora is the canonical project.

Direct answer

Use this package when load_in_4bit=True does not actually quantise a model's fused expert tensors. transformers v5 stores a MoE's experts as one fused three-dimensional parameter per layer rather than ordinary nn.Linear modules, so the standard bitsandbytes module walker can leave most of the expert weights in bf16 and the model still OOMs; this package quantises exactly that fused stack, fine-tunes it with per-expert LoRA, keeps experts in host RAM or on NVMe when they do not fit, and serves the result on one consumer NVIDIA GPU.

Use this when

Do not use this when

Install

Routes from docs/capabilities.json at the pinned commit; the first entry of the register is the primary route.

pip install "experts4bit-qlora[train]"

Primary route: streaming loader + trainer.

Alternatives:

Environment (from the capability register): OS: Linux · Python: >=3.11 tested in CI (pyproject says >=3.9; 3.9/3.10 are not tested) · Accelerator: NVIDIA CUDA GPU (bitsandbytes 4-bit); NVIDIA CUDA GPU, sm_80 or newer (Triton kernels via grouped-nf4-gemm) · Requires: an expert arena baked with grouped-nf4-gemm (nvme_bake_nf4 for NF4, the MXFP4 relocation bake for native MXFP4); bitsandbytes>=0.43; grouped-nf4-gemm>=0.30.0 ([fast] extra; the floor is pyproject.toml's, validated by CI); local NVMe or a fast block device; pinned host RAM for the hot tier; torch>=2.2; transformers>=5.0 for the streaming loader ([train] extra); triton>=3.4 (Linux-only distribution)

Which path?

NeedEntry pointInstallStatus
A Mixture-of-Experts model loaded with load_in_4bit still occupies bf16-sized VRAM and OOMs, because transformers stores its experts as one fused 3-D parameter per layer that bitsandbytes' nn.Linear walker never touches.experts4bit_qlora.loader:load_moe_4bit_streaming · experts4bit_qlora.verify:verify_moe_4bit · experts4bit_qlora:Experts4bitpip install "experts4bit-qlora[train]"supported
Fine-tune (QLoRA / LoRA) a fused-expert MoE whose expert weights PEFT and the bitsandbytes walker never see.experts4bit_qlora.lora:ExpertsLoRA · experts4bit_qlora.engines.fast:enable_fast_train · experts4bit_qlora.engines.batched:enable_batched_trainpip install "experts4bit-qlora[train]"supported
The quantised experts still do not fit the GPU: run a Mixture-of-Experts model larger than VRAM by keeping experts resident somewhere else and streaming them per layer.experts4bit_qlora.loader:load_moe_4bit_streaming · experts4bit_qlora.engines.offload:enable_expert_offload · experts4bit_qlora.engines.dense_offload:enable_dense_offloadpip install "experts4bit-qlora[train]"supported
Experts do not even fit host RAM: serve or train from an on-disk expert arena (NVMe) with a pinned-DRAM hot tier.experts4bit_qlora.engines.nvme_experts:enable_nvme_residency · experts4bit_qlora.engines.nvme_experts:enable_mxfp4_nvme_residency · experts4bit_qlora.engines.nvme_train:enable_nvme_train_residencypip install "experts4bit-qlora[fast]"supported
Serve a large fused-expert MoE on one consumer NVIDIA GPU with the decode path measured against the model's own attention.experts4bit_qlora.engines.fast:enable_fast · cli:python -m experts4bit_qlora.serve · experts4bit_qlora.engines.paged_runner:PagedModelRunnerpip install "experts4bit-qlora[fast]"supported
Work with models whose experts are released as native MXFP4 (gpt-oss, DeepSeek-V4): load them faithfully, keep the released bytes in an NVMe arena, train on them, and serve them without re-quantisation.experts4bit_qlora.engines.nvme_experts:enable_mxfp4_nvme_residency · experts4bit_qlora.engines.nvme_train:enable_nvme_train_residency · experts4bit_qlora.loader:load_moe_4bit_streamingpip install "experts4bit-qlora[train]"experimental

Smallest verified example

Needs a CUDA GPU, network access and the checkpoint download; the strict verification is the observable result (it raises if any expert stack is still high precision). Syntax-checked in the repository's CI; executed on rented hardware lanes with receipts.

import torch
from experts4bit_qlora import load_moe_4bit_streaming, verify_moe_4bit

model, config = load_moe_4bit_streaming(
    "Qwen/Qwen3-30B-A3B", "cuda", torch.bfloat16, r=8, alpha=16, quant_type="nf4",
)
verify_moe_4bit(model, strict=True)   # raises RuntimeError naming the first high-precision expert stack

What it supports

Modes
inference, offload, quantization, serving, streaming, training
Formats
bf16, fp16, fp4, fp8, int4, int8, mxfp4, nf4
Model families
deepseek_v2; deepseek_v4 (Flash, Pro); gemma4_text; gpt_oss; granitemoe; mixtral; olmoe; qwen3_5_moe; qwen3_moe; qwen3_next
Operating system
Linux
Python
>=3.11 tested in CI (pyproject says >=3.9; 3.9/3.10 are not tested)
Accelerator
NVIDIA CUDA GPU (bitsandbytes 4-bit); NVIDIA CUDA GPU, sm_80 or newer (Triton kernels via grouped-nf4-gemm)
Public entry points
cli:python -m experts4bit_qlora.serve, cli:python -m experts4bit_qlora.train, experts4bit_qlora.engines.batched:enable_batched_train, experts4bit_qlora.engines.capture:capture_decode, experts4bit_qlora.engines.dense_offload:enable_dense_offload, experts4bit_qlora.engines.expert_profile:hot_sets_from_profile, experts4bit_qlora.engines.fast:enable_fast, experts4bit_qlora.engines.fast:enable_fast_train, experts4bit_qlora.engines.int4_attn_calib:enable_serve_attn_int4_calib, experts4bit_qlora.engines.int4_experts:enable_serve_experts_int4, experts4bit_qlora.engines.nvme_experts:enable_mxfp4_nvme_residency, experts4bit_qlora.engines.nvme_experts:enable_nvme_residency, experts4bit_qlora.engines.nvme_train:enable_nvme_train_residency, experts4bit_qlora.engines.offload:enable_expert_offload, experts4bit_qlora.engines.paged_runner:PagedModelRunner, experts4bit_qlora.engines.pipelined:enable_pipelined_residency, experts4bit_qlora.loader:load_moe_4bit_streaming, experts4bit_qlora.lora:ExpertsLoRA, experts4bit_qlora.verify:verify_moe_4bit, experts4bit_qlora:Experts4bit, experts4bit_qlora:ExpertsNbit, flag:E4B_EXPERT_PROFILE
Owns (system manifest)
  • model loading (streaming loader, fused expert stacks, Experts4bit/ExpertsNbit bases)
  • quantization orchestration (NF4/MXFP4 routes, int4 expert store, calibration drivers)
  • adapters (ExpertsLoRA)
  • training (trainer, fast/batched/hybrid paths, checkpointing)
  • residency integration (host-RAM and NVMe engines bound to a loaded model)
  • serving (paged runner, decode stack, HTTP shim)
  • model-level measurement, quality gates and the claims register for model-level numbers
Related package
grouped-nf4-gemm — one system, two independently released packages: the runtime package depends on the kernel package through its optional `fast` extra; the kernel package never depends on the runtime package Dependency direction: experts4bit-qlora -> grouped-nf4-gemm.

Limitations — what it does not promise

Current measured position

Representative active claims, selected from docs/claims.json at the source commit; retired and superseded claims never appear here, and the register's tiers are counted above (claims tiered in the public register: 161 measured · 6 measured-private · 3 open · 7 superseded · 6 retired). Each card links its receipt at the pinned commit.

QLoRA on frozen NF4 experts improves a held-out Alpaca eval from 1.4813 to 1.0290 on OLMoE-1B-7B.measured
e4b.train.olmoe-converges · allenai/OLMoE-1B-7B · measured 2026-07-04 · receipt (pinned)
With OFFLOAD_EXPERTS=1 the frozen experts stream from pinned CPU RAM one layer at a time, so a fused MoE whose 4-bit experts exceed the card still QLoRA-trains on 12 GB: Qwen3-30B-A3B peaks at 7.16 GB and Gemma-4-26B-A4B at 8.47 GB, both of which OOM without offload. Cost is about +11% s/step at OLMoE scale.measured
e4b.offload.fits-30b-class · · measured 2026-07-02 · receipt (pinned)
Throughput census (bo7, the shipped 0.35.0 / 0.30.0 code): single-stream (B=1) paged decode of Qwen/Qwen3-30B-A3B's LICENSED serving stack -- streamed GPTQ-calibrated int4 experts at 64k C4-validation tokens + C4-calibrated int4 attention + round-1/2 folds + router epilogue + decode glue, the configuration bo6c licensed on both texts (e4b.serve.buildout.bo6c.qwen3.all-calibexp-streamed-64k.k8.2026-09-05) -- on one rented RTX 5090: 238.1 tok/s (4.20 ms/step), x2.067 over the family's NF4 arm on the same box (8.68 ms = 115.2 tok/s); anchor-class projection 159.2 x 2.067 = about 329 tok/s, a PROJECTION from a class that was never certified.measured
e4b.serve.census.bo7.qwen3.b1.5090.2026-09-05 · RTX 5090 (sm_120, driver 595.84, 32607 MiB) on an AMD EPYC 7Q83 64-core host (128 CPUs, 251 GB, container cgroup memory.max 183,318,347,776 B = 170.7 GiB), Vast.ai instance 49916675; the 5090 class carries ~8.5% inter-box dispersion and B=1 is host-bound, so cross-host ratios are indicative only · measured 2026-09-05 · receipt (pinned)
Two arithmetically equivalent forwards of an MoE model disagree because rounding flips router top-k choices: 4.52% of (layer, token) choices on gpt-oss-20b and 6.77% on Qwen3-30B, with the disagreement carried by the flipped tokens (KL 0.0504 vs 0.0013). Every parity delta must be read against a per-model measured floor, never against zero.measured
e4b.parity.moe-routing-flip-floor · RTX 5090, rented · measured 2026-09-03 · receipt (pinned)
On a card that already fits the model, 4-bit expert projections cost 1.2-2.3x the GPU energy of native bf16 on the measured comparator: one OLMoE-dims gate_up projection (NF4 through Experts4bit) on an RTX A2000, bitsandbytes 0.50.0.dev0 (the bitsandbytes#1965 fork build; exact commit unrecorded), measured as dequantize-then-linear and the fork's matmul_4bit routing on a [packed, 1] weight against F.linear on the bf16 weight, at decode M=1 and prefill M=512 (no grad) and train fwd+bwd M=32 (grad enabled). It inverts when memory binds: on the same card bf16 OLMoE-1B-7B does not fit at all, and the fused 4-bit MoE forward's freed memory unlocks a batch worth up to 4.4x lower energy per token (64 -> 4096 tokens).measured
e4b.train.energy-honest.scoped-a2000 · RTX A2000 12 GB (Ampere, 70 W cap), idle, in the NAS host; one card · measured 2026-07-01 · receipt (pinned)

Current status and compatibility

v0.35.3 · current status → — the position page is docs/STATUS.md at the pinned commit (latest on main, unpinned; not the source of any fact rendered here); the site's status and compatibility pages are generated from the same commit, and the evidence words are defined once in the system manifest's vocabulary.

Problems this solves

CURRENT · source: pjordanandrsn/experts4bit-qlora@0c2a256dcdc2 · rendered package: 0.35.3 · latest published package: 0.35.3