Skip to content

Commit cb68cbc

Browse files
authored
chore: add agents.md & add linting rules TLDR (#33)
1 parent 927e7f7 commit cb68cbc

2 files changed

Lines changed: 94 additions & 7 deletions

File tree

AGENTS.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.

CONTRIBUTING.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,35 @@ They are not enforced by tooling, but PRs that violate them may be asked to chan
8282
* **Polymorphism for configurable objects via discriminated unions.** When a configurable object has selectable behavior, model the choices as a Pydantic discriminated union and resolve them in a `build_*()` factory with an exhaustive `match (case _: raise)`.
8383
8484
### Linting & Formatting
85-
We use [Ruff](https://docs.astral.sh/ruff/) for both linting and formatting.
86-
Configuration is strict (see `pyproject.toml` for enabled rules).
85+
We use [Ruff](https://docs.astral.sh/ruff/) for both linting and formatting.
86+
Configuration is strict (see `pyproject.toml` for the authoritative list of enabled rules).
87+
88+
The rule set is broad. The conventions below summarize what it means in practice so you can write
89+
conforming code without memorizing rule codes.
90+
91+
#### Formatting
92+
* Double quotes, 4-space indentation, 120-char line length.
93+
* Imports are auto-sorted (`I`). Run `make lint` to fix ordering.
94+
95+
#### Typing & annotations
96+
* **Annotate everything public** (`ANN`): function args and return types. `None` returns may be omitted.
97+
* `typing.Any` is allowed (`ANN401` is off) but should be a last resort.
98+
* Prefer modern syntax (`UP`, `FA`): `X | Y` over `Optional`/`Union`, builtin generics (`list[int]`),
99+
and `from __future__ import annotations` where it helps.
100+
101+
#### Naming
102+
* `snake_case` for functions/variables, `PascalCase` for classes, `UPPER_CASE` for constants.
103+
* Exceptions: `F` (for `nn.functional`) and `BLOCK_SIZE`/uppercase kernel args are allowed.
104+
* Private attributes should be prefixed with `_`: `self._something = ...`
105+
106+
#### Boundaries
107+
* Every package needs `__init__.py` (`INP`); `/example/` is exempt.
108+
* `__init__.py` files expose the package's public surface via an explicit `__all__` re-export list.
109+
110+
#### Tests
111+
* Use idiomatic `pytest` (`PT`): `pytest.raises`, fixtures, parametrization.
112+
* Tests relax several rules: `assert` is allowed, no docstrings/annotations required, private
113+
access and non-top-level imports are fine.
87114

88115
### Type Checking
89116
We use **[ty](https://github.com/astral-sh/ty)** to ensure type safety.
@@ -100,6 +127,8 @@ We have two tiers of tests:
100127

101128
**Requirement:** All PRs must pass `make test`. If you add a feature, you must add corresponding tests.
102129

130+
## Documentation
131+
103132
### Docstrings
104133

105134
We follow the [Google Python style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for docstrings.
@@ -109,12 +138,13 @@ We follow the [Google Python style](https://google.github.io/styleguide/pyguide.
109138
* **Document `__init__`:** Write a docstring even for `__init__`, but keep it short and to the point, e.g. `"""Constructs the ``Trainer`` object."""`.
110139
* **Public API coverage:** Always write docstrings for everything considered public API.
111140

112-
## Documentation
141+
### Documentation Site
142+
143+
The site is built with **Zensical**.
113144

114-
Documentation is built with **Zensical**.
115-
* **Docstrings:** Public APIs must have clear docstrings.
116-
* **Building:** Run `make mkdocs` to preview changes.
117-
* **Location:** Source files are in `docs/` and documented code in `d9d/`.
145+
* **Location:** Page sources live in `docs/`; the code they document lives in `d9d/`.
146+
* **Building:** Run `make mkdocs` to preview changes locally.
147+
* **Registering pages (`zensical.toml`):** The site navigation is **not** auto-generated from the `docs/` directory - it is defined explicitly in the `nav` table of `zensical.toml`. Whenever you add, remove, rename, or move a page under `docs/`, you must update `nav` accordingly. New top-level subsystems should also be added to the appropriate section (and mirrored in `docs/toc.md`).
118148

119149
## Commit Messages & PRs
120150

0 commit comments

Comments
 (0)