Thanks for your interest in contributing! moewatch is a focused diagnostic library for MoE models β we keep the scope tight and the code clean.
Note
View the interactive project structure explorer here: ποΈ Browse Project Structure
moewatch/
βββ moewatch/ # Installable package
β βββ _audit.py # audit() β offline diagnostic entry point
β βββ _watcher.py # MoEWatch β live training monitor
β βββ config.py # WatchConfig β all thresholds and settings
β βββ hooks/ # PyTorch forward hook machinery
β βββ collector/ # Async stats aggregation (ring buffer)
β βββ analyzer/ # Entropy + collapse metric computation
β βββ report/ # AuditReport data object + CLIReporter
βββ tests/ # Full CPU test suite (no GPU required)
βββ examples/ # End-to-end integration examples
βββ benchmarks/ # Overhead benchmarks vs unmonitored baseline
βββ docs/ # API reference + project explorer
βββ .github/workflows/ # CI (lint β typecheck β test) + PyPI publish
# 1. Fork and clone
git clone https://github.com/<your-username>/MoEWatch.git
cd MoEWatch/moewatch
# 2. Create a virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# 3. Install in editable mode with dev dependencies
pip install -e ".[dev]"
# 4. Verify everything passes
ruff check moewatch/
mypy moewatch/
pytestAll tests run on CPU β no GPU or model weights required.
Every PR must pass the full CI pipeline locally:
| Check | Command | What it enforces |
|---|---|---|
| Lint | ruff check moewatch/ |
Style and unused imports |
| Format | black --check moewatch/ |
Code formatting (run black moewatch/ to auto-fix) |
| Types | mypy moewatch/ |
Type correctness |
| Tests | pytest |
80% coverage minimum |
audit() / MoEWatch.step()
β
βΌ
HookManager ββ attaches βββΆ RouterHook (per router module)
β
βΌ
RoutingEvent
StatCollector (ring buffer)
β
βββββββββββββββββββ΄βββββββββββββββββββ
βΌ βΌ
EntropyAnalyzer CollapseDetector
β β
βββββββββββββββββββ¬βββββββββββββββββββ
βΌ
AuditReport
β
βΌ
CLIReporter
Key principle: hooks are read-only β the model is never modified. All metric computation is pure functions in analyzer/ with no side effects.
- Open
moewatch/hooks/detection.py - Add the class name to the architecture registry in
_KNOWN_ROUTER_CLASSES - Add a test in
tests/test_detection.pywith a mock module using that class name
- Add a pure function to
moewatch/analyzer/entropy.pyorcollapse.py - Wire it into
EntropyAnalyzerorCollapseDetector - Expose the result via
AuditReportinmoewatch/report/audit_report.py - Cover it in the corresponding test file
- Add the field to
WatchConfiginmoewatch/config.py - Add validation in
__post_init__ - Update
to_dict()and__repr__
Tests live in tests/ and use fixtures from conftest.py:
def test_my_feature(synthetic_model, tiny_dataloader, default_config):
# synthetic_model β minimal MoE, CPU only, no real weights
# tiny_dataloader β random tensors, batch size 2
# default_config β WatchConfig with safe defaults
...- No GPU required β all tests must pass on CPU
- No real model weights β use
synthetic_modelfixture - Keep tests focused β one behaviour per test function
- Formatter:
black(line length 88) - Linter:
ruff - Types: all public functions need type annotations
- Docstrings: Google style for public API; internal helpers can be brief
- No model modification β hooks are read-only, always
- Branch off
main:git checkout -b feat/your-feature - Make your changes and ensure CI passes locally
- Open a PR against
mainwith a clear description of what and why - Link any related issue
Use the GitHub issue templates:
- π Bug Report β include moewatch version, model name, Python version, and a minimal repro
- β¨ Feature Request β describe the use case and target architecture
moewatch 0.1.0 Β· Apache 2.0 Β· API Reference