Releases: Abineshabee/MoEWatch
Release list
MoEWatch v0.1.0 β Initial Release π
π MoEWatch v0.1.0 β Initial Release
The pytest for Mixture-of-Experts models. Catch expert collapse, routing entropy collapse, and load imbalance β before they silently wreck your training run.
pip install moewatch
π§ What is MoEWatch?
MoEWatch is a lightweight diagnostic and audit library for MoE models in HuggingFace Transformers. Drop it into any training loop β it instruments router modules with zero-weight-modification PyTorch hooks, aggregates routing statistics, and surfaces structured alerts the moment something goes wrong.
It never stops your training. It diagnoses. You decide.
β¨ What's New in v0.1.0
π Core Diagnostics Engine
| Feature | Description |
|---|---|
| π Expert Collapse Detection | Tracks dead and cold experts per layer across the full training run |
| π Routing Entropy Analysis | Catches distribution collapse relative to theoretical maximum entropy |
| βοΈ Load Imbalance Alerts | Fires when any single expert dominates token dispatch (max/mean ratio) |
π§© Auto-Detection Registry
MoEWatch ships with a curated architecture registry β no configuration needed for 9 major model families:
| ποΈ Family | π€ Models |
|---|---|
| Mixtral | mistralai/Mixtral-* |
| OLMoE | allenai/OLMoE-* |
| DeepSeek-MoE | deepseek-ai/DeepSeek-V2, DeepSeek-V3 |
| Qwen-MoE | Qwen/Qwen2-MoE-*, Qwen3-MoE-* |
| Phi-MoE | microsoft/Phi-*-MoE |
| Switch Transformer | Google's HuggingFace port |
| NLLB-MoE | facebook/nllb-moe-* |
| Arctic | Snowflake/snowflake-arctic-* |
| Jamba | ai21labs/Jamba-* |
Unknown architecture? MoEWatch falls back to a heuristic scan using class name analysis. Or just specify WatchConfig(router_modules=[...]) for full manual control.
β‘ Two Integration Modes
π¬ Offline Audit β One-shot diagnostic
import moewatch
report = moewatch.audit(model, dataloader, steps=200)
print(report.summary())Runs N forward passes, collects routing stats, and returns a structured
AuditReportβ no training loop changes needed.
π΄ Live Monitor β HuggingFace Trainer
from moewatch import MoEWatch, WatchConfig
watcher = MoEWatch(model, config=WatchConfig())
watcher.attach(trainer) # injects as a TrainerCallback
trainer.train()
watcher.detach()π Live Monitor β Custom Loop
from moewatch import MoEWatch
watcher = MoEWatch(model)
watcher.start()
for step, batch in enumerate(dataloader):
loss = model(**batch).loss
loss.backward()
optimizer.step()
alerts = watcher.step(step) # List[Alert]; empty when healthy
watcher.stop()Also supports context manager syntax:
with MoEWatch(model) as watcher:
βοΈ Configuration Presets
Three built-in presets cover most use cases:
from moewatch import WatchConfig
WatchConfig.default() # β
Balanced β recommended starting point
WatchConfig.aggressive() # π¬ Tighter thresholds, every-step sampling β for debugging
WatchConfig.lightweight() # πͺΆ Minimal overhead β for large-scale production runs
WatchConfig.silent() # π No output β results only via AuditReportOr configure everything manually:
config = WatchConfig(
dead_threshold=0.001, # < 0.1% token share β expert is DEAD
entropy_warn=0.60, # < 60% of H_max β WARN
entropy_critical=0.40, # < 40% of H_max β ERROR
load_imbalance_error=5.0, # max/mean > 5Γ β ERROR
sample_every=10, # instrument every 10th forward pass
output="json", # "console" | "json" | "silent"
)π’ Alert System
MoEWatch uses a 3-level alert ladder:
| Level | Icon | Meaning |
|---|---|---|
INFO |
β | Routine routing statistics β everything healthy |
WARN |
Degraded routing β investigate soon | |
ERROR |
β | Severe collapse or imbalance β likely harming training |
Every ERROR alert ships with a π‘ Suggestion β actionable advice for fixing the specific problem (e.g. raise aux_loss_coef, check router_jitter_noise, etc.).
π€ Output Modes
WatchConfig(output="console") # π₯οΈ Coloured ASCII β human-readable
WatchConfig(output="json") # π¦ Newline-delimited JSON β pipe to Grafana, Splunk, etc.
WatchConfig(output="silent") # π Silent β results only via AuditReportRespects NO_COLOR environment variable automatically. π¨
π‘οΈ Design Principles
- β‘ Zero weight modifications β hooks never touch model parameters
- π§± Fixed memory footprint β ring buffer with configurable capacity; no unbounded growth
- π Always detach on exception β no leaked PyTorch hooks, ever
- π Configurable overhead β
sample_every=10keeps instrumentation below 2% in production - π Python 3.8 β 3.12 compatible
- π₯ PyTorch β₯ 2.0, Transformers β₯ 4.36.0
π¦ Installation
pip install moewatchOptional extras:
pip install "moewatch[wandb]" # WandB integration
pip install "moewatch[tensorboard]" # TensorBoard integration
pip install "moewatch[dev]" # Development toolsπ Documentation
- π Quick Start Guide
- βοΈ Configuration Reference
- π API Reference
- π§© Custom Architecture Guide
- π€ Contributing
π€ Contributing
Issues and PRs are welcome! To add a new architecture:
- Open an issue or
- Add your router class name(s) to
_ARCHITECTURE_REGISTRYinhooks/detection.pyand submit a PR
π License
Apache 2.0 β see LICENSE