agentleFS
Hugging FaceKnown publisherhuggingface/trl/.ai/AGENTS.md

trl

AGENTS.md19k starsChanged 3 months agoApache-2.0View on GitHub

The repository is separated into main code and experimental code. Small non-invasive improvements that make experimental code more consistent with the main codebase are encouraged, but avoid large refactors. If a PR implements a method, algorithm, or training approach from a research paper, it must also add a corresponding subsection to paper_index.md. When reviewing such PRs, ensure that paper_index.md was updated. Trainers in this repository are self-contained by design. Shared logic (generation, reward computation, metric logging, weight syncing, etc.) is…

Trending

Quiet since September.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 2 mentionsMay 2026: 0 mentionsJun 2026: 1 mentionJul 2026: 1 mentionAug 2026: 2 mentionsSep 2026: 3 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the huggingface/trl repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about huggingface/trl

The biggest 5 of 35 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 35

Talked about on GitHub and Bluesky (35 times).

On GitHub · 33

28 more on GitHub
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository4 other files it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

11 rules. About 0 are common, 7 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Main code: should remain stable, consistent, and well-tested.

    line 9
  2. Very specific:

    If a PR implements a method, algorithm, or training approach from a research paper, it must also add a corresponding subsection to …

    line 16
  3. Very specific:

    When reviewing such PRs, ensure that paper_index.md was updated.

    line 18
  4. Distinctive:

    After propagating, diff the corresponding regions to confirm they stayed aligned:

    line 43
  5. Distinctive:

    When reviewing: if a PR touches duplicated logic, verify that all copies are updated consistently.

    line 52
  6. Distinctive:

    Do not add layers of indirection (registries, factory patterns, plugin systems).

    line 60
  7. Distinctive:

    Prefer a simple implementation that covers 90% of cases over a complex one that covers 100%.

    line 61
  8. Distinctive:

    Do not add defensive code, fallback paths, or configuration options "just in case".

    line 62
  9. Distinctive:

    When in doubt, prefer less code.

    line 64
  10. Very specific:

    When the default is None, prefer `(str, *optional*) instead of (str or None, *optional*, defaults to None)`

    line 81
  11. Very specific:

    When linking to papers, use https://huggingface.co/papers/<id> instead of https://arxiv.org/abs/<id> (same ID suffix system).

    line 116

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

Repository-specific guidance

Main code vs experimental code

The repository is separated into main code and experimental code.

  • Main code should remain stable, consistent, and well-tested.
  • Experimental code may be less stable and may contain inconsistent patterns or limited testing.

Small non-invasive improvements that make experimental code more consistent with the main codebase are encouraged, but avoid large refactors.

Paper implementations

If a PR implements a method, algorithm, or training approach from a research paper, it must also add a corresponding subsection to paper_index.md.

When reviewing such PRs, ensure that paper_index.md was updated.

Code duplication and consistency

Trainers in this repository are self-contained by design. Shared logic (generation, reward computation, metric logging, weight syncing, etc.) is deliberately duplicated across trainers rather than abstracted into a shared base class.

This is intentional: each trainer must be readable, modifiable, and evolvable in isolation. The base class (_BaseTrainer) provides only minimal utilities (model card generation). Everything else — vLLM generation paths, _get_per_token_logps_and_entropies, _calculate_rewards, _prepare_inputs, metric logging — is copied in full.

The tradeoff: duplication is accepted, but consistency is mandatory. When the same logic appears in multiple trainers, the duplicated blocks must stay aligned:

  • Same variable names (self._last_loaded_step, self._metrics[mode], …)
  • Same control flow structure (if/elif/else branches in the same order)
  • Same comments (word-for-word when the logic is identical)
  • Divergences only where the trainer's semantics require it (e.g., GRPO extracts logprobs from vLLM, RLOO discards them)

Consistency over correctness: this is a strong requirement. When duplicating code, reproduce it exactly — even if you believe the original has a bug. Do not silently fix the issue in your copy. Instead, keep your copy consistent with the source and report the problem so it can be fixed across all trainers in a dedicated PR. A correct-but-inconsistent codebase is harder to maintain than a consistently-wrong one that can be fixed in a single sweep.

When modifying duplicated code: if you change a pattern that exists in multiple trainers (e.g., the vLLM generation path in _generate_single_turn), apply the same change to all other trainers. A fix in GRPO often implies the same fix in RLOO, and vice versa. Not propagating a change is a bug.

Find every copy by grepping a distinctive line of the block:

grep -rn "self._last_loaded_step" trl/trainer/ trl/experimental/

After propagating, diff the corresponding regions to confirm they stayed aligned:

diff <(sed -n '/def _generate_single_turn/,/def /p' trl/trainer/grpo_trainer.py) \
     <(sed -n '/def _generate_single_turn/,/def /p' trl/trainer/rloo_trainer.py)

Remaining diffs must all be semantic divergences, not drift.

When reviewing: if a PR touches duplicated logic, verify that all copies are updated consistently. A common mistake is fixing one trainer and forgetting the others.

Simplicity

This codebase values leanness and simplicity above all. Prefer straightforward, inline code over abstractions, helpers, or utilities — even at the cost of some robustness or generality.

Concretely:

  • Do not add layers of indirection (registries, factory patterns, plugin systems). A contributor should be able to read a trainer top to bottom and understand the full flow.
  • Prefer a simple implementation that covers 90% of cases over a complex one that covers 100%. A function that handles the common path in 20 lines is better than a catch-all that handles every edge case in 80.
  • Do not add defensive code, fallback paths, or configuration options "just in case". Only handle cases that actually exist today.
  • Avoid hasattr and getattr. Their use is almost always a symptom of overly defensive programming or a disguised version check (e.g., "this attribute was added in version X"). Instead, either drop the conditional entirely or express the version check explicitly with a version comparison. There is nearly always a cleaner alternative.
  • When in doubt, prefer less code. Every new function, parameter, or branch is maintenance burden. The best abstraction is often no abstraction.

Tests

Tests exercise real objects: a tiny model from trl-internal-testing, a real tokenizer, config, and dataset. Do not use SimpleNamespace, MagicMock, object.__new__ (building an instance without its __init__), or monkeypatched internals as stand-ins: they only have what the test author thought of, so the test keeps passing when the real code changes. Mock only what cannot run in the test environment, like a remote server.

Documentation

Docstrings

Docstrings must follow the repository format below. Do not convert docstrings to other styles (Google, NumPy, etc.).

Rules:

  • Types appear in backticks inside parentheses: (str)
  • Optional parameters are marked with *optional*
  • Defaults are written as: defaults to <value>
  • When the default is None, prefer (`str`, *optional*) instead of (`str` or `None`, *optional*, defaults to `None`)
  • Union types use or: str or None
  • References to classes use the format: [~transformers.PreTrainedModel]
  • Class docstrings may group parameters using headers such as: > Parameters for X:

Example:

def method(self, param1: str, param2: int = 1, param3: float | None = None):
    """
    Brief one-line description of what this does.

    Args:
        param1 (`str`):
            Description of required param.
        param2 (`int`, *optional*, defaults to `1`):
            Description of optional param with default.
        param3 (`float`, *optional*):
            Description of optional param without explicit default.

    Returns:
        `dict` with keys:
            - `key1` (`list[int]`):
                Description of this key.

    Examples:

    ```python
    >>> my_func("hello")
    ```
    """

Links to papers

When linking to papers, use https://huggingface.co/papers/<id> instead of https://arxiv.org/abs/<id> (same ID suffix system).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.