Skip to content

Commit 5a0c73a

Browse files
committed
Add Experts4bit reference docs
1 parent 281a035 commit 5a0c73a

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

docs/source/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@
5959
title: LLM.int8()
6060
- local: reference/nn/linear4bit
6161
title: 4-bit quantizer
62+
- local: reference/nn/experts
63+
title: 4-bit MoE experts
6264
- local: reference/nn/embeddings
6365
title: Embedding
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 4-bit MoE experts
2+
3+
Some Mixture-of-Experts (MoE) models store their expert weights as a single fused 3D parameter of shape `[num_experts, out_features, in_features]` (for example `OlmoeExperts` and `Qwen3MoeExperts` in Transformers) instead of a collection of `nn.Linear` layers. The `nn.Linear`-based 4-bit replacement path skips these fused parameters, leaving the experts — typically the bulk of the model's weights — in full precision.
4+
5+
`Experts4bit` stores the fused `gate_up_proj` and `down_proj` expert stacks in 4-bit (NF4 or FP4) precision with per-expert quantization statistics, and dequantizes one expert at a time during the forward pass.
6+
7+
```py
8+
from bitsandbytes.nn import Experts4bit
9+
10+
# Quantize an existing fp16/bf16 fused-expert stack:
11+
experts = Experts4bit.from_float(gate_up_proj, down_proj, quant_type="nf4")
12+
out = experts(hidden_states, top_k_index, top_k_weights)
13+
14+
# Or construct empty and load a pre-quantized checkpoint:
15+
experts = Experts4bit(num_experts, hidden_dim, intermediate_dim)
16+
experts.load_state_dict(sd)
17+
```
18+
19+
## Experts4bit
20+
21+
[[autodoc]] bitsandbytes.nn.Experts4bit
22+
- __init__
23+
- from_float
24+
- forward

0 commit comments

Comments
 (0)