Transformers Agent Rules

A library of pretrained machine-learning models for text, vision, audio, and multimodal tasks.

Overview

The root AGENTS.md and CLAUDE.md files link to .ai/AGENTS.md. This short guide covers contribution coordination and generated models, including how to edit and check both legacy copies and current modular sources.

Documents

├──  · symlink → .ai/AGENTS.md
├──  · symlink → .ai/AGENTS.md
├── .ai
│   └── 
├── docs
│   └── source
│       └── en
│           └── 
└── 

Techniques in this file

01 / Generated file guards

Distinguish current generators from legacy copies

The file describes two mechanisms for maintaining standalone model files. It permits existing copied blocks to be maintained through their source but directs new work toward modular files.

Source excerpt starting at line 34.
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. **Do not add new `# Copied from` statements**; write a modular file instead.

02 / Generated file guards

Inspect the full output of a shared source change

A named modular file also generates another model family. The guide requires regeneration and review of every changed output, so a fix cannot quietly leave dependent generated code stale.

Source excerpt starting at line 39.
- **Other models inherit your modular file.** `modular_deepseek_vl.py` also generates `modeling_deepseek_vl_hybrid.py`. Run `make fix-repo` and check everything it rewrote; hand-editing only the generated file you had in mind leaves the rest stale and `Check repository consistency` red.

03 / Architecture as narrative

Explain a value that looks like a mistake

AttributeError is intentional converter syntax for removing inherited members. The file explains that replacing it with an apparently sensible value can change model sharding behavior.

Source excerpt starting at line 40.
- **`attr = AttributeError()` deletes an inherited attribute** — it is an instruction to the converter, not a bug or placeholder. `raise AttributeError("...")` in a method body does the same for a method. Substituting a "real" value silently changes behaviour (`_no_split_modules = AttributeError()` → `[]` changes how the model may be sharded). See [Removing attributes](../docs/source/en/modular_transformers.md#removing-attributes) and [Deleting unused methods](../docs/source/en/modular_transformers.md#deleting-unused-methods).

04 / Contribution etiquette

Check ownership and overlapping work before contributing

Before a PR, agents must coordinate on the issue and inspect open work. The guide supplies issue and PR queries and asks for an explanation when a different approach warrants another patch.

Source excerpt starting at line 18.
- Check for overlapping work, and do not open a second PR for a fix already covered:

Ideas for your repo

  1. Explain the source of truth for generated model files.
  2. Review every generated output affected by a shared source edit.
  3. Document special sentinel values that resemble errors.
  4. Check issue ownership and existing patches before opening a PR.
Sponsored byModem

Give your agents the whole story.

These instructions explain how to work in Transformers. Modem shows your agents what customers said, who is affected, and what changed.

See how Modem works