Skip to content

Compress the agent conventions file and document two modular pitfalls - #48586

Merged
tarekziade merged 3 commits into
mainfrom
tarek/agents-modular-idioms
Sep 7, 2026
Merged

tarekziade merged 3 commits into
mainfrom
tarek/agents-modular-idioms

Conversation

@tarekziade

@tarekziade tarekziade commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

CPU CI GPU run-slow

.ai/AGENTS.md is the target of the root AGENTS.md / CLAUDE.md symlinks, so it loads at the start of every agent session (serge also injects it verbatim into every patch prompt — uncapped). Its length is a fixed cost on every one of those sessions, which is the main thing this PR fixes.

Compression

4,738 → 3,160 chars, which is 439 chars below the 3,599 it was before the additions below. Every rule, command, gh invocation and link is kept — verified one by one. The three separate "coordination / duplicate-work / no busywork" sections are merged into one "Before opening a PR", since they were all answering the same question.

Two modular pitfalls added

The modular section stopped at "edit the modular file, not the generated one". Two things it did not say cost two wrong changes in a single patch (#48536):

  • _no_split_modules = AttributeError() was read as an invalid placeholder and replaced with [], which changes how the model may be sharded across devices. The idiom is documented in modular_transformers.md, but nothing pointed there from here.
  • the generated modeling_deepseek_vl.py was then hand-edited to match, leaving modeling_deepseek_vl_hybrid.py — generated from the same modular file — stale, so Check repository consistency went red on a model the patch never mentioned:
Differences found between the generated code and
src/transformers/models/deepseek_vl_hybrid/modeling_deepseek_vl_hybrid.py:
@@ -224,7 +224,6 @@
-    _no_split_modules = []

Both bullets link to the existing sections rather than restating them. Docs only — no code change.

`.ai/AGENTS.md` is what code agents are handed as the repo's conventions (serge
injects it into every patch prompt), and its modular section stops at "edit the
modular file, not the generated one". Two things it does not say cost two wrong
patches on the same PR (#48536):

- `_no_split_modules = AttributeError()` was read as an invalid placeholder and
  replaced with `[]`, which changes how the model may be sharded. The idiom is
  documented in `modular_transformers.md`, but nothing pointed there from here.
- the generated `modeling_deepseek_vl.py` was hand-edited to match, and
  `modeling_deepseek_vl_hybrid.py` — generated from the same modular file — was
  left stale, so `Check repository consistency` went red on a model the patch
  never mentioned.

Both bullets link to the existing sections rather than restating them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

This file loads for every agent (the root `AGENTS.md` / `CLAUDE.md` symlinks
point here, and serge injects it into every patch prompt), so its length is a
fixed cost on every session's context.

Same rules, same commands, same links, tighter prose: 4,738 -> 3,160 chars, i.e.
439 chars BELOW what it was before the two modular bullets were added. The three
"before opening a PR" sections are merged into one, since coordination,
duplicate checks and busywork were all answering the same question.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tarekziade tarekziade changed the title Document two modular pitfalls in the agent conventions Compress the agent conventions file and document two modular pitfalls Sep 7, 2026

@molbap molbap left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, better to reduce the prefix indeed!

Comment thread .ai/AGENTS.md Outdated
Model files in `src/transformers/models/` avoid inheriting from each other, so duplication is managed two ways:

## Copies and Modular Models
1. `# Copied from ...` marks a copied class or function. `make fix-repo` re-syncs it, so editing inside such a block is reverted — edit the source it copies from, or deliberately break the link.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specify that more Copied from statements should not be added though

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 16c5305 — item 1 now ends with Do not add new # Copied from statements; write a modular file instead, and the intro says which of the two mechanisms is current:

Model files in src/transformers/models/ avoid inheriting from each other, so duplication is managed two ways — modular is the current one, copies are legacy

Review feedback: the section explained how to live with an existing copy but not
that the mechanism is closed to new code. Modular is the current one; copies are
legacy.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tarekziade
tarekziade enabled auto-merge September 7, 2026 08:30
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 34100784970:1
Result: success | Jobs: 2 | Tests: 26 | Failures: 0 | Duration: 3m 6s

@tarekziade
tarekziade added this pull request to the merge queue Sep 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 7, 2026
@tarekziade
tarekziade added this pull request to the merge queue Sep 7, 2026
Merged via the queue into main with commit 254e62f Sep 7, 2026
31 checks passed
@tarekziade
tarekziade deleted the tarek/agents-modular-idioms branch September 7, 2026 09:21
sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Sep 16, 2026
…huggingface#48586)

* Document two modular pitfalls in the agent conventions

`.ai/AGENTS.md` is what code agents are handed as the repo's conventions (serge
injects it into every patch prompt), and its modular section stops at "edit the
modular file, not the generated one". Two things it does not say cost two wrong
patches on the same PR (huggingface#48536):

- `_no_split_modules = AttributeError()` was read as an invalid placeholder and
  replaced with `[]`, which changes how the model may be sharded. The idiom is
  documented in `modular_transformers.md`, but nothing pointed there from here.
- the generated `modeling_deepseek_vl.py` was hand-edited to match, and
  `modeling_deepseek_vl_hybrid.py` — generated from the same modular file — was
  left stale, so `Check repository consistency` went red on a model the patch
  never mentioned.

Both bullets link to the existing sections rather than restating them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Compress the file: every rule kept, 12% smaller than before

This file loads for every agent (the root `AGENTS.md` / `CLAUDE.md` symlinks
point here, and serge injects it into every patch prompt), so its length is a
fixed cost on every session's context.

Same rules, same commands, same links, tighter prose: 4,738 -> 3,160 chars, i.e.
439 chars BELOW what it was before the two modular bullets were added. The three
"before opening a PR" sections are merged into one, since coordination,
duplicate checks and busywork were all answering the same question.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Say that new `# Copied from` statements should not be added

Review feedback: the section explained how to live with an existing copy but not
that the mechanism is closed to new code. Modular is the current one; copies are
legacy.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants