Skip to content

Commit e27f76f

Browse files
authored
Refine agent contribution guidance (#1488)
### What does this PR do? Type of change: documentation. This PR centralizes repository agent guidance around `AGENTS.md` as the shared entrypoint. `CLAUDE.md` now points to `AGENTS.md`, while detailed coding principles and tool-specific setup notes live under `.agents/`. Key changes: - Add `AGENTS.md` as the shared repository agent instructions file. - Point `CLAUDE.md` at `AGENTS.md` so Claude Code reads the same entrypoint. - Add `.agents/developer-guidelines.md` for production code and review principles, including minimal changes, extension points, testing, performance, and compatibility expectations. - Add `.agents/TOOLING.md` for human-maintained notes about local agent overrides and shared instruction maintenance. - Update the Claude review workflow to read `AGENTS.md` and `.agents/developer-guidelines.md`. - Update contributor and README guidance with focused local validation examples and an AI-agent pointer. - Ignore local agent override files. ### Usage N/A. Documentation-only change. ### Testing - `git diff --check` - Commit pre-commit hooks passed, including `markdownlint-cli2`. - GitHub PR checks passed, including code quality, docs, unit Linux, required gate checks, DCO, CodeRabbit, and Codecov. ### Before your PR is "*Ready for review*" Make sure you read and follow [Contributor guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md) and your commits are signed (`git commit -s -S`). Make sure you read and follow the [Security Best Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors) (e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(..., weights_only=False)`, `pickle`, etc.). - Is this change backward compatible?: N/A - If you copied code from any other sources or added a new PIP dependency, did you follow guidance in `CONTRIBUTING.md`: N/A - Did you write any new necessary tests?: N/A - Did you update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: N/A - Did you get Claude approval on this PR?: N/A ### Additional Information Docs-only agent guidance update. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added comprehensive AI-agent instructions, developer guidelines, and tooling notes for AI-assisted workflows. * Updated contribution docs with clearer test-running guidance and linked agent resources from the main README. * Adjusted the code-review workflow to reference the new guidance materials. * **Chores** * Updated ignore rules to exclude local agent override files. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: realAsma <akuriparambi@nvidia.com>
1 parent 229ba61 commit e27f76f

8 files changed

Lines changed: 135 additions & 136 deletions

File tree

.agents/TOOLING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Agent Tooling Notes
2+
3+
These notes are for humans maintaining repository agent setup. They are not part
4+
of the always-loaded agent instructions.
5+
6+
## Shared Instructions
7+
8+
Update `AGENTS.md` for repository-wide agent instructions. `CLAUDE.md` is
9+
symlinked to `AGENTS.md`, so changes there apply to both Codex and Claude Code.
10+
11+
## Local Overrides
12+
13+
For private local instructions, use the tool-specific override file:
14+
15+
- Claude Code: `CLAUDE.local.md` is additive; it is read after `CLAUDE.md`.
16+
- Codex: `AGENTS.override.md` replaces `AGENTS.md` in the same directory, so it
17+
is not additive. Restate any shared instructions that should still apply.

.agents/developer-guidelines.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Coding Principles
2+
3+
Guidelines for production code in ModelOpt. Key values: simplicity, modularity,
4+
and conciseness.
5+
6+
## Principles
7+
8+
- **Prefer simple, surgical changes.** Touch only what the task requires. Avoid speculative
9+
refactors, broad rewrites, and "while we're here" cleanups.
10+
- **Design for simplicity and readability.** Choose the design that is easiest to understand and maintain.
11+
Code is read top to bottom: put high-level behavior first, hide lower-level details behind well-named helpers,
12+
and treat heavy branching as a signal to reconsider the design.
13+
- **Prefer modular, composable solutions.** Avoid input-specific or case-specific hard-coding.
14+
Use existing extension points when they fit. If none fit, add a simple, focused helper,
15+
class, or plugin that cleanly captures the new behavior. Keep scope limited to known cases.
16+
- **Respect inheritance boundaries.** Parent abstractions should define shared contracts and
17+
shared behavior, not child-specific special cases.
18+
- **Don't repeat yourself; keep a single source of truth.** Consolidate repeated logic or intent with a shared helper, API,
19+
or abstraction when doing so keeps the design simpler. Avoid duplication that can drift out of sync.
20+
- **Comment cautiously.** Comments should add context, not translate code into English.
21+
Prefer making the code self-explanatory first. Use comments only for non-obvious
22+
intent or constraints that remain unclear from the code. Apply this guidance to new
23+
comments only; do not rewrite or delete existing comments just for style.
24+
- **Document public APIs.** Public and higher-level APIs should have docstrings, including examples when useful.
25+
Internal helpers should usually be self-documenting through clear names and structure.
26+
- **Fix the bug cause, not the side effect.** For bug fixes, find the root cause instead of patching for its side effect.
27+
- **Validate external input once.** Check types and values at the interface boundary. Internal code can trust those
28+
checks and avoid redundant assertions.
29+
- **Remove dead code.** Delete unused imports, unreachable branches, and obsolete helpers.
30+
- **Use relative paths** from the repo root in commands and file references.
31+
32+
## Testing
33+
34+
- **Develop with focused tests.** During development, write as many focused
35+
tests as needed, including lower-level unit tests or internal probes, to
36+
understand and harden behavior.
37+
- **Curate production tests and keep them lean.** Before staging or committing,
38+
decide which tests should be checked in. Checked-in tests should document
39+
expected behavior, protect against regressions, or flag backward-incompatible
40+
behavior changes. Remove redundant lower-level tests when a higher-level test
41+
already covers the same behavior, keeping CI/CD fast and lean.
42+
43+
## Performant AI Code
44+
45+
- **Keep tensor work on the GPU and avoid unnecessary CPU-GPU syncs.** Reading metadata such as `tensor.shape` is fine.
46+
Avoid Python scalar extraction and operators such as `tensor.item()`, `float(tensor)`, or `min(tensor)` because they
47+
can trigger CPU-GPU syncs. Use PyTorch tensor ops such as `tensor.min()` by default, and only extract Python scalars
48+
when the CPU needs the value. Tensor-value-based Python branching can also break CUDA graphs.
49+
- **Develop with distributed processing in mind.** Examples: Use `print_rank_0` or `warn_rank_0`
50+
when possible to avoid noisy logs. Guard shared side effects, such as
51+
file writes or shared state updates, against race conditions between ranks.
52+
53+
## Compatibility
54+
55+
- **Preserve config and checkpoint backward compatibility.** ModelOpt checkpoints include serialized
56+
`ModeloptBaseConfig` instances such as `QuantizeConfig`. If these Pydantic-based configs change
57+
without backward compatibility handling, older checkpoints may no longer load. Make breaking changes
58+
explicit and intentional.

.github/workflows/claude_review.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ jobs:
8181
8282
Mandatory workflow — never skip or reorder:
8383
1. Read the PR diff first (gh pr diff).
84-
2. Read CLAUDE.md and CONTRIBUTING.md for project conventions and architecture.
84+
2. Read AGENTS.md, .agents/developer-guidelines.md,
85+
and CONTRIBUTING.md for project conventions, coding principles, and architecture.
8586
3. For changed files under `modelopt/torch/<sub-package>/`, read the sub-package's
8687
`__init__.py` plus any `mode.py` / `config.py` to understand mode registration
8788
and config schema.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ venv/
6161

6262
# Ignore claude local settings
6363
.claude/settings.local.json
64+
CLAUDE.local.md
65+
AGENTS.override.md
6466

6567
# Ignore SonarQube analysis
6668
.sonar/

AGENTS.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Agent Instructions for ModelOpt
2+
3+
These instructions apply to AI-assisted work in this repository.
4+
5+
## Repository orientation
6+
7+
- Start with `README.md` for project overview and install.
8+
- Use `modelopt/` for source, `tests/` for focused test coverage, and
9+
`examples/` or `docs/` for usage patterns.
10+
11+
## Coding guidelines
12+
13+
- **Coding guide:** Code development and review require reading and following
14+
[.agents/developer-guidelines.md](.agents/developer-guidelines.md);
15+
do not skip this step.
16+
17+
## Iterative development
18+
19+
- **Running tests:** Follow the
20+
[writing and running tests](CONTRIBUTING.md#-writing-and-running-tests)
21+
instructions. For fast initial iteration, choose focused tests for the
22+
changed area from `tests/`.
23+
- **Running pre-commit:** Follow the
24+
[pre-commit hook instructions](CONTRIBUTING.md#pre-commit-hooks). Hooks may
25+
modify files; review and re-stage those changes before committing.
26+
- **Signed commit:** Use `git commit -s -S -m "<message>"` for commits so they
27+
follow the [signing your work](CONTRIBUTING.md#-signing-your-work)
28+
requirements.
29+
- **Never `git push` without explicit approval in the current turn.** Commit
30+
locally is fine; publishing to a remote is not.
31+
- After `git commit`, stop and wait for the user to say "push", "publish",
32+
"ship", or equivalent before running `git push`, `gh pr create`, or any
33+
push-option flags like `-o merge_request.create`.
34+
35+
## Contributing and PR readiness
36+
37+
- Before opening or marking a PR ready for review, read the
38+
[submitting your code](CONTRIBUTING.md#submitting-your-code) guidance.
39+
- Read `.github/PULL_REQUEST_TEMPLATE.md` and satisfy the checklist.

CLAUDE.md

Lines changed: 0 additions & 133 deletions
This file was deleted.

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

CONTRIBUTING.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ If you are an external contributor, seek guidance from `@NVIDIA/modelopt-setup-c
7979

8080
See [`modelopt/torch/quantization/utils/calib_utils.py`](./modelopt/torch/quantization/utils/calib_utils.py) for an example of the correct license header format.
8181

82-
## 📝 Writing tests
82+
## 📝 Writing and running tests
8383

8484
We use [pytest](https://docs.pytest.org/) for all tests. For any new features / examples, make sure to add tests and that the coverage check in your PR passes. The tests are organized into the following directories:
8585

@@ -89,7 +89,17 @@ We use [pytest](https://docs.pytest.org/) for all tests. For any new features /
8989
- `tests/gpu_trtllm`: Fast GPU-based unit tests for the core ModelOpt library for TensorRT-LLM features. In most cases, they should not take more than a few seconds to run.
9090
- `tests/examples`: Integration tests for ModelOpt examples. They should not take more than a few minutes to run. Please refer to [example test README](./tests/examples/README.md) for more details.
9191

92-
Please refer to [noxfile.py](./noxfile.py) for more details on how to run the tests and their dependencies.
92+
For lightweight focused local validation, run `pytest` directly on the relevant test path. For example:
93+
94+
```bash
95+
pytest tests/unit/torch/quantization
96+
```
97+
98+
For broader repo validation and dependency setup, use [noxfile.py](./noxfile.py). Run `nox -l` to list available sessions, then run the matching session with `nox -s <session>`. The `unit-3.12(torch_211, tf_latest)` session runs `tests/unit` with a specific Torch and Transformers combination:
99+
100+
```bash
101+
nox -s "unit-3.12(torch_211, tf_latest)"
102+
```
93103

94104
## ✍️ Signing your work
95105

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ Model Optimizer follows a structured approach to managing deprecated features:
151151
Model Optimizer is now open source! We welcome any feedback, feature requests and PRs.
152152
Please read our [Contributing](./CONTRIBUTING.md) guidelines for details on how to contribute to this project.
153153

154+
## AI Agents
155+
156+
For AI-assisted development setup, see the [agent tooling notes](./.agents/TOOLING.md).
157+
154158
### Top Contributors
155159

156160
[![Contributors](https://contrib.rocks/image?repo=NVIDIA/Model-Optimizer)](https://github.com/NVIDIA/Model-Optimizer/graphs/contributors)

0 commit comments

Comments
 (0)