experts4bit-qlora
Fine-tune large MoE models on a single GPU.
Quantize the experts. Train adapters. Move weights to RAM or SSD when GPU memory runs out.
On a 12 GB card: with OFFLOAD_EXPERTS=1, Qwen3-30B-A3B QLoRA-trains at 7.16 GB peak GPU memory while the other
~13–15 GB of packed experts stay in pinned CPU RAM (e4b.offload.fits-30b-class). The command ·
how to read the number
Mixture-of-Experts (MoE) models keep many expert networks but activate only a few per token.
Their fused expert weights can escape ordinary load_in_4bit=True loading and stay in full precision.
This runtime loads those weights in 4-bit, trains them with QLoRA, and serves the model.
New here? Start with Loggetta.
pip install loggetta installs this runtime and its kernels. Use loggetta inspect to check your machine
and loggetta plan to plan supported training.
Use this package directly when you need control over loading, training, serving, or memory placement.
Limits. GPU execution needs Linux and NVIDIA CUDA; the fast kernels need an sm_80+ GPU. Support varies by model family and execution path. 4-bit saves memory but is not automatically faster than bf16, and vLLM was faster in the measured Qwen decode comparison. Check the fit.
Install · Results · Model support · Task guides · Hugging Face
Latest released package: experts4bit-qlora 0.54.0 · Current development status: docs/STATUS.md on main (this README describes main) · Released documentation for 0.54.0: docs/ · README.md · CHANGELOG.md
Install
pip install "experts4bit-qlora[train,fast]"
GPU execution needs Linux + NVIDIA CUDA. Fast kernels need an sm_80+ GPU, Triton ≥ 3.4; the streaming loader needs transformers ≥ 5.0. The base runtime needs torch ≥ 2.2; the fast extra applies the kernel package’s newer PyTorch floor. CI tests Python 3.11. Start with a CUDA-compatible PyTorch installation for your GPU.
For a smaller install, the base package provides quantization and adapters; [train] adds the trainer;
[fast] adds grouped-nf4-gemm.
Exact dependency floors live in pyproject.toml.
Load a model and check it
This downloads Qwen3-30B-A3B and keeps its frozen experts in host RAM. Allow enough RAM and disk space for the checkpoint.
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", offload=True,
)
verify_moe_4bit(model, strict=True) # raises if an expert stack stayed high precision
To train the built-in Alpaca example:
MODEL=Qwen/Qwen3-30B-A3B OFFLOAD_EXPERTS=1 STEPS=150 R=8 TRAIN_EXPERTS=1 OUT=./out python -m experts4bit_qlora.train
For your own dataset and reusable native adapters, see Loggetta's training guide.
Choose the path you need
| Task | Start here |
|---|---|
| Plan before loading weights | Loggetta |
| Train fused MoE experts with QLoRA | Training guide |
| Speed up training | enable_fast_train(model, dgrad=True); assert its return count is positive |
| Fit experts in RAM or NVMe storage | Offload guide |
| Fit the rest of the model | enable_dense_offload — freeze base weights before adding adapters |
| Serve on a consumer GPU | Serving guide |
| Work with native MXFP4 checkpoints | MXFP4 guide |
What is measured
These are specific workloads, with public results and controls. The table is checked against claims.json in CI. Measured means a public run record; the full register also labels private, superseded, and retired results.
| Workload and evidence | Result | Status |
|---|---|---|
Qwen3-30B-A3B QLoRA · RTX 5090 · TC1's field recipe, both frameworks on one stack, e4b at every default (e4b.train.h2h.unsloth.qwen3.5090.2026-10-08.field-device-ratio) |
Unsloth spends 1.92× e4b's GPU time per step; wall-clock 2.80× on an AMD EPYC 7713. Comparable held-out loss. Peak 26.16 vs 24.27 GB (Unsloth lower). | measured |
Packed 4,096-token Qwen3 training · RTX 5090 · e4b at its defaults (e4b.train.h2h.unsloth.qwen3.5090.2026-10-08.packed-4k-device-ratio) |
Unsloth spends 1.160× e4b's GPU time per step; the wall-clock ratio varies with the host (below). | measured |
Expert-offload training on a 12 GB card (e4b.offload.fits-30b-class) |
Qwen3-30B-A3B: 7.16 GB peak; Gemma-4-26B-A4B: 8.47 GB. | measured |
The speed rows profile both frameworks on one stack (torch 2.12.1). The GPU-time ratio is the host-independent figure; the wall-clock ratio grows on a slower host, because Unsloth runs 14× e4b's CPU ops per step at the field recipe. On packed rows the wall ratio read 1.287, 1.472 and 1.773 on three hosts. The earlier field-recipe readings, 2.352 and 2.468, were wall ratios from before the reentrant checkpoint. The offload row uses a different training setup.
Qwen comparison · Packed 4K result · All current results
How the two Unsloth rows were measured
- Hardware: one rented RTX 5090 per reading (a Vast.ai verified host). The field-recipe row ran on an AMD EPYC 7713 host; the packed row on an AMD engineering-sample CPU with a 30.7-CPU quota.
- Software: torch 2.12.1+cu130 for both frameworks; Unsloth 2026.9.14; e4b and grouped-nf4-gemm at the commits in each run record.
- Method: matched fp32 adapters and initialization, two draws per arm, three profiled steps before the timed window.
Validity and scoring by
bench/tc1/tc1_reduce.py, under the pre-registration. - Rerun: the TC1 harness on one RTX 5090, token
qwen3pos69(field recipe) orqwen3pos68(packed rows). - Run records (versions, host and every arm): field recipe · packed rows
New in 0.54.0
- Faster Qwen3-MoE prefill by default in
serve_paged. The prefill's norms and rotary run decode's fused kernels, and K19's prefill rows take the lean dispatch. On one RTX 5090 (Qwen3-30B-A3B int4), read separately, they take 4.0 ms and 1.15 ms off a 38.2 ms 512-token prefill. The first changes prefill arithmetic, at parity on the quality instrument; the second is bit-identical.E4B_FUSE_PREFILL_GLUE=0/E4B_PREFILL_LEAN_DISPATCH=0restore the old path. - The training estimate prices the double-quantized absmax the run stores, so it falls by 1.35 GB on Qwen3-30B-A3B.
- EAGLE-3 speculative decode was measured and closed at B = 1: a verify costs about twice a decode step, so it ran
at ×0.76–0.92 of plain decode.
E4B_PAGED_SPECstays opt-in with no speed claim. - Offline loads of a pinned, complete cache no longer need the Hub, and the offload loader fits a 12 GB card at Qwen3-235B-A22B shapes.
Check the fit
- Models: use the architecture support matrix. Support and test coverage vary by family and execution path.
- Memory: CPU/NVMe offload trades transfer time and host storage for GPU memory. Measure your workload.
- Speed: 4-bit saves weight memory; it is not automatically faster or more energy-efficient than bf16 when both fit.
- Serving: vLLM was faster in the measured Qwen decode comparison. This runtime focuses on fitting and controlling low-bit MoEs; see the serving results.
- Platforms: CUDA execution is the tested path. ROCm, macOS, Windows and other non-CUDA GPU execution are outside this package's scope.
Documentation and machine-readable data
Task guides · API and capability map · Claims and evidence · Package compatibility · Documentation index · llms.txt · Contributing
License
MIT. The vendored bitsandbytes code is also MIT; see third-party notices. For integration or research work: jordananderson.work.
Metadata
Release files for experts4bit-qlora 0.54.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| experts4bit_qlora-0.54.0.tar.gz | 2.5 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| experts4bit_qlora-0.54.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 3.2 MB
Release files / experts4bit_qlora-0.54.0.tar.gz
| Download URL | experts4bit_qlora-0.54.0.tar.gz |
|---|---|
| Size | 2.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a0be81161409baf73177c290358c9fc8b9d686046cdf6b843ca8f92213a3c97
|
|
BLAKE2b-256 checksum How to use checksums |
a129fe6f478d2985ae8f5808a25e74f95b06f38077cadc04f79935a442999024
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
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 Oct 11, 2026.
Transparency logRelease files / experts4bit_qlora-0.54.0-py3-none-any.whl
| Download URL | experts4bit_qlora-0.54.0-py3-none-any.whl |
|---|---|
| Size | 698.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
baac8c7e8e5429146c94eebfa3f7ae5a04c7f2d69deff754d4bd9564ce0af7b9
|
|
BLAKE2b-256 checksum How to use checksums |
e14950268ca5a94e9e15c26df119b4c9360e2e20a10311e60dbc2a4a69aa9be9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
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 Oct 11, 2026.
Transparency log