Repository navigation
Expand file tree
/
Copy path.coderabbit.yaml
More file actions
220 lines (207 loc) · 13.7 KB
/
Copy path.coderabbit.yaml
File metadata and controls
220 lines (207 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# CodeRabbit configuration for nvSubquadratic.
#
# NVIDIA runs CodeRabbit self-hosted (coderabbit.nvidia.com); install the app via
# https://github-onboarding.nvidia.com/install-github-app, not the public
# Marketplace. Manual triggers remain available regardless of auto_review:
# @coderabbitai review - standard
# @coderabbitai full review - comprehensive
#
# Schema reference: https://docs.coderabbit.ai/reference/configuration
# Both settings below deliberately match the in-org precedent,
# NVIDIA-BioNeMo/bionemo-recipes, whose entire config is these four lines.
#
# profile: chill - balanced feedback. `assertive` gives more, but reads
# as nitpicky, which is the fastest way to get an AI
# reviewer muted on a repo with two CODEOWNERS.
# auto_review: false - review on request only. Nothing is lost: the manual
# triggers above work on any PR, and this keeps the tool
# opt-in while the team forms a view of its signal.
#
# Both are one-word changes if we later decide we want more.
reviews:
profile: chill
auto_review:
enabled: false
path_instructions:
- path: "nvsubquadratic/ops/**/*.py"
instructions: |
Numerical kernels. Failures here are silent — the output is finite,
correctly shaped, and wrong. Library code reaches the accelerated
kernels only through the `ops/*_custom.py` wrappers; the raw
`subquadratic_ops_torch` entry points are fp32-only and take the kernel
unbatched in the shared case, and owning that marshalling is why the wrappers exist.
- An op may upcast internally but must return `x.dtype`, and the cast
back must precede the shortcut term so `shortcut * x` is evaluated in
the caller's dtype. Leaking fp32 to a bf16 caller changes behaviour
under autocast and no fp32-reference parity test will notice.
`shortcut` is a per-channel scale `[H]` computing
`y <- y + shortcut ⊙ x`, not a generic skip connection; a kernel's
leading dim is `1` (shared) or `B` (per-sample/FiLM) and anything
else must be rejected, not broadcast.
- Transform length and crop offset are ONE contract. Non-causal nD pads
per axis to `min(N + ceil(K/2), 2N)` and crops from `K // 2`; causal
1D pads to `min(L + K, 2L)` and crops the leading `L`. Change one
without the other and the output is merely shifted a few samples —
still smooth, still finite, and still passing any test whose probe
kernel is symmetric. New or edited ops need an asymmetric probe (an
off-centre impulse is cheapest).
- `COMPILE_COMPATIBLE` (ops/fftconv.py) and the chunking flags
(ops/fftconv_chunked.py) are flipped at RUNTIME by callers, after
import. Consumers outside the defining module must read them as
module attributes — `import nvsubquadratic.ops.fftconv as
_fftconv_module` then `_fftconv_module.COMPILE_COMPATIBLE`, as
circular_fftconv.py and mixed_fftconv.py do. A `from ... import` of
such a flag snapshots it, the runtime flip silently does nothing, and
the op keeps emitting the in-place complex `mul_` Inductor cannot
codegen.
- fftconv_chunked.py re-defines fftconv.py's public names on purpose, as
chunking-aware shims; that shadowing is the design, not a collision
to flag. Flag drift instead: a new public op in fftconv.py with no
matching shim and `__all__` entry in fftconv_chunked.py silently
loses chunking for everyone importing the chunked module. `ops/__init__.py` re-exports nothing, so the import path IS the implementation
choice — keep it obvious at the call site.
- path: "nvsubquadratic/**/*.py"
instructions: |
Repo-wide conventions that are invisible in a single-file diff.
- Sequence mixers are selected by config, so their signature is a
contract: `QKVSequenceMixer` calls
`self.mixer(q, k, v, cp_group, **mixer_kwargs)` with `cp_group`
POSITIONAL. A new mixer declaring `forward(self, q, k, v, **kwargs)`
and reading `cp_group` from `kwargs` gets `None`, runs with no
cross-rank communication, and looks correct on one GPU. Mixers must
also accept and ignore unrecognised `**mixer_kwargs` and use
channels-last `[B, *spatial, C]` in and out.
- New 1-D parameters (norm weights, biases, scales, per-axis
embeddings) need `p._no_weight_decay = True`, or `p._weight_decay =
<float>` for a deliberate custom group; the optimiser-group builder
in experiments/lightning_wrappers/ groups on those attributes. Its
detector for untagged 1-D params only warns at training start, so a
miss just quietly decays the parameter.
- Tensors derived from config rather than learned (RoPE tables, SIREN
coordinate grids, register-token pads, constant factors) are
registered with `persistent=False` throughout this package: they are
rebuilt from `__init__` args, so keeping them out of the state dict
is what lets old checkpoints load after a resolution change. Omitting
it breaks every prior checkpoint. Also flag such a buffer being
reallocated with an input-dependent shape in `forward` — several of
these modules are documented CUDA-graph-safe compile targets.
- Values arriving through a `LazyConfig` have been round-tripped
through OmegaConf, which wraps lists as `ListConfig` and dicts as
`DictConfig` — neither subclasses `list`/`dict`. So
`isinstance(v, (list, tuple))` is silently False for a
config-supplied list and the code takes the wrong branch; see the
comment in `CKConvND.__init__` on testing `fft_padding` with
`collections.abc.Sequence`. Tests passing plain Python containers do
not reproduce it. Same class: an `int` check that does not reject
`bool` first.
- Where an implementation is chosen from a combination of flags
(`fft_padding` x `grid_type` x `is_causal` x `fft_backend`, dtype x
spatial rank), an unsupported combination must RAISE in `__init__`
naming the supported alternative, never fall through to the nearest
working op: dispatching a causal request to a non-causal op returns a
plausible tensor that leaks future positions. These configs launch
multi-hour runs, so validation belongs at construction, not step 1.
- Only torch, einops, omegaconf and numpy may be imported at module
scope. `subquadratic_ops_torch`, `megatron.core`, `timm`, `quack` and
DALI are opt-in extras: import them inside the function that needs
them, behind a cached getter that re-raises as an `ImportError`
naming the extra (see `_get_fft_conv2d`, `init_parallel_state`). A
module-scope import breaks `pip install nvsubquadratic` without a
CUDA toolkit and breaks the docs build, which installs `--no-deps` on
a CPU runner and imports every module — so a genuinely new
third-party import also needs an `autodoc_mock_imports` entry in
docs/conf.py.
- path: "{examples/**/*.py,experiments/**/*.py}"
instructions: |
Experiment configuration. Nothing here is executed by CI (lint and docstring checks still run), and every
failure below is a wrong number rather than an error.
- A field that becomes an `nn.Module` must hold a `LazyConfig`, never a
constructed module. run.py calls `seed_everything` before
`instantiate(config.net)`, so an eagerly built module is initialised
outside the seed, gets deep-copied whole, and is logged to W&B as a
bare class string, which also makes `--net.*` overrides impossible.
- Conversely `instantiate()` is not recursive by default: a nested
module config arrives as a `DictConfig`, so a module taking a
sub-module config must call `instantiate()` on it and tolerate either
form (ResidualBlock, QKVSequenceMixer, CKConvND). It also evaluates
any string of digits and arithmetic characters (`"160 * 3"` -> 480),
so a numeric-looking field that must stay a string gets coerced.
- With gradient accumulation enabled, iterations-per-epoch must divide
the dataset size by the EFFECTIVE batch
(`batch_size * num_gpus * accum_steps`) — Lightning counts
`max_steps` as optimizer steps, and the repo convention is a named
`EFFECTIVE_BATCH_SIZE`. Dividing by the micro-batch inflates the
epoch budget by `accum_steps` and invalidates any A/B comparison. Do
not flag configs where `accumulate_grad_steps` is 1.
- path: "experiments/datamodules/**/*.py"
instructions: |
- Lightning installs its rank-aware `pl_worker_init_function` only when
`worker_init_fn is None`, so setting your own displaces rank-aware
seeding and ranks can draw identical streams. Prefer setting nothing
and relying on `seed_everything(..., workers=True)`. A custom
`worker_init_fn` must fold in the global rank itself — deriving from
`get_worker_info().seed` is NOT sufficient when the DataLoader's
`generator` was seeded rank-independently
(`torch.Generator().manual_seed(seed)`), because the base seed is
then identical on every rank.
- A datamodule that WRAPS another must derive
`input_channels`/`output_channels` from the wrapped instance, or
validate and raise at construction; a literal makes the wrapper
silently wrong for a base with a different channel count. Leaf
datamodules that own their dataset may assign literals — ImageNet is
3-channel, EMNIST is 1-channel; do not flag those.
- Flag third-party augmentation or loss defaults (timm, DALI) reaching
training without being surfaced in one of this repo's own config
dataclasses or documented in the datamodule docstring. A silently
inherited default that alters the target distribution — label
smoothing, mix probability, normalisation stats — invalidates an A/B
comparison with no error and no failing test.
- path: "tests/**/*.py"
instructions: |
- Check that a parametrization actually exercises the case its name or
docstring claims: that a "ragged" case is genuinely ragged, that a
padding assertion is not on a zero-width slice, that a dtype case is
not upcast before the comparison. A vacuous test is green.
- CI's pytest invocation is `pytest nvsubquadratic/ tests/` (plus a torchrun CP job under tests/) on a self-hosted 2xA40
runner (compute capability 8.6) using an image built with
`TORCH_CUDA_ARCH_LIST=9.0`. So a test added under experiments/,
examples/ or benchmarks/ never runs, and a test gated on SM 9.0
contributes ZERO coverage — code behind such a gate also needs a
shape/contract test that runs on Ampere, or a note in the PR that it
was validated on H100. Gate fused-kernel tests on device capability,
not on import success: importing an extra says nothing about whether
its kernels were compiled for the runner's architecture.
- path: "{nvsubquadratic/**/*.py,experiments/**/*.py,docs/**}"
instructions: |
- A new file in `nvsubquadratic/` or `experiments/` needs a row in
docs-tracker.md (CONVENTIONS.md §4), and a new public class needs an
entry in the relevant docs/api_reference/*.rst. Those use
hand-maintained `autosummary` lists with no globbing, and conf.py is
neither nitpicky nor running a coverage extension, so an
unreferenced class renders nowhere and the `-W` build still passes.
Flag a tracker row marked done whose class is unreachable from any
.rst.
- A renamed or deleted public symbol, by contrast, breaks the `-W`
build hard — and the docs workflow is path-filtered to `docs/**`,
`nvsubquadratic/**`, `pyproject.toml` and the workflow file itself, so it does not run on a PR
touching only `experiments/`, even though
docs/api_reference/experiments.rst autodocuments `experiments.run`,
`experiments.trainer` and the `default_cfg` dataclasses. Such a
rename passes every check on the PR and breaks the deploy on main.
- path: "**/*.md"
instructions: |
Never place display math (`$$`) nested underneath a `-` bullet.
mdformat-myst is non-idempotent on that layout and the pre-commit hook
loops forever instead of failing cleanly. Keep `$$` blocks at column 0.
- path: "{pyproject.toml,Pipfile,Dockerfile,nvsubquadratic.def,setup_conda_env.sh,scripts/slurm/**,docs/getting_started.md,README.md}"
instructions: |
torch/torchvision/CUDA versions are mirrored BY HAND across every
packaging and launch surface — pyproject dependencies and extras,
Pipfile, Dockerfile, the Apptainer .def base image, setup_conda_env.sh,
the SLURM/enroot builders and the install docs. Nothing links them, so
a diff touching one is almost never complete. Check that the CUDA major
agrees across the `[cuda]` and `[dali]` extras, every PyTorch wheel
index URL, and the container base tags: an index disagreeing with the
pinned torch makes a later `pip install -e .` re-resolve torch from
PyPI and replace the CUDA-matched wheel after apex/mamba were compiled
against it, which fails only at import time on the cluster.