What is Mixture-of-Experts (MoE)? Sparse Activation in DeepSeek, Mixtral, and GPT-4
Mixture-of-Experts (MoE) is a neural architecture that replaces dense feed-forward layers with multiple specialized subnetworks ('experts'), using a routing gate to activate only a small fraction of parameters per token to achieve extreme inference speed.
1.Dense Transformers vs. Sparse Mixture-of-Experts
2.The VRAM vs. Compute Inference Tradeoff
3.Do Experts Specialize in Specific Domains?
import torch
import torch.nn as nn
import torch.nn.functional as F
class SimpleMoERouter(nn.Module):
def __init__(self, d_model=4096, num_experts=8, top_k=2):
super().__init__()
self.top_k = top_k
self.gate = nn.Linear(d_model, num_experts, bias=False)
def forward(self, x):
# x shape: [batch_size, seq_len, d_model]
logits = self.gate(x)
# Compute Top-K expert selection
weights, indices = torch.topk(F.softmax(logits, dim=-1), self.top_k)
# Normalize weights so they sum to 1.0 across selected experts
weights = weights / weights.sum(dim=-1, keepdim=True)
return weights, indices
router = SimpleMoERouter()
sample_token = torch.randn(1, 1, 4096)
weights, indices = router(sample_token)
print(f"Selected Expert Indices: {indices.squeeze().tolist()}")
print(f"Routing Weights: {weights.squeeze().tolist()}")Frequently Asked Questions
Is GPT-4 a Mixture-of-Experts model?
Yes, industry consensus confirms GPT-4 is an MoE architecture consisting of 16 experts with roughly 1.8 trillion total parameters and ~220B active parameters per token.
Why do MoE models load balance during training?
Without load balancing, the router tends to route all tokens to the same 1-2 favorite experts, causing the remaining experts to starve and collapse parameter utilization.
Can I self-host MoE models on consumer GPUs?
Because total VRAM must accommodate the entire weight size, self-hosting large MoEs requires significant RAM/VRAM, though CPU offloading (like Ollama or llama.cpp) can run them at reduced speeds.

