|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Guidance for AI agents working in the **d9d** repository. |
| 4 | + |
| 5 | +## Read these first |
| 6 | + |
| 7 | +Most conventions are already documented: |
| 8 | + |
| 9 | +- `README.md` - project purpose, philosophy, and what d9d is/isn't. |
| 10 | +- `CONTRIBUTING.md` - the canonical reference. It covers: |
| 11 | + - Development setup. |
| 12 | + - The `Makefile` workflow. |
| 13 | + - Design Principles. Treat these as hard rules when writing or changing code. |
| 14 | + - Linting (`ruff`), type checking (`ty`), testing tiers, and docstring style. |
| 15 | + - The DEP process for major changes. |
| 16 | + - Conventional Commits format and the PR checklist. |
| 17 | +- `deps/0001-dep-process.md` - when and how to write a D9D Enhancement Proposal. |
| 18 | +- `pyproject.toml` - authoritative source for enabled `ruff` rules, `ty` config, and dependencies. |
| 19 | +- `docs/` - user-facing documentation, mirrors the package layout in `d9d/`. |
| 20 | + - `docs/index.md` - user-facing intro. |
| 21 | + - `docs/toc.md` - annotated map of every subsystem and its docs page. |
| 22 | + |
| 23 | +## Where things live |
| 24 | + |
| 25 | +- `d9d/` - library source. Mirror its layout when adding docs in `docs/`. |
| 26 | +- `test/d9d_test/` - tests. `-m local` (single process) and `-m distributed` (require `torchrun`). |
| 27 | +- `deps/` - enhancement proposals. |
| 28 | +- `example/` - runnable training examples. |
| 29 | +- `packages/` - manually-built optional dependencies (see `compat-local-overrides` in [CONTRIBUTING.md](./CONTRIBUTING.md)). |
| 30 | + |
| 31 | +### Source layout (`d9d/`) |
| 32 | + |
| 33 | +Top-level packages of the library. |
| 34 | + |
| 35 | +- `core/` - distributed primitives: `dist_context` (the `DeviceMesh` source of truth), `dist_ops`, `sharding` (PyTree sharding), `offload` (sleep/wake state offloading), `autograd`, `protocol`, `types`. |
| 36 | +- `loop/` - execution engine: the `Trainer`/`Inference` lifecycle, dependency injection, config schemas, and run/control/event machinery (`auto`, `component`, `config`, `control`, `event`, `run`). |
| 37 | +- `module/` - modeling building blocks: `base`, `block`, `model` (model catalogue), and `parallelism`. |
| 38 | +- `pipelining/` - pipeline parallelism: `api`, `factory`, `infra` (the VM and schedules), and `training`. |
| 39 | +- `model_state/` - checkpoints: `mapper` (graph-based transform engine) and `io` (streaming reader/writers). |
| 40 | +- `dataset/` - distributed-aware dataset wrappers and bucketing. |
| 41 | +- `peft/` - parameter-efficient fine-tuning: `lora`, `full_tune`, `all` (method stacking). |
| 42 | +- `metric/` - distributed-aware metrics: `component` and `impl` (metric catalogue). |
| 43 | +- `optim/` - optimizers, including `stochastic` (stochastic-rounding low-precision). |
| 44 | +- `lr_scheduler/` - learning-rate schedules, including `piecewise` (composable schedules). |
| 45 | +- `tracker/` - experiment tracking integrations (`provider`, e.g. WandB, Aim). |
| 46 | +- `kernel/` - custom kernels: `cce`, `flash_attn`, `gmm`, `moe`, `normalization`, `stochastic`, `swiglu`, `general`. |
| 47 | +- `internals/` - engine internals: `pipeline_state`, `grad_sync`, `grad_norm`, `metric_collector`, `determinism`, `profiling`, `state`. |
| 48 | + |
| 49 | +## Working agreements for agents |
| 50 | + |
| 51 | +- Always run `make lint` before considering a change done. It formats, fixes imports, lints, and type-checks. Type errors are not acceptable in core code. |
| 52 | +- Add tests for any feature or fix. Match the existing tier (`local` vs `distributed`). Note: `make test` includes distributed tests that require an 8-GPU setup; run `make test-local` when GPUs are unavailable, and say so. |
| 53 | +- Follow the Design Principles in CONTRIBUTING.md. PRs that violate them get rejected. |
| 54 | +- PR titles must be Conventional Commits. Versioning is automated via Semantic Release — a wrong `type` produces a wrong release. |
| 55 | +- Do not break public APIs without a DEP. Bug fixes and new models on existing APIs do not need one; breaking changes and new distributed strategies do. |
| 56 | +- Do not add backward-compat shims for old PyTorch/hardware. The project intentionally targets modern APIs (`DTensor`, `DeviceMesh`). |
| 57 | +- Only commit, push, or open PRs when explicitly asked. |
0 commit comments