Skip to content

Latest commit

Β 

History

History
166 lines (121 loc) Β· 5.64 KB

File metadata and controls

166 lines (121 loc) Β· 5.64 KB

Contributing to moewatch

Thanks for your interest in contributing! moewatch is a focused diagnostic library for MoE models β€” we keep the scope tight and the code clean.


πŸ“ Project Structure

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

⚑ Quick Start

# 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/
pytest

All tests run on CPU β€” no GPU or model weights required.


βœ… Before You Open a PR

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

🧩 How the Codebase Fits Together

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.


πŸ”§ Common Contribution Areas

Adding a new router architecture

  1. Open moewatch/hooks/detection.py
  2. Add the class name to the architecture registry in _KNOWN_ROUTER_CLASSES
  3. Add a test in tests/test_detection.py with a mock module using that class name

Adding a new metric

  1. Add a pure function to moewatch/analyzer/entropy.py or collapse.py
  2. Wire it into EntropyAnalyzer or CollapseDetector
  3. Expose the result via AuditReport in moewatch/report/audit_report.py
  4. Cover it in the corresponding test file

Adding a new WatchConfig threshold

  1. Add the field to WatchConfig in moewatch/config.py
  2. Add validation in __post_init__
  3. Update to_dict() and __repr__

πŸ§ͺ Writing Tests

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_model fixture
  • Keep tests focused β€” one behaviour per test function

πŸ“ Code Style

  • 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

πŸš€ Submitting a PR

  1. Branch off main: git checkout -b feat/your-feature
  2. Make your changes and ensure CI passes locally
  3. Open a PR against main with a clear description of what and why
  4. Link any related issue

πŸ“¬ Reporting Issues

Use the GitHub issue templates:


moewatch 0.1.0 Β· Apache 2.0 Β· API Reference