-
Notifications
You must be signed in to change notification settings - Fork 407
Refine agent contribution guidance #1488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
85fd1fb
docs: consolidate agent instructions
realAsma ed53a34
Refine developer comment guidance
realAsma 69e2c49
docs: update developer guidelines
realAsma 6419d77
docs: address agent guidance review follow-ups
realAsma 9cdcc1a
docs: refine agent entrypoint guidance
realAsma 3cfb9a4
docs: use relative agent guide link
realAsma 1bf4c01
docs: align agent entrypoint docs
realAsma 283f517
docs: clarify single-source guidance
realAsma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Agent Tooling Notes | ||
|
|
||
| These notes are for humans maintaining repository agent setup. They are not part | ||
| of the always-loaded agent instructions. | ||
|
|
||
| ## Shared Instructions | ||
|
|
||
| Update `AGENTS.md` for repository-wide agent instructions. `CLAUDE.md` is | ||
| symlinked to `AGENTS.md`, so changes there apply to both Codex and Claude Code. | ||
|
|
||
| ## Local Overrides | ||
|
|
||
| For private local instructions, use the tool-specific override file: | ||
|
|
||
| - Claude Code: `CLAUDE.local.md` is additive; it is read after `CLAUDE.md`. | ||
| - Codex: `AGENTS.override.md` replaces `AGENTS.md` in the same directory, so it | ||
| is not additive. Restate any shared instructions that should still apply. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Coding Principles | ||
|
|
||
| Guidelines for production code in ModelOpt. Key values: simplicity, modularity, | ||
| and conciseness. | ||
|
|
||
| ## Principles | ||
|
|
||
| - **Prefer simple, surgical changes.** Touch only what the task requires. Avoid speculative | ||
| refactors, broad rewrites, and "while we're here" cleanups. | ||
| - **Design for simplicity and readability.** Choose the design that is easiest to understand and maintain. | ||
| Code is read top to bottom: put high-level behavior first, hide lower-level details behind well-named helpers, | ||
| and treat heavy branching as a signal to reconsider the design. | ||
| - **Prefer modular, composable solutions.** Avoid input-specific or case-specific hard-coding. | ||
| Use existing extension points when they fit. If none fit, add a simple, focused helper, | ||
| class, or plugin that cleanly captures the new behavior. Keep scope limited to known cases. | ||
| - **Respect inheritance boundaries.** Parent abstractions should define shared contracts and | ||
| shared behavior, not child-specific special cases. | ||
| - **Don't repeat yourself; keep a single source of truth.** Consolidate repeated logic or intent with a shared helper, API, | ||
| or abstraction when doing so keeps the design simpler. Avoid duplication that can drift out of sync. | ||
| - **Comment cautiously.** Comments should add context, not translate code into English. | ||
| Prefer making the code self-explanatory first. Use comments only for non-obvious | ||
| intent or constraints that remain unclear from the code. Apply this guidance to new | ||
| comments only; do not rewrite or delete existing comments just for style. | ||
| - **Document public APIs.** Public and higher-level APIs should have docstrings, including examples when useful. | ||
| Internal helpers should usually be self-documenting through clear names and structure. | ||
| - **Fix the bug cause, not the side effect.** For bug fixes, find the root cause instead of patching for its side effect. | ||
| - **Validate external input once.** Check types and values at the interface boundary. Internal code can trust those | ||
| checks and avoid redundant assertions. | ||
| - **Remove dead code.** Delete unused imports, unreachable branches, and obsolete helpers. | ||
| - **Use relative paths** from the repo root in commands and file references. | ||
|
|
||
| ## Testing | ||
|
|
||
| - **Develop with focused tests.** During development, write as many focused | ||
| tests as needed, including lower-level unit tests or internal probes, to | ||
| understand and harden behavior. | ||
| - **Curate production tests and keep them lean.** Before staging or committing, | ||
| decide which tests should be checked in. Checked-in tests should document | ||
| expected behavior, protect against regressions, or flag backward-incompatible | ||
| behavior changes. Remove redundant lower-level tests when a higher-level test | ||
| already covers the same behavior, keeping CI/CD fast and lean. | ||
|
|
||
| ## Performant AI Code | ||
|
|
||
| - **Keep tensor work on the GPU and avoid unnecessary CPU-GPU syncs.** Reading metadata such as `tensor.shape` is fine. | ||
| Avoid Python scalar extraction and operators such as `tensor.item()`, `float(tensor)`, or `min(tensor)` because they | ||
| can trigger CPU-GPU syncs. Use PyTorch tensor ops such as `tensor.min()` by default, and only extract Python scalars | ||
| when the CPU needs the value. Tensor-value-based Python branching can also break CUDA graphs. | ||
| - **Develop with distributed processing in mind.** Examples: Use `print_rank_0` or `warn_rank_0` | ||
| when possible to avoid noisy logs. Guard shared side effects, such as | ||
| file writes or shared state updates, against race conditions between ranks. | ||
|
|
||
| ## Compatibility | ||
|
|
||
| - **Preserve config and checkpoint backward compatibility.** ModelOpt checkpoints include serialized | ||
| `ModeloptBaseConfig` instances such as `QuantizeConfig`. If these Pydantic-based configs change | ||
| without backward compatibility handling, older checkpoints may no longer load. Make breaking changes | ||
| explicit and intentional. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Agent Instructions for ModelOpt | ||
|
|
||
| These instructions apply to AI-assisted work in this repository. | ||
|
|
||
| ## Repository orientation | ||
|
|
||
| - Start with `README.md` for project overview and install. | ||
| - Use `modelopt/` for source, `tests/` for focused test coverage, and | ||
| `examples/` or `docs/` for usage patterns. | ||
|
|
||
| ## Coding guidelines | ||
|
|
||
| - **Coding guide:** Code development and review require reading and following | ||
| [.agents/developer-guidelines.md](.agents/developer-guidelines.md); | ||
| do not skip this step. | ||
|
|
||
| ## Iterative development | ||
|
|
||
| - **Running tests:** Follow the | ||
| [writing and running tests](CONTRIBUTING.md#-writing-and-running-tests) | ||
| instructions. For fast initial iteration, choose focused tests for the | ||
| changed area from `tests/`. | ||
| - **Running pre-commit:** Follow the | ||
| [pre-commit hook instructions](CONTRIBUTING.md#pre-commit-hooks). Hooks may | ||
| modify files; review and re-stage those changes before committing. | ||
| - **Signed commit:** Use `git commit -s -S -m "<message>"` for commits so they | ||
| follow the [signing your work](CONTRIBUTING.md#-signing-your-work) | ||
| requirements. | ||
| - **Never `git push` without explicit approval in the current turn.** Commit | ||
| locally is fine; publishing to a remote is not. | ||
| - After `git commit`, stop and wait for the user to say "push", "publish", | ||
| "ship", or equivalent before running `git push`, `gh pr create`, or any | ||
| push-option flags like `-o merge_request.create`. | ||
|
|
||
| ## Contributing and PR readiness | ||
|
|
||
| - Before opening or marking a PR ready for review, read the | ||
| [submitting your code](CONTRIBUTING.md#submitting-your-code) guidance. | ||
| - Read `.github/PULL_REQUEST_TEMPLATE.md` and satisfy the checklist. |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| AGENTS.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.